Java most frequently asked interview questions ...



 1.      What is java?

Java is a high level object oriented programming language. It consists of mainly classes and objects. We can create any number of objects for a class. It was developed by Sun Microsystems. It was developed by James Gosling in June 1991. There are a lot of applications, websites, and games that are developed using java.

 2.      What are the primitive data types in java ?

Int

Double

float

Long

Char

Boolean

Short

byte

 3.      List some of features of java.

·        Simple – java is easy to learn.

·        Object oriented – Code reusability and maintenance will be good.

·        Portable – java supports read once write any where. Java program is converted to byte code which can run on any machine.

·        Platform independent –  java doesn’t depend on operating system to get executed.

·        Secured   java is secured because it doesn’t use explicit pointers.

·        Robust – java is a strong programming language as it uses strong memory management. The concepts like garbage collector, exception handling make it more robust.

·        High performance – As java uses ‘JIT – just in time’ compiler that reduces                          compile time.

4.      What is type casting in java?

It is a process of assigning a value of one primitive data type to another type.

Widening casting

Converting a smaller type to a larger type size.

Byte -> short -> char -> int -> long -> float -> double

Narrow casting

Converting a larger type to a smaller size type

Double -> float -> long -> int -> char -> short -> byte

 5.      What is JIT compiler ?

The compiler used by the java for compiling is JIT compiler. It is mainly used to improve the performance and reduces the amount of time needed for compilation.

 6.      What is function to find string length in java?

txt.length()

Example

String txt = "KJIHGFEDCBA";

System.out.println("The length of the txt string is: " + txt.length());

 

 7.      Mention some of the string methods in java.

txt.toUpperCase()

txt.toLowerCase()

txt.indexOf("sub-string"))

Example

String txt = "Hello World";

System.out.println(txt.toUpperCase());   // Output  HELLO WORLD

System.out.println(txt.toLowerCase());   //  Output  hello world

 

String txt = "i love java and python";

System.out.println(txt.indexOf("and"));   // Output 12

 8.      Mention some of the math functions in java.

·        Math.max(x,y)

·        Math.min(x,y)

·        Math.sqrt(x,y)

·        Math.abs(x)

·        Math.random()

9.      What do you know about ‘break’?

The break statement can be mainly in used in two forms.

1.      Switch case

The break is used to "jump out" of a switch statement.

2.      Loops

The break statement can also be used to “jump out” of a loop.

10.   What do you know about ‘continue’ in java?

The continue statement skips one iteration (in the loop), and continues with the next iteration in the loop.

 

11.   What is an array?

An array is a collection of similar data type items stored at contiguous memory locations.

12.   Any two applications of arrays.

·        Arrays can be used for CPU scheduling.

·        Used to implement other data structures like Stacks, Queues, Heaps, Hash tables, etc.

 

  1.   13.   What is method overloading?

In a class when multiple methods have same name but different parameters.

NOTE

Return types may or may not be same.

 

14.   Tell about scope in java.

a.      Method scope

Variables declared directly inside a method are available in that method only.

b.     Block scope

The code between curly braces {} is referred as a block. Variables declared inside blocks   are only accessible inside that specific block only I mean between the curly braces.

 

15.   What is recursion?

Recursion is the technique of making a function call itself. This technique provides a way to break complicated problems down into simple problems which are easier to solve.

 

16.   What is ‘HALTING CONDITION’ ?

If we consider a loop there is a problem called infinite looping. In recursion there is a problem called infinite recursion. Infinite recursion is when the function never stops calling itself. Every recursive function should have a halting condition, which is the condition where the function stops calling itself.

 

17.   What are various access specifiers in java?

a.      Public

The classes, methods, or variables which are defined as public, can be accessed by any class or method.

b.     Protected

Protected can be accessed by the class of the same package, or by the sub-class of this class, or within the same class.

c.      Default

Default are accessible within the package only.

d.     Private

The private class, methods, or variables defined as private can be accessed within the class only.

 

18.   What  is a package ?

Package in Java is a mechanism to encapsulate a group of classes, sub packages and interfaces.

It is also defined as collection of modules.

 

19.    

Previous Post
Next Post

post written by: