Friday, 7 January 2022

Java 7 Interview Question's

New Features introduced from JAVA 7:

1) Using strings in switch statements

2) Binary values with prefix 0B (Example: int n = 0b1101)

3) Introducing of underscore in numeric values (Example: int n = 10_00)

4) Catching multiple exceptions

5) Type inference for generic instance creation

Example: Before Java 7: ArrayList<String> obj = new ArrayList<String>();

                After Java 7: ArrayList<String> obj = new ArrayList< >();

6) Try with resource statement

Example: Before Java 7: try { file = new FileInputStream ("file.txt");})

                After Java 7: try (FileInputStream file = new FileInputStream ("file.txt")){ })


JAVA 7 ELH Interview Questions:

1) What is the difference b/w an executable file and a .class file ?

Ans) Executable file contains machine language instructions for the microprocessor and is system dependent, whereas Class file contains byte code instructions for the JVM and is system independent.

2) Which part of JVM will allocate the memory for a java program ?

Ans) Class loader subsystem of JVM will allocate the necessary memory needed by the java program.

3) What is garbage collector and how it is used ?

Ans) Garbage collector is a form of memory management that checks the memory time to time and marks the variable or object not used by the program. After repeatedly identifying the same variable or object, garbage collector confirms that the variable or object is not used and hence it deletes.

        Garbage collector uses many algorithm's but the most common algorithm used by garbage collector is mark and sweep.

        Garbage collector is automatically invoked when a program is being run. It can also be called by calling gc() method of runtime class or system class in java.

4) What is JIT Compiler ?

Ans) JIT Compiler is a part of JVM which increases the maximum speed of execution of a Java program.

5) What is the difference b/w #include and Import ?

Ans) 

5) What happens if String args[] is not written in main method ?

Ans) The code will compile but JVM cannot run the code because it cannot recognize the main() method. JVM will always look for main() method with string type array as parameter to start execution of the java program.

6) What is the difference b/w float and double ?

Ans) float can represent up to 7 digits accurately after decimal point, whereas double can represent up to 15 digits accurately after the decimal point.

7) What is the difference b/w return and System.exit(0) ?

Ans) return statement is used inside a method to come out of it, whereas System.out(0) can be used any where to come out of it. 

8) 


No comments:

Post a Comment

Java 7 Interview Question's

New Features introduced from  JAVA 7 : 1) Using strings in switch statements 2) Binary values with prefix 0B (Example: int n = 0b1101) 3) In...