Java - Interview Questions and Answers for 'Objects' | Search Java 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

   



Interview Questions and Answers for 'Objects' - 58 question(s) found - Order By Newest

Very Very frequently asked. Among the first few questions in almost all interviews.Among Top 5 frequently asked questions.
  Q1. Difference between == and .equals() ?Core Java
Anonymous
Ans. "equals" is the method of object class which is supposed to be overridden to check object equality, whereas "==" operator evaluate to see if the object handlers on the left and right are pointing to the same object in memory.

x.equals(y) means the references x and y are holding objects that are equal. x==y means that the references x and y have same object.

Sample code:

String x = new String("str");
String y = new String("str");

System.out.println(x == y); // prints false
System.out.println(x.equals(y)); // prints true

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

   Like      Discuss      Correct / Improve     java   string comparison   string   object class   ==    equals   object equality     Ebay  Cerner  GuideWire  Expeditors Associate  Revature  SAIC  ValueLabs  Realty Redefined  Bank Of America  Capgemini  HCL Technologies  Goldman Sachs  Symmetric Corp  Backstop Solutions  Frontier  IQOR   Science  Vanguard  eClinicalWorks  Experticity  Blue Cross and Blue Shield of Kansas  ComTrade  Banja Luka  Overstock.com  Intrasoft International  IBM  Apex Systems  infoview technologies      basic        frequent

Try 6 Question(s) Test


 Q2. Why do we need Inner classes ? Cant we just work with outer classes wherever we implement Inner classes ?Core Java
Admin
info@buggybread.com
Ans. Yes, we can substitute outer classes wherever we need to have inner classes but Inner classes have advantage in certain cases and hence preferred -

Ease - Why to implement a class outside if its objects are only intended to be part of an outer object. Its easy to define the class within another class if the use is only local.

Protection - Making a call an outer exposes a threat of it being used by any of the class. Why should it be made an outer class if its object should only occur as part of other objects.

For example - You may like to have an class address whose object should have a reference to city and by design thats the only use of city you have in your application. Making Address and City as outer class exposes City to any of the Class. Making it an inner class of Address will make sure that its accessed using object of Address.

  Sample Code for 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   objects   technical lead      intermediate

Try 1 Question(s) Test


Frequently asked in Infosys and HCL Technologies ( Based on 2 feedback )
 Q3. What are different ways of object creation in Java ?Core Java
Admin
info@buggybread.com
Ans. Using new operator - new xyzClass()

Using factory methods - xyzFactory.getInstance( )

Using newInstance( ) method - (Class.forName(xyzClass))emp.newInstance( )

By cloning an already available object - (xyzClass)obj1.clone( )

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

   Like      Discuss      Correct / Improve     java   oops   object creation   new operator   class.forname   cloning   ebay     Intelligrape  Infosys  Polaris  British Telecom (BT)  Vyom Labs  Deutsche Bank  HCL Technologies      expert


 Q4. What are the common uses of "this" keyword in java ?Core Java
Anonymous
Ans. "this" keyword is a reference to the current object and can be used for following -

1. Passing itself to another method.

2. Referring to the instance variable when local variable has the same name.

3. Calling another constructor in constructor chaining.

  Sample Code for this keyword

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

   Like      Discuss      Correct / Improve     java   this   object reference   constructor chaining      intermediate        rare

Try 3 Question(s) Test


 Q5. Describe what happens when an object is created in Java ?Core Java
Anonymous
Ans. 1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data.
2. The instance variables of the objects are initialized to their default values.
3. The constructor for the most derived class is invoked. The first thing a constructor does is call the constructor for its superclasses. This process continues until the constructor for java.lang.Object is called,as java.lang.Object is the base class for all objects in java.
4. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.

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

   Like      Discuss      Correct / Improve     java   memory management   object creation   advanced   ebay


 Q6. What will this code print ?

String a = new String ("TEST");
String b = new String ("TEST");
if(a == b) {
System.out.println ("TRUE");
} else {
System.out.println ("FALSE");
}
Core Java
Anonymous
Ans. FALSE. == operator compares object references, a and b are references to two different objects, hence the FALSE. .equals method is used to compare string object content.

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

   Like      Discuss      Correct / Improve     string   string class   java   ==   object references   coding      basic        frequent

Try 1 Question(s) Test


Frequently asked. Favorite question in Walk in Drive of many Indian service companies.
  Q7. What are the methods of Object Class ?Core Java
Anonymous
Ans. clone() - Creates and returns a copy of this object.

equals() - Indicates whether some other object is "equal to" this one.

finalize() - Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

getClass() - Returns the runtime class of an object.

hashCode() - Returns a hash code value for the object.

toString() - Returns a string representation of the object.

notify(), notifyAll(), and wait() - Play a part in synchronizing the activities of independently running threads in a program.

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

   Like      Discuss      Correct / Improve     java   oops   object class     Capgemini  NIIT Technologies   Virtusa  Goldman Sachs  PwC  Citi  Expeditors  SoftFluent  LinkedIn  Amadeus  Navteq  PLC Systems  Axtria Associate  Netcracker Technology  Altisource      basic        frequent

Try 1 Question(s) Test


 Q8. What one should take care of, while serializing the object?
Anonymous
Ans. One should make sure that all the included objects are also serializable. If any of the objects is not serializable then it throws a NotSerializable Exception.

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

   Like      Discuss      Correct / Improve     serialization   java   oops   object      expert


 Q9. Difference between object instantiation and construction ?Core Java
Anonymous
Ans. Though It's often confused with each other, Object Creation ( Instantiation ) and Initialization ( Construction ) are different things in Java. Construction follows object creation.

Object Creation is the process to create the object in memory and returning its handler. Java provides New keyword for object creation.

Initialization is the process of setting the initial / default values to the members. Constructor is used for this purpose. If we don't provide any constructor, Java provides one default implementation to set the default values according to the member data types.

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

   Like      Discuss      Correct / Improve     java   oops   constructor   object instantiation



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. Difference Between this() and super() ?
Core Java
Admin
info@buggybread.com
Ans. 1.this is a reference to the current object in which this keyword is used whereas super is a reference used to access members specific to the parent Class.

2.this is primarily used for accessing member variables if local variables have same name, for constructor chaining and for passing itself to some method whereas super is primarily used to initialize base class members within derived class constructor.

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

   Like      Discuss      Correct / Improve     java   oops   class   objects   inheritence   constructor   this   super

Try 1 Question(s) Test


 Q11. Why Java is not considered pure OOP's language ?Core Java

Ans. There are 2 reasons for it.

1. Usage of Primitive types - Though Java provides classes for the primitive data types but as the usage of primitives is permissible, its considered unpure OOP's language.

2. Usage of Static members - Static members belong to the class and not objects and hence not considered fit for pure OOP's programming.

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

   Like      Discuss      Correct / Improve     oops  object oriented programming  object oriented language  primitive data types     BSL Information Technology  Data64


 Q12. 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


 Q13. 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


 Q14. 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


 Q15. 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


 Q16. Difference between new operator and Class.forName().newInstance() ?
Admin
info@buggybread.com
Ans. new operator is used to statically create an instance of object. newInstance() is used to create an object dynamically ( like if the class name needs to be picked from configuration file ). If you know what class needs to be initialized , new is the optimized way of instantiating Class.

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

   Like      Discuss      Correct / Improve     java   oops   object instantiation   object creation   class.forname   newinstance   new operator   difference between   advanced      intermediate


 Q17. If everything is an object , Cant we declare every object as

Object obj = new String();
Core Java2016-12-02 14:45:05

Ans. Yes, we can do that. Compiler wont complain. But using object reference we can only access methods which have been defined for object class i.e clone(), equals(), hashCode(), toString() etc.

We cannot access methods defined in String class or in any class in hierarchy between String and Object.

For example - we cannot do obj.append("abc") as it will now give compile time error.

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

   Like      Discuss      Correct / Improve     object initialization  object declaration   runtime polymorphism


 Q18. Difference between Class#getInstance() and new operator ?
Admin
info@buggybread.com
Ans. Class.getInstance doesn't call the constructor whereas if we create an object using new operator , we need to have a matching constructor or copiler should provide a default constructor.

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

   Like      Discuss      Correct / Improve     java   constructor   object creation   default constructor   getinstance   new operator


 Q19. What is an Object ?Core Java
Admin
info@buggybread.com
Ans. Object is a run time entity whose state is stored in fields and behavior is shown via methods. Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication.

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

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



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. Variable of the boolean type is automatically initialized as?Core Java
Admin
info@buggybread.com
Ans. The default value of the boolean type is false.

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

   Like      Discuss      Correct / Improve     java   data type   boolean   initialization   default object construction   default constructor   default value


 Q21. In a case where there are no instance variables what does the default constructor initialize?Core Java
Admin
info@buggybread.com
Ans. Java expects the superclass ( Object Class ) constructor to be called while creation of any object. So super constructor is called in case there are no instance variables to initialize.

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

   Like      Discuss      Correct / Improve     java   constructor   object creation   default constructor   super

Try 1 Question(s) Test


 Q22. Will this code compile fine ?

ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("newFile.txt")));
Core Java
Admin
info@buggybread.com
Ans. Yes.

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

   Like      Discuss      Correct / Improve     java   io   file   fileio   coding   code   objectoutputstream   fileoutputstream   yesno


 Q23. Can we declare Entity class as final ?Hibernate
Admin
info@buggybread.com
Ans. Yes but as Hibernate creates the Proxy Classes inherited from the Entity Classes to communicate with Database for lazy initialization. Declaring entity classes as final will prohibit communication with database lazily and hence will be a performance hit.

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

   Like      Discuss      Correct / Improve     hibernate   proxy objects   proxy classes   entity hibernate


 Q24. What are stateless objects ? How are they different from immutable objects ? Which of these two is thread safe ?
Admin
info@buggybread.com
Ans. Stateless objects are the objects without instance fields (instance variables). The class may have compile time constants i.e static final fields.

Immutable objects are the objects which have state but the state cannot be changed after initialization.

Both are Thread safe.

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

   Like      Discuss      Correct / Improve     java   stateless objects   immutable objects   objects   singleton scope


 Q25. What are advantages of stateless and / or immutable objects ?
Admin
info@buggybread.com
Ans. They can be shared across multiple threads as they are thread safe.

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

   Like      Discuss      Correct / Improve     java   stateless objects   immutable objects   objects


 Q26. What will be the output ?Integer a = 10, b =10;Integer c = 10, d = 1000;System.out.println(a == b);System.out.println(c ==d);Core Java
admin
info@buggybread.com
Ans. truefalse

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

   Like      Discuss      Correct / Improve     java   coding   equality   object equality


 Q27. Which of the following do you think is the primary reason you would never use a static class even the application doesn't need multiple requests or threads ?

a. Serialization
b. Runtime Polymorphism
c. Lazy Loading
d. Memory
Anonymous
Ans. Runtime Polymorphism

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

   Like      Discuss      Correct / Improve     static class   static vs singleton   java   oops   objects  Runtime Polymorphism


 Q28. What will the following code print ?

Integer a = 100, b =100;
Integer c = 1000, d = 1000;
System.out.println(a == b);
System.out.println(c ==d);
Core Java

Ans. false
false

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

   Like      Discuss      Correct / Improve     object equality  code  coding        frequent


 Q29. Can a lock be acquired on a class? How is it different than the object level lock ?

Ans. Yes, a lock can be acquired on the class. Class level lock is applicable on the whole class and hence on all objects of the class whereas the object level lock is applicable on the respective object.

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

   Like      Discuss      Correct / Improve     synchronization  class level lock  object level lock



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q30. What is DTO ?2016-06-16 08:30:10

Ans. DTO is Data Transfer Object i.e Pojo which is supposed to move between different layers of software architecture for transferring information. Example could be the object passed from client in case of web service call or the object passed to Persister for Database Persistence.

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

   Like      Discuss      Correct / Improve     DTO   Data Transfer Object      basic        frequent


 Q31. What is DAO ?2016-06-16 08:31:35

Ans. DAO is Data Access Object which is used within Persistence Layer to make Database Transaction. For example , the class holding the Database connection and CRUD methods.

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

   Like      Discuss      Correct / Improve     DAO  Data Access Object      basic        frequent


 Q32. What is POJO ?2016-06-16 08:33:49

Ans. POJO is Plain Java Object that holds only Member Elements , getters are setters and minimal processing on that. The primary purpose of such object is to either transfer information or keeping state for a while. They are not intended to provide any processing or transformation.

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

   Like      Discuss      Correct / Improve     POJO   Plain Java Objects


 Q33. What are VO ?2016-06-16 08:34:25

Ans. VO or Value objects are the objects that are supposed to hold some value. For Example , Integer, Float , Money etc.

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

   Like      Discuss      Correct / Improve     Value Objects


 Q34. Why do we use a copy constructor ?2016-07-21 08:28:52

Ans. Copy Constructor is used for creating a duplicate of another object. Duplicate object will have the same state of the copied object but will have independent values in different memory locations. Copy Constructor can be useful to create duplicates of immutable objects as the Original cannot be tampered. Moreover It can be useful if base copies are required for individual requests in threading.

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

   Like      Discuss      Correct / Improve     copy constructor  clone  cloning object


 Q35. Does it make sense to clone an object which is supposed to be immutable ?Design2016-07-28 20:54:59

Ans. It make sense only if we intend to modify either of the object and would like to preserve original state in other. Otherwise we can reuse the original object by making it singleton.

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

   Like      Discuss      Correct / Improve     clone  clone objects  prototype design pattern


 Q36. What is the difference between = and == in Java ?Core Java2016-09-02 08:12:45

Ans. = is the assignment operator that assigns the result of the expression on the right to the variable on the left, whereas

== is the operator to check object equality to see if the reference on left and right are pointing to the same object. For primitive types, its used to check if both variables holds the same value.

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

   Like      Discuss      Correct / Improve     =  ==  assignment operator  object equality  difference between      Basic


 Q37. How is == operator different for objects and primitive types ? Core Java2016-09-02 08:14:44

Ans. For objects or references, == operator check if the reference on left and right points to the same object.

For primitive types or variables, == operator check if the variable on left and right holds the same value.

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

   Like      Discuss      Correct / Improve     ==  object equality      Basic


 Q38. What is the default value of a declared object reference ?Core Java2017-01-12 11:05:03

Ans. Null

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

   Like      Discuss      Correct / Improve     object reference  null     HCL Technologies      basic


 Q39. Is there a way to know size of an object in Java ?Core Java2017-01-12 11:14:59

Ans. No, Java doesn't have a sizeOf operator. In C / C++ , its required to determine how much memory allocation is required which is not the case with Java. Java handles memory allocation and deallocation intrinsically.

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

   Like      Discuss      Correct / Improve     sizeOf  size of object     HCL Technologies        rare



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q40. Difference between shallow copy and object cloning ?Core Java2017-01-12 14:21:02

Ans. Shallow copy is one of the way for object cloning, other being deep copy.

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

   Like      Discuss      Correct / Improve     cloning  shallow copy  object cloning      basic


 Q41. What is a class and object ?

or

How would you explain a fresher the concept of class and object in simple terms ?
Core Java2017-01-19 12:39:36

Ans. Class is a template using which objects are created in memory. It's kind of a mold using which objects with body / state are made.


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

   Like      Discuss      Correct / Improve     class  object  class vs object     Nucleus Software Exports  GST Global      basic        frequent


 Q42. Can we override wait() or notify() methods?Core Java2017-01-19 13:59:12

Ans. wait and notify are declared final in object class and hence cannot be overridden.

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

   Like      Discuss      Correct / Improve     object class methods  wait  notify


 Q43. What are the benefits of creating immutable objects ?Core Java2017-01-22 16:01:54

Ans. 1. Security and Safety - They can be shared across multiple threads as they are thread safe. Moreover, it protects then from bad state due to interception by the other code segment. One such problem due to mutability and access by alternate code segment could be the change of hash code and then the impact on its search with hash collections.

2. Reuse - In some cases they can be reused as only one copy would exist and hence it can be relied upon. For example - String Pool

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

   Like      Discuss      Correct / Improve     immutable objects     Knight Capital      Intermediate        frequent


 Q44. How are the concept of Association related to Composition and Inheritance ?Core Java2017-02-06 16:18:04

Ans. Composition and Inheritance are the different types of Associations for Classes.

Composition is a has-a association between classes.
Inheritance is a is-a association between classes.

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

   Like      Discuss      Correct / Improve     composition  inheritance  association  relationship between objects


 Q45. What is ACL ?Operating System2017-03-01 09:45:12

Ans. Access Control List or ACL is the list of permissions attached to an object in the File System.

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

   Like      Discuss      Correct / Improve     acl  file system  file security  object security  operating system


 Q46. What could be the possible cause for following exception ?

org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect):

What could be the way to fix it ?
Hibernate2017-03-29 12:44:00

Ans. This looks like the case for optimistic locking wherein hibernate suspects that the information in table was updated by some other transaction after the entity was loaded by current transaction.

One way is to have synchronized entity state and don't detach the entity. Other could be to merge the entity with the table record rather than just directly persisting the entity.

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

   Like      Discuss      Correct / Improve     StaleObjectStateException  Optimistic locking


 Q47. What will be the output of following code

Integer x = 1;
Integer y = 2;
System.out.println(x == y);

What if you change 1 to "1" and Integer to String?
Core Java2017-05-07 19:30:13

Ans. It will print "true" with integers as well as strings. The reason is "Integer constant pool" and "String pool"

String pool maintains pool of string literals. When a string literal is used for the first time, a new string object is created and is added to the pool. Upon it's subsequent usage , the reference for the same object is returned. Similarly java uses integer constant pool.

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

   Like      Discuss      Correct / Improve     string pool  object equality  ==


 Q48. How can we destroy an object ? Core Java2017-05-07 20:39:20

Ans. We cannot explicitly initiate destruction of an object as no destroy method is available in java. Only Garbage collection can destroy an object.

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

   Like      Discuss      Correct / Improve     Garbage collection  object destruction     Sabre


 Q49. When does an object cleaned or destroyed by garbage collection ?Core Java2017-05-07 20:41:46

Ans. When it is no longer referenced or it looses all references which were earlier pointing to it.

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

   Like      Discuss      Correct / Improve     garbage collection  object destruction     Sabre



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q50. What is the difference between reference and object ?Core Java2017-05-13 20:20:48

Ans. Object is an entity in Java , i.e which has a state ( instance variables ) and methods attached to it ( static or non static , through class definition ). References are the identifiers that are used to point to objects.

For example -

Employee emp = new Employee();
emp = new Employee();

In this code, emp is the reference that gets assigned to the new object created by the new operator. In the second line , we have assigned the same reference to another object. So with these 2 lines of code, we have 2 objects in memory with reference emp now pointing to second object.

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

   Like      Discuss      Correct / Improve     reference  object  reference vs object      Basic        frequent


 Q51. What happens when you assign a pre initialized reference some other object ?Core Java2017-05-22 08:31:02

Ans. Now the reference points to a new object in memory. If that was the only reference for the previous object , it will be marked for garbage collection.

Foe example -

Object obj = new Object();
obj = new Object();

object created in first line will be eligible for garbage collection after line 2 as it looses all it's handlers.

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

   Like      Discuss      Correct / Improve     references  objects  garbage collection     UST Global


 Q52. What are the examples of immutable objects in Java ?Core Java2017-05-29 08:35:00

Ans. Following Classes in Java SE creates immutable objects

String class
Wrapper Classes like Integer, Float etc.
StackTraceElement
Most Enum classes
File Class
Locale Class

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

   Like      Discuss      Correct / Improve     immutable objects  immutable     Persistent Systems      Basic        frequent


 Q53. How would you explain the statement "Java Programs are collection of objects" ?Core Java2017-06-08 07:24:57

Ans. Java Programs are collection of objects that communicates with each other to get a task accomplished. To add to those objects, there are common spaces ( static i.e common for objects belonging to a class ) that are used too.

We can visualize objects as departments of an organization in real world. Just like Task gets initiated in one department and then files are moved across different departments to get work done. In a similar fashion, a task is initiated in one object ( having main method ) and then information ( through POJOs / DTOs ) is moved across objects to accomplish a task.

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

   Like      Discuss      Correct / Improve     objects  Java Programs are collection of objects  real life example of object communication


 Q54. What will be the output of following code

class TestMain {
public static void main(String[] args) {
String s1 = "ravi";
String s2 = new String("ravi");
Integer i = 10;
Integer a1 = new Integer("10");
System.out.println(s1 == s1);
System.out.println(i == a1);
}
}
Core Java2017-07-17 08:07:19

Ans. false
false

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

   Like      Discuss      Correct / Improve     object equality  ==  coding  code     XMSS


 Q55. How can we track of all objects created in an application ?Design2017-08-04 14:02:03

Ans. We can store the references in a collection by adding to those objects in the collection. We can create a class "ObjectRegistry" with a collection or multiple collections with a search algorithm to look for the already collected objects.

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

   Like      Discuss      Correct / Improve     objects


 Q56. What will be the output of following ?

String str1 = new String("String1");
String str2 = new String("String1");
System.out.print(str1 == str2);
System.out.print(str1.equals(str2));
str1 = str2;
System.out.print(str1 == str2);
Core Java
a. falsetruetrue
b. truetruetrue
c. truetruefalse
d. falsetruefalse

Ans.a. falsetruetrue

 Q57. What will be the output of following code ?

String str1 = "String1";
String str2 = "String1";
System.out.print(str1 == str2);
System.out.print(str1.equals(str2));
str1 = str2;
System.out.print(str1 == str2);
Core Java
a. falsetruetrue
b. falsefalsetrue
c. truetruetrue
d. falsefalsefalse

Ans.c. truetruetrue

 Q58. Which of following is not the method of object class ?Core Java
a. run
b. notify
c. wait
d. clone

Ans.a. run



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

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: