Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Java - Interview Questions and Answers

   next 100
 Q101. What is the difference between the following two code lines ?

1. new OuterClass().new InnerClass();

2. new OuterClass.InnerClass();
Core Java2016-06-30 14:45:37

Ans. In first case we are trying to initialize Inner class object using the instance of Outer Class whereas in second case we are trying to initialize the Inner class object directly using the Outer class name.

In second case , Inner class is "static inner class" as we cannot access "non static inner class" using Classname alone.

In first case, the inner class could be either "static inner class" or "non static inner class".

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     inner classes  inner class   static inner class   new operator


 Q102. Why HashTable has been deprecated ?Core Java2016-07-08 10:01:58

Ans. HashTable has been Deprecated as an alternative ConcurrentHashMap has been provided which uses multiple buckets to store data and hence much better performance than hashtable. Moreover there is already a raw type hashmap. The only difference between the HashTable and HashMap is that Hashtable is synchronized whereas HashMap is not. Most of the synchronized collections have been deprecated and their raw alternative have been presented as preferred.

Synchronization has a cost. Using synchronized collection at a place where there is hardly any need of it would means useless utilization of resources. As these collections are rarely used in static context or shared among threads, Java might have thought it better to just provide the raw collection and let developer implement synchronization if he feels the need to do so.

As HashMap has been presented as default and preferred way of using Map with read optimized hashing, and ConcurrentHashMap has been provided for synchronized access which provides better performance than HashTable, Java thought it right to deprecate the use of HashTable.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     hashtable  synchronized collections  Why synchronized collections have been deprecated  Why HashTable has been deprecated  HashTable vs HashMap      expert

Try 3 Question(s) Test


 Q103. What are the different uses of Interfaces in Java ?Core Java2016-07-20 15:14:43

Ans. 1. Regulation / Enforcement / Policy / Contract , It's primary use

2. Use as a collection of utility methods(since java 8 through default methods)

3. Collecting constants together, As Interface are lighter, it makes sense to use them instead of classes if no getters and setters required.

4. Creation of Custom Annotations

5. Special services like marker interface

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     interfaces   uses of interfaces in java     BMC Software


Frequently asked to fresh graduates.
 Q104. What is ACID ?Database2016-11-04 08:09:44

Ans. ACID stands for Atomicity, Consistency, Isolation, Durability is a set of properties of database transactions.

Atomicity means all or nothing. i.e parts of a transaction shouldn't commit if any one of them fails. Either the whole transaction should succeed or it should be complete rollback.

Consistency means that any transaction should lead database from one stabe state to another.

Isolation means that the execution of transaction results in a system state that would be obtained if transactions were executed serially.

Durability means that when a transaction is committed it forms the permanent state of database.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     database  acid     CapitalOne   Tata Consultancy (TCS)  SilverRail Technologies  A9.com  Oracle  Sirius Computer Solutions      Intermediate

Try 1 Question(s) Test


Basic and Very Frequently asked.
  Q105. What is Polymorphism in Java ?Core Java2016-11-06 09:10:54

Ans. Polymorphism means the condition of occurring in several different forms.

Polymorphism in Java is achieved in two manners

1. Static polymorphism is the polymorphic resolution identified at compile time and is achieved through function overloading whereas

2. Dynamic polymorphism is the polymorphic resolution identified at runtime and is achieved through method overriding.

  Sample Code for overloading

  Sample Code for overriding

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     polymorphism  oops concepts     Credit Suisse  Unbounded Solutions  Microsoft   Google  Purch  HCL Technologies  Tata Consultancy (TCS)  Wipro  Mathworks  Accenture  ZonOff  ZapCom  Addteq  Priceline.com  Acute Informatics  Trimax IT Infrastructure & Services   USAA      Basic        frequent

Try 2 Question(s) Test


 Q106. Why two types of memory - stack and heap are required by Java ?Core Java2016-12-21 13:08:55

Ans. Because of the life cycle requirement for different type of values in java.

variables initialized and used in functions needs to be destructed with the execution of function and hence kept in stack. Same is applicable for the object references initialized within the method. If objects would have been created in stack, they wouldnt have been passed around across methods and hence they are created on heap.

So anything that is required beyond the scope of a method or function is kept on heap which is usually garbage collected by Java.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     memory management  heap  stack

Try 1 Question(s) Test


 Q107. What do you look for when you do code review ?Core Java2016-12-28 13:59:38

Ans. Modularity - First sign of good code is whether it has been segregated into methods and classes appropriately. I dont mind it in excess because I believe that is forward looking strategy as applications tends to expand and eventually become hard to read.

Self Explanatory - Variables and methods should be named in a way that the code should be self explanatory even without comments. Use of Constant variables to explain use of literal.

Proper Code Reuse - If there is anything being reused , it should be moved to parent classes / methods.

Proper composition calls - Composed hierarchy should not be access in just single line. One or two levels is ok but having multiple levels make it hard to read and debug.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     code review  clean code


 Q108. What are different types of variables a class can have ?Core Java2017-01-07 16:58:43

Ans. 1. Method local variables - These are declared and defined within a method ( instance or static methods ) and their scope is limited to the method itself. They are destructed once the execution of method completes. They are stored in stack memory.

2. Instance variables - These are declared as non static variables as part of the class.They are initialized as part of object creation ( constructor ) and are destructed by java's garbage collection mechanism and hence stored in heap.

3. Static variables - These are declared with the static keyword and are part of the class. They are initialized at the time of class loading and are destructed by java's garbage collection mechanism and hence stored in heap.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java variables


  Q109. What are Inner , Outer , Left and Right Joins in SQL ?Database2017-01-09 13:07:55

Ans. Inner join is the intersection of two tables on the condition defined by the where clause i.e will get records from both tables matched by a column.

Outer join is the union of two tables i.e will get all records from both tables and will put null in the columns where related records are not present.

Left Outer join is the left union of two tables i.e all records from the table on the left and values from the right table for related records else null for the columns from right table.

Right Outer join is the right union of two tables i.e all records from the table on the right and values from the left table for related records else null for the columns from left table.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     sql  inner join  outer join  right join  left join     EPAM  Antra  MSCI  HCL Technologies  Cognizant (CTS)  Morgan Stanley  Wipro  Infosys  Accenture  IBM  PayPal  A9.com  Curriculum Associates  Gold Coast IT  Kobie Marketing  Hybris  Aptroid Technologies  E2open  IGATE  SnapDeal  Verilogue  Span Infotech      basic        frequent



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q110. Can we have multiple main methods in a single class ?Core Java2017-01-12 11:00:02

Ans. We can overload the main method by specifying different argument types. For example -

2 main methods with different arguments is perfectly legal

public static void main();
public static void main(String[] args);

The following are not legal as compiler will complain of duplicate methods

public static void main(String[] args);
public static void main(String[] args);

Even The following are not legal as we cannot overload on return types

public static String main(String[] args);
public static void main(String[] args);

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     main method     HCL Technologies  SapientNitro


 Q111. Which elements of a class are ignored during serialization ?Core Java2017-01-12 11:08:21

Ans. 1. Objects are serialized and not classes and hence Static variables are ignored.

2. Transient is an explicit declaration to ignore the variable during serialization and hence transient instance variables are ignored too.

3. Base class instance variables if the base class hasn't been declared serializable.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     serialization     HCL Technologies      intermediate        frequent

Try 1 Question(s) Test


 Q112. Can we declare static variables as transient ?Core Java2017-01-12 11:12:48

Ans. It's weird that compiler doesn't complain if we declare transient with static variable because it makes no sense. At least a warning message saying "transient is useless in this situation" would have helped with code cleaning.

Static variables are never serialized and transient is an indication that the specified variable shouldn't be serialized so its kind of double enforcement not to serialize.

It could be that as it makes no different to the variable behavior and hence using both keywords with a variable are permitted.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     static  transient  serialization     HCL Technologies      expert        rare

Try 1 Question(s) Test


 Q113. Which of the following are valid declarations

1. void method(int... x){};
2. void method(int.. x){};
3. void method(int.. .x){};
4. void method(int ...x){};
5. void method(int... x){};
6. void method(int ... x){};
7. void method(int x, int... y){};
8. void method(int... x, int y){};
9. void method(int... x,int... y){};
Core Java2017-05-22 21:22:57

Ans. 1st is a valid and standard declaration.

2nd results in compilation error as only 2 dots are there.

3rd results in compilation error as three dots are not consecutive and broken.

4 through 6 may not be standard and ideal way of declarations but they are valid and will compile and work fine.

7 is valid declaration.

8 and 9 will result in compilation error as var args can only be provided to last argument.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     var args  methods  functions   method declaration  scjp  ocjp


 Q114. What is the difference between these two method declarations ?

private static void method(String[] arg)

and

private static void method(String... arg)
Core Java2017-05-23 08:41:54

Ans. First expects the argument as a string array whereas second expects variable number of string arguments or a string array.

So we can call both by providing string array as an argument but second can be called with 0 to n string arguments which cannot be done for first.

for example - We can call second method with any of following

method();
method("Hello");
method("Hello","World");
method(new String[4]);


 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     var args  methods  method declarations  functions


Very frequently asked in HCL Tech ( Based of 4 inputs )
  Q115. Write a Program to reverse a string iteratively and recursivelyCore Java

Ans. Using String method -

new StringBuffer(str).reverse().toString();

Iterative -

Strategy - Loop through each character of a String from last to first and append the character to StringBuilder / StringBuffer

public static String getReverseString(String str){
StringBuffer strBuffer = new StringBuffer(str.length);
for(int counter=str.length -1 ; counter>=0;counter--){
strBuffer.append(str.charAt(counter));
}
return strBuffer;
}

Recursive -

Strategy - Call the method with substring starting from 2nd character recursively till we have just 1 character.

public static String getReverseString(String str){
if(str.length <= 1){
return str;
}
return (getReverseString(str.subString(1)) + str.charAt(0);
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     string  StringBuffer  recursion  for loop  stringbuffer.append  java.lang.String  java.lang.StringBuffer  String Manipulation     HCL Technologies  Ocado  BlackRock  Oracle  FINRA  Arezzo Sky  Zalando  Boeing        frequent


  Q116. What are the different types of inner classes ?Core Java
Anonymous
Ans. Simple Inner Class,
Local Inner Class,
Anonymous Inner Class,
Static Nested Inner Class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   inner classes   classes     Infosys  Tata Consultancy (TCS)  HCL Technologies  IBM  IBM India  Gateway Media      basic        frequent

Try 1 Question(s) Test


Very Frequently asked across all type of companies and across all levels.
  Q117. Difference between Public, Private, Default and Protected ?Core Java
Anonymous
Ans. Private - Not accessible outside object scope.

Public - Accessible from anywhere.

Default - Accessible from anywhere within same package.

Protected - Accessible from object and the sub class objects.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oop   access specifier   public   private   default   protected   basic interview question     HCL Technologies  Tata Consultancy (TCS)  IBM  Wipro  Deegit  Argonne National Laboratory  Motorola Mobility  Accenture  Deegit  Cerner      basic        frequent

Try 1 Question(s) Test


 Q118. What are the Wrapper classes available for primitive types ?Core Java
Anonymous
Ans. boolean - java.lang.Boolean
byte - java.lang.Byte
char - java.lang.Character
double - java.lang.Double
float - java.lang.Float
int - java.lang.Integer
long - java.lang.Long
short - java.lang.Short
void - java.lang.Void

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java5   data types   wrapper classes   adapter design pattern        rare


 Q119. Does Constructor creates the object ?Core Java
Anonymous
Ans. New operator in Java creates objects. Constructor is the later step in object creation. Constructor's job is to initialize the members after the object has reserved memory for itself.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   constructor   object creation      intermediate        rare



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



  Q120. Does Java support Multiple Inheritance ?Core Java
Anonymous
Ans. Java doesn't support multiple inheritance. Interfaces does't facilitate inheritance and hence implementation of multiple interfaces doesn't make multiple inheritance.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oop   oop concepts   inheritence   multiple inheritence   basic interview question     Credit Suisse  Sun Microsystems  VMware  NSEiT  Exterro  theScore  JP Morgan  Computrade Israel      basic        frequent

Try 1 Question(s) Test


Very frequently asked. Favorite question in Walk in Drive of many Indian service companies.
  Q121. What is a Final Variable ?Core Java
Anonymous
Ans. Final variable is a variable constant that cannot be changed after initialization.

  Sample Code for final variable

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     oops   java   final   final variable   basic interview question     IBM  Goldman Sachs  TrueCar  Intertek  RedMane  Antra  HCL Technologies  Tata Consultancy (TCS)  Accenture  Forte Group  Mastercard      basic        frequent

Try 1 Question(s) Test


 Q122. Which String class does not override the equals() and hashCode() methods, inheriting them directly from class Object?Core Java
Anonymous
Ans. java.lang.StringBuffer.

  Sample Code for StringBuffer

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   object class   stringbuffer      expert        rare


Very frequently asked. Favorite question in Walk in Drive of many Indian service companies.
  Q123. What is a final method ?Core Java
Anonymous
Ans. Its a method which cannot be overridden. Compiler throws an error if we try to override a method which has been declared final in the parent class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   final   final method     Oracle  Intertek  HCL Technologies  Tata Consultancy (TCS)  Accenture   IBM  Goldman Sachs   TrueCar   Intertek RedMane   Antra      basic        frequent

Try 1 Question(s) Test


 Q124. When are static variables loaded in memory ?Core Java
Anonymous
Ans. They are loaded at runtime when the respective Class is loaded.

  Sample Code for static variable

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   static   static variable   memory      intermediate


 Q125. Can we serialize static variables ?Core Java
Anonymous
Ans. No. Only Object and its members are serialized. Static variables are shared variables and doesn't correspond to a specific object.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     serialization   java   oops   static   static variables     Deloitte      intermediate        rare

Try 2 Question(s) Test


 Q126. There are two objects a and b with same hashcode. I am inserting these two objects inside a hashmap.

hMap.put(a,a);
hMap.put(b,b);

where a.hashCode()==b.hashCode()

Now tell me how many objects will be there inside the hashmap?
Core Java
Anonymous
Ans. There can be two different elements with the same hashcode. When two elements have the same hashcode then Java uses the equals to further differentation. So there can be one or two objects depending on the content of the objects.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   hashcode   map   hashmap   object reference   advanced


Frequently asked to fresh graduates and less experienced developers.
 Q127. Explain multithreading in Java ?Core Java
Anonymous
Ans. 1. Multithreading provides better interaction with the user by distribution of task

2. Threads in Java appear to run concurrently, so it provides simulation for simultaneous activities.The processor runs each thread for a short time and switches among the threads to simulate sim-ultaneous execution (context-switching) and it make appears that each thread has its own processor.By using this feature, users can make it appear as if multiple tasks are occurring simultaneously when, in fact, each is running for only a brief time before the context is switched to the next thread.

3. We can do other things while waiting for slow I/O operations.In the java.iopackage, the class InputStreamhas a method, read(), that blocks until a byte is read from the stream or until an IOExceptionis thrown. The thread that executes this method cannot do anything elsewhile awaiting the arrival of another byte on the stream.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   threads   multi threading  concurrency   multithreading     Hamsini ECommerce   Cognizant (CTS)  Cumulus Systems  Cognizant (CTS)      intermediate        frequent

Try 1 Question(s) Test


 Q128. Can constructors be synchronized in Java ?Core Java
Anonymous
Ans. No. Java doesn't allow multi thread access to object constructors so synchronization is not even needed.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     synchronization   synchronize   constructor   java   multithreading   yes-no   advanced     Tieto      expert        rare


 Q129. Can we use null as a key for a map collection ?Core Java
Anonymous
Ans. Yes , for HashMap. HashMap implements Map interface. HashMap allows one null key and any number of null values.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   collections   hashmap   map   hashtable   yes-no     BlackBerry



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



Frequently asked in all types of companies especially Indian Services companies. Frequently asked in CTS (Based on 2 feedback)
 Q130. What is the use of hashcode in Java ?Core Java
Anonymous
Ans. Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc. The value received from hashcode() is used as bucket number for storing elements. This bucket number is the address of the element inside the set/map. when you do contains() then it will take the hashcode of the element, then look for the bucket where hashcode points to and if more than 1 element is found in the same bucket (multiple objects can have the same hashcode) then it uses the equals() method to evaluate if object are equal, and then decide if contain() is true or false, or decide if element could be added in the set or not.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   collections   hashcode   advanced     Cognizant (CTS)  Compro Technologies  VigLink  Proofpoint      intermediate        frequent

Try 1 Question(s) Test


 Q131. What are wrapper classes ?Core Java
Anonymous
Ans. They are wrappers to primitive data types. They allow us to access primitives as objects.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   data types   wrapper classes     CSL  Xoriant  Webilent      basic        frequent


Usually asked only to fresh graduates.
 Q132. What is the difference between time slicing and preemptive scheduling ?Operating System
Anonymous
Ans. In preemptive scheduling, highest priority task continues execution till it enters a not running state or a higher priority task comes into existence. In time slicing, the task continues its execution for a predefined period of time and reenters the pool of ready tasks.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     operating system   scheduling   threads   multi threading        rare


  Q133. What is casting?Core Java
Anonymous
Ans. There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   data types   casting   basic interview question     Mindtree  HCL Technologies  Wipro  Tata Consultancy (TCS)  Infosys  KPMG      basic        frequent


 Q134. What is JSON ?Json
Anonymous
Ans. JSON is "JavaScript Object Notation", primarily used for client-server or server-server communication. Its a much lighter and readable alternative to XML. JSON is language independent and is easily parse-able in all programming languages.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     json   markup language   client server communication      basic        frequent

Try 2 Question(s) Test


 Q135.  What is the role of JSON.stringify ?Json
Anonymous
Ans.  JSON.stringify() turns an object into a JSON text and stores that JSON text in a string. 

So If we stringfy above notation , it will become

{"name":"xyz","gender":"male";"age":30}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     json   JSON.stringify      intermediate        rare


 Q136. Which function is used to convert a JSON text into an object ?Json
Anonymous
Ans. eval

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     json   markup language


 Q137. Which data types are supported by JSON ?Json
Anonymous
Ans. Number
String
Boolean
Array
Object
null

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     json   markup language   client server communication


 Q138. What is an API ( Application Programming Interface ) ?
Anonymous
Ans. An API is a kind of technical contract which defines functionality that two parties must provide: a service provider (often called an implementation) and an application. an API simply defines services that a service provider (i.e., the implementation) makes available to applications.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     j2ee   api   java      basic        frequent


 Q139. What is URL?
Java EE
Anonymous
Ans. URL is Uniform Resource Locator which is representation of HTTP address.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     j2ee   http   internet   url      basic        rare



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q140. What is HTTP ?Java EE
Anonymous
Ans. HTTP or Hypertext Transfer Protocol is internet protocol for tranmission of hypertext ( text with meta data ) over internet.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     j2ee   http   internet  fidelity     Myntra  AOL Inc      basic        frequent


 Q141. Is tomcat an application or Web server ?
Anonymous
Ans. Application server.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     tomcat   j2ee   web server   application server   build management


 Q142. Is Apache an application or Web server ?
Anonymous
Ans. Web server.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     apache   web server   j2ee


 Q143. What are the default or implicitly assigned values for data types in java ?
Anonymous
Ans. boolean ---> false
byte ----> 0
short ----> 0
int -----> 0
long ------> 0l
char -----> /u0000
float ------> 0.0f
double ----> 0.0d
any object reference ----> null

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   data types   default values

Try 1 Question(s) Test


 Q144. Can I import same package/class twice? Will the JVM load the package twice at runtime?Core Java
Anonymous
Ans. One can import the same package or same class multiple times. Neither compiler nor JVM complains wil complain about it. And the JVM will internally load the class only once no matter how many times you import the same class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   import   jvm   advanced     Gateway Media      intermediate        rare


 Q145. Which access specifier can be used with Class ?
Anonymous
Ans. For top level class we can only use "public" and "default". We can use private with inner class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   class   access specifier   inner class      basic        frequent


 Q146. What is meant by an "asynchronous event." Give some examples ?Operating System
Anonymous
Ans. An asynchronous event is one that occurs at an unpredictable time outside the control of the program that the CPU is running. It is not "synchronized" with the program.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     j2ee   internet   web application   asynchronus   asynchronus communication   architecture     Alten India


 Q147. What are meta Annotations ?
Anonymous
Ans. Annotations that apply to other annotations are called meta-annotations.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   annotations   meta annotations


 Q148. How to display and set the Class path in Unix ?
Anonymous
Ans. To display the current CLASSPATH variable, use these commands in UNIX (Bourne shell):

% echo $CLASSPATH

To delete the current contents of the CLASSPATH variable,

In UNIX: % unset CLASSPATH; export CLASSPATH

To set the CLASSPATH variable,

In UNIX: % CLASSPATH=/home/george/java/classes; export CLASSPATH

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     unix   unix commands   classpath


 Q149. Difference between Abstract and Concrete Class ?Core Java
Anonymous
Ans. Abstract classes are only meant to be sub classed and not meant to be instantiated whereas concrete classes are meant to be instantiated.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   abstract classes   basic interview question     Goldman Sachs      basic        frequent



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q150. Different ways of implementing Threads in Java ?Core Java
Anonymous
Ans. Threads in Java can be implement either by Extending Thread class or implementing runnable interface.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   threads   multi threading     Cognizant (CTS)      basic        frequent


Frequently asked question for intermediate developers.
  Q151. What is Volatile keyword used for ?Core Java
Anonymous
Ans. Volatile is a declaration that a variable can be accessed by multiple threads and hence shouldnt be cached.

  Sample Code for volatile

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   synchronization   volatile   java keywords     ABC Ltd   Ciena  Xchanging  Square  Infoview Technologies  HCL Technologies  EPAM  GrubHub  TeleMessage  TRUSTe  Informatica  Square  Medidata Solutions  Yellow Pages  eQ Technologic  Sutra Analytics  CustomerXPs  Globant  BB Holdings  Rakuten  Booking.com  BlackRock  Qualcomm  LSI Corporation  ARM Holdings  SpaceX  Toshiba  Peapod  Amadeus  Apptio  Tivo  EchoStar  HomeAway  Syscom Technologies  Aversan  Symantec  Samsung India  Axtria  Qualcomm  CGI Group      intermediate        frequent

Try 1 Question(s) Test


  Q152. What is Serialization ? Why do we need it ?Core Java
Anonymous
Ans. Storing the state of an object in a file or other medium is called serialization.

Classes can communicate only if they are built together ( as they need Byte code for communication ). What if we need to enable communication between different applications ( i.e they have been built independently or even they reside at different locations ), We need a mechanism that will transfer the Bean state to a Medium than can be transferred to the receiving application.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   serialization     Computer Sciences Corporation (CSC) India   Tieto  Uproar  Priceline.com  HCL Technologies  Cognizant (CTS)      basic        frequent

Try 1 Question(s) Test


 Q153. What is the use of Transient Keyword ?Core Java
Anonymous
Ans. It in Java is used to indicate that a field should not be serialized.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   serialization   transient   java keywords     Cognizant (CTS)  The Advisory Board Company      intermediate        frequent

Try 2 Question(s) Test


 Q154. What is a Final Method ?Core Java
Anonymous
Ans. A Method that cannot be overriden in the sub class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   java keywords   final   final method   overriding   basic interview question      basic        frequent

Try 1 Question(s) Test


Very Frequently asked.Favorite question in Walk in drive for many Indian service companies.
 Q155. What is a Final Class ?
Anonymous
Ans. A Class that cannot be sub classed.

  Sample Code for final class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   final   final class   java keyword   basic interview question     HCL Technologies  Tata Consultancy (TCS)  Infosys      basic        frequent


Very frequently asked. Usually asked with questions related to String.
  Q156. What is an Immutable Object ?Core Java
Anonymous
Ans. Object that can't be changed after instantiation.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   immutable     LiveSocialize Technologies  Oracle  Bureau Veritas  AudioCodes  GCPL Technologies  Infogain  Goldman Sachs  JP Morgan  Incture Technologies  Novell  Amisoft Technologies  Xactly Corp  Amisoft Technologies  Sunrun  Cognizant (CTS)  Hortonworks  AdNovum  Aquent   V-Soft  Sears  Idexcel  Infusion  Knight Capital  Bally Technologies  Yatra Online  Multivision (Virginia)  Portware LLC      basic        frequent

Try 2 Question(s) Test


Very Frequently asked. Usually asked along with String Class related questions.
 Q157. What is an immutable class ?Core Java
Anonymous
Ans. Class using which only immutable (objects that cannot be changed after initialization) objects can be created.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   immutable   immutable class   string class   basic interview question   ebay     Cognizant (CTS)  Hybris  YuMe  ebizAutos      Basic        frequent

Try 2 Question(s) Test


 Q158. How to implement an immutable class ?Core Java
Anonymous
Ans. We can make a class immutable by

1. Making all methods and variables as private.

2. Setting variables within constructor.

Public Class ImmutableClass{

private int member;
ImmutableClass(int var){
member=var;
}
}

and then we can initialize the object of the class as

ImmutableClass immutableObject = new ImmutableClass(5);

Now all members being private , you cant change the state of the object.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   immutable   immutable class   technical lead     Deloitte  Pramati Technologies  JPMorgan Chase  Mastercard      intermediate        frequent

Try 2 Question(s) Test


 Q159. Does Declaring an object "final" makes it immutable ?Core Java
Anonymous
Ans. Only declaring variables as final makes them immutable. Making objects final means that the object handler cannot be used to target some other object but the object is still mutable.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   final   immutable   immutable object



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q160. Can we override static methods ? Why ?Core Java
Anonymous
Ans. No.

Static methods belong to the class and not the objects. They belong to the class and hence doesn't fit properly for the polymorphic behavior.

A static method is not associated with any instance of a class so the concept of overriding for runtime polymorphism using static methods is not applicable.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   static   static methods   java keywords   yes-no      intermediate        frequent


 Q161. Can we reduce the visibility of the inherited or overridden method ?Core Java
Anonymous
Ans. No.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   access specifier   overriding   overridding   inheritence   yes-no


 Q162. Name few Java Exceptions ?Core Java
Anonymous
Ans. IndexOutofBoundException ,
NoClassDefFoundException ,
OutOfMemoryException ,
IllegalArgumentException,
NullPointerException,
IllegalStateException

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   exceptions   basic interview question      basic        frequent


Frequently asked to fresh graduates and less experienced.
 Q163. Which of the following is tightly bound ? Inheritance or Composition ?Core Java
Anonymous
Ans. Inheritance.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     inheritance   java   oops   composition     Deegit      basic        frequent


 Q164. How can we make sure that a code segment gets executed even in case of uncatched exceptions ?
Anonymous
Ans. By putting it within finally.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   exceptions   finally   uncatched exceptions      basic        frequent


 Q165. What is "super" used for ?
Anonymous
Ans. Used to access members of the base class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   java keywords   super   basic interview question      basic        frequent


 Q166. What is "this" keyword used for ?
Anonymous
Ans. Used to represent an instance of the class in which it appears.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   java keywords   this   basic interview question      basic        frequent


 Q167. Difference between boolean and Boolean ?Core Java
Anonymous
Ans. boolean is a primitive type whereas Boolean is a class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   wrapper classes      basic        rare


Frequently asked to fresh graduates.
  Q168. Difference between Process and Thread ?Operating System
Anonymous
Ans. Process is a program in execution whereas thread is a separate path of execution in a program.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   threads   multi threading   operating system   basic interview question     Walt Disney  Goldman Sachs  Nuance  Bank of America  Cogent Infotech  Sogeti  Siemens  Veritas  Vudu  One97 Communications  Riverbed Technology  TK20  MZ  Utopia  LogicMonitor  Lockheed Martin  Lab49  IGATE  Intel Corp  Verint Systems  Kronos  Amazon.com  Citrix  Persistent Systems      basic        frequent


Frequently asked to fresh graduates.
  Q169. What is a Deadlock ?Operating System
Anonymous
Ans. When two threads are waiting each other and cant precede the program is said to be deadlock.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   threads   multi threading   operating system   deadlock  concurrency     Lime Wire  Perfect Sense  QuantCast  Aequitas NEO Exchange  Akuna Capital  Juniper Networks  Casale Media  Netflix  NetApp  Apple  AIG  Cpart  SnapStream Media  Cumulus Systems  Wissen Infotech  HedgeServ Corp  KeyIdeas Infotech  Verint Systems  BlackBerry  EverQuote      basic        frequent



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q170. Difference between Serialization and Deserialization ?Core Java
Anonymous
Ans. Serialization is the process of writing the state of an object to a byte stream. Deserialization is the process of restoring these objects.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   serialization   deserialization     Priceline.com   Tieto      basic        frequent

Try 1 Question(s) Test


 Q171. Explain Autoboxing ?Core Java
Anonymous
Ans. Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java5   autoboxing   wrapper classes     Cognizant (CTS)      basic        frequent


 Q172. What is an Enum type ?Core Java
Anonymous
Ans. An enum type is a special data type that enables for a variable to be a set of predefined constants

  Sample Code for enum

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java5   enum   basic interview question      basic        frequent

Try 2 Question(s) Test


 Q173. What are Wrapper Classes ? What are Primitive Wrapper Classes ?
Core Java
Anonymous
Ans. A wrapper class is any class which "wraps" or "encapsulates" the functionality of another class or component. A Wrapper Class that wraps or encapsulates the primitive data type is called Primitive Wrapper Class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   wrapper classes   primitive wrapper classes


 Q174. What Design pattern Wrapper Classes implement ?Design
Anonymous
Ans. Adapter.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   wrapper classes   adapter design pattern   design pattern


 Q175. What is "Import" used for ?Core Java
Anonymous
Ans. Enables the programmer to abbreviate the names of classes defined in a package.

  Sample Code for import

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   import   java keyword


 Q176. Different types of memory used by JVM ?Core Java
Anonymous
Ans. Class , Heap , Stack , Register , Native Method Stack.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   jvm   memory management   memory   advanced   architecture   technical architect     Priceline.com      intermediate        frequent

Try 5 Question(s) Test


 Q177. What is a class loader ? What are the different class loaders used by JVM ?Core Java
Anonymous
Ans. Part of JVM which is used to load classes and interfaces.

Bootstrap , Extension and System are the class loaders used by JVM.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   class loaders  classloaders   jvm   java memory management   advanced


 Q178. Can we declare interface methods as private ?
Anonymous
Ans. No.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   interfaces   yes-no   private


 Q179. What is a Static import ?Core Java
Anonymous
Ans. By static import , we can access the static members of a class directly without prefixing it with the class name.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java5   static import   static   java keyword   static import     Infosys  Weather Channel  Tata Consultancy (TCS)  ePace Technologies      basic        frequent



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



Very frequently asked. Usually difference between String,StringBuffer and StringBuilder is asked in different variations.
  Q180. Difference between StringBuffer and StringBuilder ?Core Java
Anonymous
Ans. StringBuffer is synchronized whereas StringBuilder is not.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   string   stringbuffer   string class   stringbuilder   synchronized   basic interview question   infosys technologies     Thomson Reuters  Ludia  QualiTest  United Health Group (UHG)  Sophos  JPMorgan Chase  ebay  Infosys Technologies  Experian India      basic        frequent

Try 1 Question(s) Test


 Q181. Difference between Map and HashMap ?Core Java
Anonymous
Ans. Map is an interface where HashMap is the concrete class.

  Sample Code for map

  Sample Code for hashmap

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   collections   hashmap   map      basic        frequent


 Q182. What is a Property class ?Core Java
Anonymous
Ans. The properties class is a subclass of Hashtable that can be read from or written to a stream.

  Sample Code for Load Properties using Property Class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   collections   hashtable   map   synchronization   synchronized


 Q183. Explain java.lang.OutOfMemoryError ?
Core Java
Anonymous
Ans. This Error is thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   exceptions   jvm   outofmemoryerror


 Q184. Can we have multiple servlets in a web application and How can we do that ?Java EE
Anonymous
Ans. Yes by making entries in web.xml

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     j2ee   servlets   servelets   web application   java   web.xml   yes-no   architecture


 Q185. How can we manage Error Messages in the web application ?Solution
Anonymous
Ans. Within message.properties file.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     j2ee   web application   struts   spring     Trimax IT Infrastructure


Frequently asked to fresh graduates.
 Q186. Is JVM, a compiler or interpretor ?
Anonymous
Ans. Its an interpretor.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   jvm   compiler   interpretor      basic        frequent


 Q187. Should we override finalize method ?
Anonymous
Ans. Finalize is used by Java for Garbage collection. It should not be done as we should leave the Garbage Collection to Java itself.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   garbage collection   java memory management   finalize

Try 2 Question(s) Test


 Q188. Difference between Factory and Abstract Factory Design Pattern ?Design
Anonymous
Ans. Factory Pattern deals with creation of objects delegated to a separate factory class whereas Abstract Factory patterns works around a super-factory which creates other factories.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   design pattern   factory design pattern   abstract factory design pattern   technical lead      expert


 Q189. Why do member variables have default values whereas local variables don't have any default value ?
Core Java
Anonymous
Ans. member variable are loaded into heap, so they are initialized with default values when an instance of a class is created. In case of local variables, they are stored in stack until they are being used.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   jvm   memory management   variables   stack memory   heap memory   default values      expert



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q190. How can we create objects if we make the constructor private ?Core Java
Anonymous
Ans. We can do so through a static public member method or static block.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   static   constructor   static method   static block  private     Jabong.com


 Q191. Is it necessary that each try block to be followed by catch block ? Core Java
Anonymous
Ans. It should be followed by either catch or finally block.

  Sample Code for Retry in case of exception

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   try   catch   finally  Oracle OCA Test     Accenture  Cognizant (CTS)      basic        frequent

Try 1 Question(s) Test


 Q192. What is exception propogation ?Core Java
Anonymous
Ans. Passing the exception object to the calling method.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   throw


 Q193. Difference between nested and inner classes ?
Anonymous
Ans. Inner classes are non static nested classes.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   static   nested classes   inner classes   basic interview question      basic        frequent

Try 1 Question(s) Test


 Q194. What is a nested interface ?
Anonymous
Ans. Any interface declared inside a class or an interface. It is static by default.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   nested classes


 Q195. What is an Externalizable interface ?
Anonymous
Ans. Externalizable interface is used to write the state of an object into a byte stream in compressed format.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   serialization   externalizable interface   interface     Egen Solutions  Xpanxion  MphasiS


 Q196. Difference between serializable and externalizable interface ?
Anonymous
Ans. Serializable is a marker interface whereas externalizable is not.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   serialization   externalizable   interface   marker interface


 Q197. What is reflection ?
Anonymous
Ans. It is the process of examining / modifying the behaviour of an object at runtime.

  Sample Code for reflection

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   reflection   reflection api   ebay   mindtree      basic        frequent


 Q198. Can we instantiate the object of derived class if parent constructor is protected ?Core Java
Anonymous
Ans. Yes, as protected constructor is accessible in sub class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   constructor   access specifier   protected   yes-no  private constructor


 Q199. What are the design considerations while making a choice between using interface and abstract class ?Core Java
Anonymous
Ans. Keep it as a Abstract Class if its a "Is a" Relationsship and should do subset/all of the functionality. Keep it as Interface if its a "Should Do" relationship.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   abstract classes   interfaces   advanced     ADP  AI corporation



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q200. Will this code give error if i try to add two heterogeneous elements in the arraylist. ? and Why ?

List list1 = new ArrayList<>();
list1.add(5);
list1.add("5");
Admin
info@buggybread.com
Ans. If we don't declare the list to be of specific type, it treats it as list of objects.

int 1 is auto boxed to Integer and "1" is String and hence both are objects.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   collections   arraylist   list   autoboxing   wrapper classes      expert        rare


previous 100   next 100


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

Redis: Its not a database but a kind ... Amit

Cassandra: Frequently used these days. Apt for storing ... Anonymous

Spring Boot: Though there is bit of learning curve ... Amit

Bank Of America: what value will be printed if A ... Anonymous

ZipRecruiter: It used to be good many years ... Anonymous

CareerBuilder: Carrier Builder is user friendly and you ... Anonymous

StackOverflow Jobs: I like stackoverflow and linkedin specifically for ... James

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: