Java Interview Questions too Answers

Java Interview Questions together with Answers

Section I: General
Section II: Comments inwards Java
Section III: Java Modifiers
Section IV: Java Data Types
Section V: Java Variables
Section VI: Operators inwards Java
Section VII: Java Control Flow Statements
Section VIII: Java IO together with File Handling
Section IX: String Handling inwards Java
Section X: Java Arrays
Section XI: Java Methods
Section XII: Exception Handling inwards Java
Section XIII: Java Inheritance
Section XIV: Java Polymorphism
Section XV) Java Abstraction
Section XVI: Java Encapsulation
Java is a Programming Language together with a Platform Java Interview Questions together with Answers
------------------------------------------------
Section I: General

1) What is Java?

Java is a Programming Language together with a Platform

• Java is used equally a programming to educate Software Applications
• Java is used equally Software Platform to run Java Applications

2) What are of import Java Editions or Parts of Java?

Java has Three Important Editions

i) Java Standard Edition / Core Java (* Old advert J2SE)
ii) Java Enterprise Edition / Advanced Java (*Old advert J2EE)
iii) Java Micro Edition (* Old advert J2ME)

3) Where Java is used? 

Java is used to create,
 Desktop Applications
 Web Applications
 Enterprise Applications
 Mobile Applications
 Smart Cards
 Embedded Systems
 • Scientific Applications
 Computer Games Etc...

4) How Java is Used?

Java is an Open Source Software together with Platform independent,

• For Software Development download together with install JDK (includes JRE together with JVM) Software,
• For Run-time (to run Software Applications that developed inwards Java) download together with install JRE (includes JVM)

We tin post away run Java byte code on whatsoever supported platform.

5) What are of import features of Java?

Important Features of Java are,

• Simple
• Object Oriented
• Platform independent
• Secured
• Robust, 
• Architecture neutral
• Portable
• Interpreted
• Multithreaded

• Distributed

6) What is JVM?

Java Virtual machine (JVM) is the virtual machine that run the Java bytecodes. 
The JVM doesn't empathise Java root code, that's why yous compile your *.java files to obtain *.class files that incorporate the bytecodes understandable past times the JVM. 

7) What is JRE?

The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine, together with other components to run applets together with applications written inwards the Java programming language.

8) What is JDK?

Java Development Kit (JDK) is a superset of the JRE, together with contains everything that is inwards the JRE, summation tools such equally the compilers together with debuggers necessary for developing applets together with applications.

9) What are of import Java Language Elements?

Important Language Elements of Java are,

i) Data Types
ii) Modifiers
iii) Variables
iv) Operators
v) Control Flow Statements
vi) Methods Etc...

10) What are the Fundamentals of OOPS?

Four fundamentals of Object Oriented Programming are,

i) Inheritance
ii) Polymorphism
iii) Abstraction
iv) Encapsulation

11) What are Java Syntax Rules?

Java Syntax Rules:

• Java is a illustration sensitive language.

• First missive of the alphabet of Class advert should live on inwards Upper case.

• Method names should offset alongside lower illustration letter.

• Java programme file advert should just check alongside course of written report name.

• Java programme execution starts from master copy method, which is mandatory inwards every Java program.

• Every statement/step should halt alongside semi colon symbol.

• Code blocks enclosed alongside {}.

12) How to setup Java Environment on Windows Operating System?

• Download Java Software (JDK) together with Install.
(Download Java (JDK) Software from either java.com or oracle.com, together with Install)

• Set Environment Variable path (Path variable)

• Download Eclipse IDE together with extract

Launch Eclipse IDE, Write Java Program together with execute.

13) How to gear upward Environment Variable path inwards Windows Operating environment?

After Java Installation thence yous tin post away instruct Java folder inwards C:\Program Files.

Set Environment Variable path (Path variable)

Navigation

First accept jdk bin directory path

Select MyComputer together with correct click
> Properties
> Advanced System Settings
> Environment Variables
> Select Path variable from arrangement variables
> Edit
> Paste coffee bin directory path inwards variable value field
> OK
> Ok
>OK
> Close

14) How to write together with execute Java Programs using Windows Command Prompt (Without Eclipse IDE)?

In Computer Programming nosotros conduct maintain 3 steps.

Step 1: Write a Sample Program inwards Notepad together with relieve alongside .java extension

public course of written report Sample {
public static void master copy (String [] args) {
System.out.println ("Hello Java World");
}
}

Step 2: Compile the Program

> Launch Command prompt
> Chang to Java programme file directory.
> Type javac Sample.java

* It creates Java course of written report file

Step 3: Run / Execute the program.

Type coffee Sample

Then it displays the Output on the Console.

15) What is Eclipse IDE?

Eclipse IDE (Integrated Development Environment)

• Eclipse IDE is a platform to write together with execute figurer programs similar Java, Perl, Python, Ruby, PHP etc...

• Eclipse IDE is opened upward source.

• It provides Editor for writing programs, Syntax guidance, Context help, automobile compilation etc...

Note: Using Eclipse IDE nosotros tin post away write together with execute Java Programs.

16) How to write together with execute Java programs using Eclipse IDE?

Steps to Write together with Execute a Java Program using Eclipse IDE :

> Launch Eclipse IDE
> Create Java Project
> Create Java Package
> Create Java Class
Write Java Program together with Run.

Note: Eclipse IDE provides automobile compilation facility.

17) Explain virtually Java Program Structure?

Sections of Java Program,

i) Documentation Section 
ii) Package annunciation statement
iii) Import Statement/s
iv) Class declaration 
v) master copy Method (Java Program execution starts from master copy method)
vi) Declarations (We declare Variables together with Constants.)
vii) General Statements (Ex: d = a + b + c;)
viii) Code blocks (Condition blocks, Loop Blocks etc...)

Note: Every Normal Statement should halt alongside Semi colon together with Every code block enclosed alongside {}
------------------------------------------------
Section II: Comments inwards Java

1) What are Comments inwards Computer Program?

Comments are English linguistic communication words used for Code documentation

Purpose of Comments
i) To brand the code Readable
ii) To brand the code disable from Execution

2) How to write comments inwards Java?

Comments Syntax inwards Java

Java supports Single line of piece of occupation comment together with multiple line of piece of occupation comment.

a) Use // for Single line of piece of occupation comment

b) Use /*..........
------------
----------
----------
-------------*/ for multiple line of piece of occupation comment

Or
In Eclipse IDE,

Select Statements/Steps
Source card -> Add Block Comment

Uncomment
Select Comment block
Source card -> Remove Block Comment
------------------------------------------------
Section III: Java Modifiers

1) What are Modifiers?

Modifiers are keywords that nosotros add together to those definitions to alter their meaning.

2) What are the types of Modifiers inwards Java?

Two types of Modifiers inwards Java

i) Access Modifiers
ii) Non Access Modifiers

3) What are Access Modifiers?

We purpose access modifiers to define access command for classes, methods together with variables.

Access Modifiers inwards Java are,

i) public
public access modifiers is accessible everywhere.

Ex:
public course of written report Sample{
}

ii) private
The mortal access modifier is accessible entirely inside class.

Ex:
private int a=100;

iii) default

If nosotros don't specify whatsoever modifier thence it is treated equally default, this tin post away live on accessible entirely inside package.

Ex:
class Sample {
}

iv) protected
The protected modifier is accessible inside package, exterior of the parcel simply through Inheritance.

Ex:
protected course of written report Sample {
}

4) What are the of import Non Access Modifiers inwards Java?

i) static 
static modifier is used to exercise classes, methods together with variables.

ii) final 
final modifier for finalizing classes, methods together with variables.

iii) abstract 
abstract modifier is used to exercise abstract classes together with abstract methods.
Etc...
------------------------------------------------
Section IV: Java Data Types

1) What is Data type?

Data Type is a classification of the type of information that a variable or Constant or Method tin post away concur inwards Computer program.

Ex: character, integer, float, boolean etc...

Java Supports Explicit annunciation of information types.

2) What is Explicit annunciation of information types?

We withdraw to specify the information type earlier declaring variables or Constants.

Examples inwards Java:

int a;
int b=100;
int c, d, e;
int f=10, g=20, h=30;

3) What are the categories of Data Types inwards Java?

Two categories of Data Types inwards Java

i) Primitive Data Types
ii) Non Primitive Data Types

4) What are Primitive Data Types inwards Java?

Primitive Data Types (8 Data types) inwards Java are,

i) Integer Data Types 

a) byte (8 bits), Ex: byte a = 10;
b) brusk (16 bits), Ex: brusk b =10000;
c) int (32 bits), Ex: int c = 1000000;
d) long (64 bits), Ex: long d = 100000000000000000000;

ii) Relational information types (Numbers alongside decimal places)

e) float (32 bits), Ex: float x = 10.23;
f) double (64 bits), Ex: double y = 1245.34567897345;

iii) Characters

g) Character, Ex: char z = "A";

iv) Conditional

h) Boolean, Ex: boolean x = true/false;

5) What are Non Primitive Data Types?

Non Primitive Data Types Or Reference information Types inwards Java are Objects together with Arrays.

Example:

Sample obj = novel Sample();
------------------------------------------------
Section V: Java Variables

1) What is Variable?

A named retentivity location to shop the temporary information inside a program.

Two types of retentivity inwards Computer environment.

i) Primary retentivity (RAM)
ii) Secondary retentivity (ROM - HDD, DVD, USB displace etc...)

Note: Variables shop inwards Primary retentivity (RAM).

2) How to Declare Variables inwards Java?

Java supports Explicit annunciation of variables.

Syntax:

dataType variableName;

Example:
int a;
char x;

3) How to assign values to Variables inwards Java?

Two types of Assign values to variables,

i) Initialization

int a =100; //Initialization

ii) Reading (Reading using Input devices, from files)

int a =100;
int b;
b=a;//Reading

4) What are Variable Naming restrictions inwards Java?

i) Java Variables are illustration sensitive.
ii) Java variable names should offset alongside a missive of the alphabet or $ or _
iii) Variable names should non check alongside Java Keywords/Reserved words
iv) Must live on unique inwards the orbit of declaration.
v) Must non top 255 characters.
Etc...

5) What are the types of Variables inwards Java?

i) Local Variables
Local variables are declared inwards methods or blocks.

ii) Instance Variables
Instance Variables are declared inwards a course of written report simply exterior of a method or whatsoever block.

iii) Class / Static Variables
Static Variables are declared equally static, these can't live on local.
------------------------------------------------
Section VI: Operators inwards Java

1) What are Operators?

Operators are used to perform mathematical, comparing together with logical operations.

2) What are the categories of Operators inwards Java?

i) Arithmetic Operators
ii) Relational Operators
iii) Assignment Operators
iv) Logical Operators
Etc...

3) What are Arithmetic Operators inwards Java?

Arithmetic Operators inwards Java are,

i) Addition + (Addition, String concatenation)
ii) Subtraction - (Subtraction, Negation)
iii) Multiplication *
iv) Division /
v) Modules %
vi) Increment ++
vii) Decrement --

Note: Arithmetic Operators render value based result.

4) Give an Example for Arithmetic Operators?

public static void main(String[] args) {

int a =10, b =5;
String c = "Selenium", d ="Testing";

System.out.println("Addition of a, b is: " +(a+b));//Addition of a, b is: 15
System.out.println(a+b);//15
System.out.println(a-b);//5
System.out.println(a*b);//50
System.out.println(a/b);//2
System.out.println(a % b);//0
b=10;
a = ++b;
System.out.println(a);//11
b=10;
a = --b;
System.out.println(a);//9
}
}

5) What are Relational Operators inwards Java?

Relational Operators inwards Java are,

i) == 
ii) !=
iii) >
iv) >=
v) <
vi) <=

Note: Relational Operators render Boolean/logical upshot (true/false)

6) Give an Example for Relational Operators?

public static void main(String[] args) {
int a =10, b =20;

System.out.println(a>b);//false
System.out.println(a>=b);//false
System.out.println(a<b);//true
System.out.println(a<=b);//true
System.out.println(a==b);//false
System.out.println(a!=b);//true
}
}

7) What are Logical Operators inwards Java?

Important Logical Operators inwards Java are,

i) Logical Not operator !
ii) Logical And Operator &&
iii) Logical Or operator ||

8) Give an Example for Logical Operators?

Example for Logical Operators,

public static void main(String[] args) {
boolean a =true, b =false;

System.out.println(!(a && b));//true
System.out.println(a && b);//false
System.out.println(a || b);//true
}

9) What are the of import Assignment Operators inwards Java?

Important Assignment Operators are,

i) Assignment  =
ii) Add together with Assign +=
iii) Subtract together with Assign -=
iv) Multiply together with Assign *=

10) Give an Example for Assignment Operators?

public static void main(String[] args) {

int a = 10;
System.out.println(a);//10

a += 10;
System.out.println(a);//20

a -= 10;
System.out.println(a);//10

a *= 10;
System.out.println(a);//100
}
}

11) What is Operator Precedence?
------------------------------------------------
Section VII: Java Control Flow Statements

1) What are the Types of Control Flow Statements inwards Java?

Java has Three types of Control Flow Statements,

i) Decision Making Statements
ii) Looping Statements
iii) Branching Statements
------------------------------------------------
Section VIII: Java IO together with File Handling

Section IX: String Handling inwards Java

Section X: Java Arrays

Section XI: Java Methods

Section XII: Exception Handling inwards Java

Section XIII: Java Inheritance

Section XIV: Java Polymorphism

Section XV) Java Abstraction

Section XVI: Java Encapsulation
------------------------------------------------
Also Read / watch:

Java Step past times Step Videos

Sumber http://www.gcreddy.com/
Post a Comment (0)
Previous Post Next Post