Java Interview Questions Part 1

Java Interview Questions and Answers Part 1

1) What is Java?

• Java is an Object oriented Programming language, In Java every thing is object, java can be easily extended since it is based on Object model.

• Java Programming Language was developed at Sun Microsystems in 1991 (The first publicly available version of Java (Java 1.0) released in 1995, Now it is subsidiary of Oracle corporation.

• Java is a Platform independent language, it can be compiled and Interpreted.

• Java is simple, easy to learn and implement.

• Java is Securable, using Java we can develop virus free and tamper free systems.

2) What is the use of Java?

• To develop Desktop Applications (ex: Acrobat Reader)

• To develop Web Applications

• To develop Enterprise Applications (Ex: Banking, Insurance Applications etc...)

• To develop Mobile Applications

• To develop Embedded Systems.

• To develop Smart Cards

• To develop Games software etc...

3) What are the important Java Syntax rules?

• Java is a case sensitive language.

• First letter of Class name should be in Upper case.

• Method names should start with lower case letter.

• Java program file name should exactly match with class name.

• Java program execution starts from main method, which is mandatory in every Java program.

• Every statement/step should end with semi colon symbol.

• Code blocks enclosed with {}.

4) How to setup Java environment? 

> Download Java Software (JDK) and Install.

> Set Environment Variable path (Path variable)

> Download Eclipse IDE and extract

Launch Eclipse IDE, Create Java project, Create Java Package under Java project, Create Java Class under Java package and write Java Code & Run/Execute.

5) Explain Java Program Structure?

i) Documentation Section

ii) Package declaration statement

Ex: package abcd;

iii) Import Statement/s

We import Built in and User defined libraries using import keyword.


import java.lang.*;

java - project

io - Package

Console - Class

iv) Class declaration
public class Sample {

public - Access Modifier

class - Java keyword/reserved word to declare class

Sample - Class name
v) main Method (Java Program execution starts from main method)

public static void main (String [] args) {

public - Access Modifier

static - Non-Access Modifier(use main method without invoking any Object.)

void - Returns Nothing

main - method name
(String [] args)
vi) Declarations

We declare Variables and Constants.

int a;
a =10;

int b =20;

int a, b, c;

int a=10, b=20, c=30, d;

final int y;
y=213; //Incorrect

final int x =100;
x=200; //Incorrect

vii) Normal Statements

d = a + b + c;


System - Class
out - Object
println -Method
viii) Code blocks

Condition blocks

Loop Blocks

Method Blocks etc...
6) What are Modifiers in Java?

Modifiers are keywords that we add to those definitions to change their meaning.

Two types of Modifiers in Java

a) Access Modifiers

b) Non Access Modifiers

7) What are Access Modifiers?

We use access modifiers to define access control for classes, methods and variables.

i) public

public access modifiers is accessible everywhere.

public class Sample{

ii) private

The private access modifier is accessible only within class.

private int a=100;

iii) default

If we don't specify any modifier then it is treated as default, this can be accessible only within package.

class Sample {

iv) protected

The protected modifier is accessible within package, outside of the package but through Inheritance.

protected class Sample {

8) What is Variable?

A named memory location to store the temporary data within a program.

Two types of memory in Computer environment.

a) Primary memory (RAM)

b) Secondary memory (ROM - HDD, DVD, USB drive etc...)

Note: Variables store in Primary memory.

9) What are the naming restrictions to create Variables?

Variable Naming restrictions

i) Java Variables are case sensitive.

ii) Java variable names should start with a letter or $ or _

iii) Variable names should not match with Java Keywords/Reserved words

iv) Must be unique in the scope of declaration.

v) Must not exceed 255 characters.

10) What are types of Variables in Java?

Three types of Variables in Java:

i) Local Variables

ii) Instance Variables

iii) Class / Static Variables


Post a Comment