Java development has always been a unique opportunity for everyone planning to get into the IT industry and deliver something innovative to the world. With its capability to support all the major operating systems, Java has been extensively used by the developers and organizations across the world. Today, more than 4.5 million developers work on the Java programming language.
With so many Java developers available in the market, organizations hiring a Java programmer are quite resolute in their hiring priorities. Organizations are now demanding more innovative professionals who have proven technical competencies in Java and who can design, code, build and deploy any kind of applications. When hiring a Java developer, organizations consider a lot of things like years of experiences, developer’s skill set, consistent performance, good communication skills and more.
An organization hiring a Java programmer is looking for someone who can code the applications flawlessly. To find out what exactly the employers ask in Java interview, we’ve interacted with a few of the newbie as well as professional Java experts. And one of them has shared what kind of interview questions he faced during his interview. Let’s take a look what he was questioned and how he answered all the interview questions.
For all the Java developers sitting out there, here presenting 35 common Java Interview questions. Make sure you tap the benefits of this comprehensive list of questions shared by our Java counterpart to crack your next interview. All the best readers!
GRAILS Accelerating J2EE Application Development Whitepaper:
Q1: What do you know about Java?
A: Java is nothing but a high-level programming language from the Sun Microsystem. It is released in the year 1995 and runs on multiple platforms like Windows, Mac and other variations of UNIX.
Q2: Can you differentiate between J2SDK 1.5 and J2SDK 5.0?
There is no difference between J2SDK 1.5 and J2SDK 5.0. Sun Microsystems has just rebranded the versions.
Q3: Can you name a few platforms that support Java?
A: Yes, Java is supported by Windows, Mac as well as UNIX/Linux like Ubuntu, Red Hat and Sun Solaris.
Q4: Could you tell me why Java is called Architectural Neutral?
A: The main reason is because the compiler creates an architecture-natural object file format. This makes the compiled code to be executable on different other processors.
Q5: Could you differentiate an Interface and an Abstract class?
A: An abstract class may have instance methods, which can implement a default behavior. On the other hand, an interface can’t implement any default behavior. However, it can declare different constants and instance methods. While an interface has all the public members, an abstract class contains only class members like private, protected and so on.
Q6: What are the different ways you can use “Static”?
A: Static can be used in four ways: static variables, static methods, static classes and it can be used across a block of code in any class in order to indicate code that runs when a virtual machine starts and before the instances are created.
Q7: Do you think all property of Immutable Object needs to be final?
A: Not compulsory as we can easily achieve the same by making member as non-final but private and not changing them except in the constructor. Also, avoid providing setter methods for them. If it is a mutable object, then prevent leaking any reference for that member.
Q8: Can you brief me about Singleton Class?
A: It basically controls object creation, restricting the number to one while allowing the flexibility to create objects if the scenario changes.
Q9: In Java, what is the default value of Float and Double?
A: Default value of Float is 0.0f while 0.0d for Double.
Q10: Can you explain Type Erasure?
A: It is nothing but a JVM phenomenon, which means that the runtime has no idea about the types of generic objects like List<Integer>.
Q11: Explain Dot Operator.
A: It is used to access the instance variables and methods of class objects. Also, we can use it to access classes and sub-packages from a package.
Q12: What do you mean by Serialization in Java?
A: Well, serialization is nothing but a process of transforming objects into a stream of bytes.
Q13: Can you tell me the reason why String class is considered immutable?
A: It is because to avoid change in String object once it is created. As String is immutable, you can share it between different threads in a safe way. This is quite crucial in multithreaded programming.
Q14: Can you quickly brief about Map, HashMap, HashTable, and TreeMap?
A: Map is an interface
HashMap is a class that implements a Map. It is unsynchronized and supports null values and keys
Hashtable is a synchronized version of HashMap
TreeMap is similar to HashMap but uses Tree to implement Map
Q15: Do you think not overriding hashcode() method has any performance implication?
A: A weak hashcode function will result into frequent collision in HashMap, which will at the end increase the time to add an object within Hash Map.
Q16: Can you explain when and why Getters and Setters important?
A: We can put setters and getters within interfaces, which can hide implementation details. This allows us to make member variables public in Java.
Q17: Is it possible to import same package or class twice? Will the JVM load the package twice at runtime?
A: It is possible to import the same package or class more than one time. Also, it won’t have any effect on compiler or JVM. JVM will load the class for one time only, irrespective of the number of times you import the same class.
Q18: What is difference between Throw and Throws?
A: While Throw is used to trigger an exception, Throws is used in the declaration of exception. It is not possible to handle checked exception without Throws.
Q19: What is the significance of the order in which catch statements for FileNotFoundException and IOException are written?
A: It is crucial to consider the order as the FileNoFoundException is inherited from the IOException. Therefore, it is important that exception's subclasses caught first.
Q20: Can throw some light on Yielding and Sleeping?
A: When any task invokes its yield() method, it will return to the ready state. Whenever a task invokes sleep() method, it will return to the wait state.
Q21: Why you should use Vector class?
A: It provides the capability to implement a growable array of objects. It is quite useful when we don’t know the exact size of the array.
Q22: Can you tell me the number of bits used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
A: For Unicode 16 bits and ASCII needs 7 bits. However, ASCII is usually represented as 8 bits. UTF-8 presents characters through 8, 16 and 18 bit pattern. UTF-16 will require 16-bit and larger bit patterns.
Q23: What is Applets?
A: A small programs based on Java that can be transformed from one computer to another using the Applet Viewer or web browser.
Q24: What is the use of Locale?
A: Locale is an object containing geographical, cultural and political information which helps in using custom codes and conventions of specific country or region for writing applications in that language.
Q25: What is the use of Java Package?
A: Java Package is useful for organizing projects containing multiple modules and protecting them from unauthorized access.
Q26: While working in the JVM, do we need to import java.lang package?
A: No, by default it is loaded in the JVM
Q27: Can Applets communicate with each other?
A: Yes, they can communicate via shared static variables even if they belong to same of different classes.
Q28: Can a .java file support more than one java classes?
A: Yes, it can support more than one Java classes in a condition where one of them is a public class.
Q29: MAIN, NEXT, DELETE & EXIT, which of these is a keyword in Java?
A: None of these is a keyword in Java
Q30: How to handle errors while writing or accessing Stored Procedures?
A: Store Procedure itself returns the error codes if any but, incase if it fails to do so, we can resort to catching SQL Exception.
Q31: From ArrayList and LinkedList, which one helps to perform an indexed search in a list of objects?
Q32: What is the use of File Class?
A: It helps in accessing files and directories of a local system.
Q33: Does Java support Default arguments?
A: No, it does not support
Q34: Describe lifecycle of Applets?
A: Initialization, Starting, Stopping, Destroying & Painting
Q35: What is the method applied to load an image in Applet class?
A: It’s getImage
Although the list is long, it contains both simple and complex development specific questions. If you are a fresher, make sure your basic concepts are strong. If you are experienced, do not worry about the questions you cannot answer. Make sure whatever you answer, it comes out with confidence.
Besides these, one can also take guidance from books specially written for clearing Java interviews which cover several concepts, database, networking, algorithms and structure related questions and answers.
With this, we sign off and wish all the Java techies good luck for your future endeavor in Java.
GRAILS: Accelerating J2EE Application DevelopmentLearn More
An email with the relevant details is on its way to your inbox.
Our motto ‘IT is About You’ is more than just a tag line – it is the very heart of Cygnet. We always ensure the continued success of our clients and employees by placing problem solving ahead of anything else and walking the extra mile when needed.
An email with the relevant details is on its way to your inbox.