Tuesday, August 14, 2018

Some Useful Java Programs for Technical Interview

There are Some Useful Java Programs for Technical Interview, These Programs will help you in your Technical Interview Preparation.

Rules  : Rules are very tough, I am just kidding Don't take it seriously,
1. You have four options,
2. You should choose any one options within explanation,

So Lets Start

"To Ye Raha Apka Agla Saval Apki Screen Per" (#Hahahahaha)

Q 1. What will be the output of the following Program ?
class QuestionOne{
               public static void main(String arg[]){
                      int a=7,b=9;
                      int add = 0;
             if(add == 0){
                               add = a+b;
                              System.out.println("Addition is : "+add);
                         }
               else{
                              int sub = a-b;
                       }
                         System.out.println("Subtraction is : "+sub);
   }
}

A) 16
B) -2
C) print error
D) print Nothing


Answer
Answer : C
It will through a error symbol can not fild because of the sub variable have local scope, Or we print it outside of the else part.

Q2 : What will be the Output of the given Program ?
for( ; ; ){
            System.out.println("Hello World!");
}

A) print Hello World!
B) Runtime Error
C) Compilation Error
D) Create Infinite Loop


Answer
Answer : D
This Programe will create Infinite Loop, Because if You leave all the parts empty of for, There is no condition under where it will terminate the this loop.

Q3 : What is string pool in java ?

Answer
Answer : 
It is a special area in java heap to store the string literals like "java Query". When you create new string JVM first checks string in pool, If It's available in pool then it will return the same object from pool.

Q4 : How to move string object from heap to string pool  ?

Answer
Answer : 
string intern() is used
to move string object from heap to string pool.

Q5 : Does string is thread-safe in java ?

Answer
Answer : 
Yes, It is, string is immutable and we can not change the value of string, so it can be used in multi-thread environment.
, , ,

1 comment:


  1. Can you upload more questions for Java. Thanks in advance.

    ReplyDelete