Java interview questions
What happens if there are multiple main methods inside one class in Java? What happens if the static modifier is not included in the main method signature in Java?
JAVA INTERVIEW QUESTIONS HOW TO
How to not allow serialization of attributes of a class in Java? Which among String or String Buffer should be preferred when there are lot of updates required to be done in the data? Java works as “pass by value” or “pass by reference” phenomenon? What are the differences between constructor and method of a class in Java? What are the different ways of threads usage? What is the importance of reflection in Java?
![java interview questions java interview questions](https://cdn.slidesharecdn.com/ss_thumbnails/40bestcorejavainterviewquestionsandanswers-141202053333-conversion-gate02-thumbnail-4.jpg)
What are the differences between HashMap and HashTable in Java? What are the differences between JVM, JRE and JDK in Java? Why is the character array preferred over string for storing confidential information? What makes a HashSet different from a TreeSet? In Java, static as well as private method overriding is possible. Using relevant properties highlight the differences between interfaces and abstract classes. How would you differentiate between a String, StringBuffer, and a StringBuilder? Apart from the security aspect, what are the reasons behind making strings immutable in Java? What part of memory - Stack or Heap - is cleaned in garbage collection process? What is the main objective of garbage collection? Do final, finally and finalize keywords have the same function? Explain the use of final keyword in variable, method and class. A single try block and multiple catch blocks can co-exist in a Java Program. Comment on method overloading and overriding by citing relevant examples. Briefly explain the concept of constructor overloading How is an infinite loop declared in Java? Can you tell the difference between equals() method and equality operator (=) in Java? What do you understand by an instance variable and a local variable? Why is Java not a pure object oriented language? Why is Java a platform independent language? For the Wrapper classes, value equality means that the primitive values are equal. For two String objects, value equality means that they contain the same character sequence. String, BitSet, Date, and File override the equals() method. The default implementation returns true only if the object is compared with itself, which is equivalent to the equality operator = being used to compare aliases to the object.
![java interview questions java interview questions](https://image.slidesharecdn.com/javainterviewquestions-150324133250-conversion-gate01/95/java-interview-questions-2-638.jpg)
The method public boolean equals(Object obj) is provided by the Object class and can be overridden. It is possible for two String objects to have the same value, but located in different areas of memory. The = operator compares two objects to determine if they are the same object in memory i.e. How is it possible for two String objects with identical values not to be equal under the = operator? What would you use to compare two String variables – the operator = or the method equals()? The argument String indicates the argument type which is given at the command line and arg is an array for string given during command line. Void main does not return anything so the return type must be void Java environment should be able to call this method without creating an instance of the class, so this method must be declared as static. Hence the access specifier has to be public. Main(.) is the first method called by java environment when a program is executed so it has to accessible from java environment. These byte codes can be run in any platform and hence java is said to be platform independent.Įxpain the reason for each keyword of public static void main(String args)? What gives java it’s “write once and run anywhere” nature?Īll Java programs are compiled into class files that contain bytecodes. If you’re overriding the method equals() of an object, which other method you might also consider? Pass by value means passing a copy of the value. Pass by reference means, passing the address itself rather than passing the value. What is meant by pass by reference and pass by value in Java? The program compiles properly but at runtime it will give “Main method not public.” message. What if the main method is declared as private? I wish you good luck and hope you find a great job. This is to help you prepare well for java related technical interviews. These questions are organized according to various java topics. Questions from different people and communities are consolidated in place for your convenience. These are some of the java job interview questions that were asked in various java interviews. Java Interview Questions site attempts to discuss core java IT technical interview questions in detail.