JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

Question: What is the difference between “==” and equals() method?


Answer:

The == (double equals) returns true, if the variable reference points to the same object in memory. This is called “shallow comparison”.

The equals() method calls the user implemented equals() method, which compares the object attribute values. The equals() method provides “deep comparison” by checking if two objects are logically equal as opposed to the shallow comparison provided by the operator ==.

If equals() method does not exist in a user supplied class then the inherited Object class's equals() method will be called which evaluates if the references point to the same object in memory. In this case, the object.equals() works just like the "==" operator.

<< Previous Question | Next Question >>

List Of Java Interview Questions:

  1. How garbage collector knows that the object is not in use and needs to be removed?
  2. Can Java thread object invoke start method twice?
  3. Give the list of Java Object class methods.
  4. Can we call servlet destory() from service()?
  5. Can we override static method?
  6. Can you list serialization methods?
  7. What is the difference between super() and this()?
  8. How to prevent a method from being overridden?
  9. Can we create abstract classes without any abstract methods?
  10. How to destroy the session in servlets?
  11. Can we have static methods in interface?
  12. What is transient variable?
  13. Incase, there is a return at the end of try block, will execute finally block?
  14. What is abstract class or abstract method?
  15. What is default value of a boolean?
  16. When to use LinkedList or ArrayList?
  17. What is daemon thread?
  18. Does each thread in java uses seperate stack?
  19. What is the difference between Enumeration and Iterator?
  20. Find out switch statement output.
  21. Does system.exit() in try block executes finally block?
  22. What is fail-fast in java?
  23. What is final, finally and finalize?
  24. In java, are true and false keywords?
  25. What are the different session tracking methods?
  26. What is the purpose of garbage collection?
  27. What are the types of ResultSet?
  28. What is difference between wait and sleep methods in java?
  29. What is servlet context?
  30. What happens if one of the members in a class does not implement Serializable interface?
  31. What is race condition?
  32. How to get current time in milli seconds?
  33. How can you convert Map to List?
  34. What is strictfp keyword?
  35. What is System.out in Java?
  36. What is difference between ServletOuptputStream and PrintWriter?
  37. What is java static import?
  38. When to use String and StringBuffer?
  39. What is difference between StringBuffer and StringBuilder?
  40. What is wrapper class in java?
  41. Is Iterator a Class?
  42. What is java classpath?
  43. Can a class in java be private?
  44. Is null a keyword in java?
  45. What is the initial state of a thread when it is started?
  46. What is the super class for Exception and Error?
  47. What is Class.forName()?
  48. Can interface be final?
  49. What is the difference between exception and error?
  50. What is default value of a local variables?
  51. What is local class in java?
  52. Can we initialise uninitialized final variable?
  53. Can we declare abstract method as final?
  54. Can we have finally block without catch block?
  55. What is pass by value and pass by reference?
  56. Can we declare main method as private?
  57. What is the difference between preemptive scheduling and time slicing?
  58. Can non-static member classes (Local classes) have static members?
  59. What are the environment variables do we neet to set to run Java?
  60. Can you serialize static fields of a class?
  61. What is the difference between declaring a variable and defining a variable?
  62. Where can we use serialization?
  63. What modifiers are allowed for methods in an Interface?
  64. What is the purpose of Runtime and System class?
  65. Which one is faster? ArrayList or Vector? Why?
  66. What is the difference between static synchronized and synchronized methods?
  67. What is the order of catch blocks when catching more than one exception?
  68. What is the difference between the prefix and postfix forms of the increment(++) operator?
  69. What is hashCode?
  70. What is the difference between Hashtable and HashMap?
  71. What are the restrictions when overriding a method?
  72. What is the use of assert keyword?
  73. What is adapter class?
  74. What is difference between break, continue and return statements?
  75. What is the difference between while and do-while statements?
  76. When does the compiler provides the default constructor?
  77. Difference between C++ and Java.
  78. Usages of java packages.
  79. What is dynamic class loading?
  80. What happens if you do not provide a constructor?
  81. Difference between shallow cloning and deep cloning of objects?
  82. Can we have interfaces with no defined methods in java?
  83. What is the difference between “==” and equals() method?
  84. How can you create an immutable class in java?
  85. What are access modifiers?
  86. Can we have private constructor in java?
  87. Why do we need generics in java?
  88. What is the difference between a product and a project?
  89. How does substring() method works on a string?
  90. What is the difference between a Java Library and a framework?
  91. Next set of java interview questions
Knowledge Centre
What is race condition?
A race condition is a situation in which two or more threads or processes are reading or writing some shared data, and the final result depends on the timing of how the threads are scheduled. Race conditions can lead to unpredictable results and subtle program bugs. A thread can prevent this from happening by locking an object. When an object is locked by one thread and another thread tries to call a synchronized method on the same object, the second thread will block until the object is unlocked.
Famous Quotations
Before you go and criticize the younger generation, just remember who raised them.
-- Unknown Author

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2022 by Nataraja Gootooru. All Rights Reserved.