Please note, this is a STATIC archive of website www.simplilearn.com from 27 Mar 2023, cach3.com does not collect or store any user information, there is no "phishing" involved.

Java is one of the most popular programming languages among developers. Its uncomplicated syntax and compatibility with all the major operating systems make it an ideal choice. Today, there are more than 10 million developers who work with the Java language.

Here's How to Land a Top Software Developer Job

Full Stack Development-MEANExplore Program
Here's How to Land a Top Software Developer Job

With competition, this intense, organizations hiring Java developers are quite resolute in their hiring priorities. Only professionals with proven technical competencies in Java and who can design, code, build and deploy any kind of applications are hired.

But no matter how great your coding skills, acing the interview is essential to land the Java role of your dreams.

Get All Your Questions Answered Here!

Caltech PGP Full Stack DevelopmentExplore Program
Get All Your Questions Answered Here!

We’ve compiled 10 of the top questions and model answers often asked at Java Developer interviews – read on to find out where you stand!

#1 Can you differentiate between J2SDK 1.5 and J2SDK 5.0?

Your answer: There is really no difference between J2SDK 1.5 and J2SDK 5.0. The versions have been rebranded by Sun Microsystems.

#2 What is the number of bits used to represent ASCII, Unicode, the UTF-16, and the UTF-8 characters?

Your answer: Unicode requires 16 bits.

ASCII requires 7 bits – however, it is usually represented as 8 bits.

UTF-8 presents characters in 8, 16, and 18 digit patterns.

UTF-16 requires 16 bit or larger patterns.

#3 Is it possible to import the same package or class twice? Will the JVM load the package twice at runtime?

Your answer: It is possible to import the same package or class more than once. It will not have any effect on the compiler or JVM. The JVM will load the class more than once, irrespective of the number of times you import the same class.

#4 IS JVM an overhead?

Your answer: No and Yes. JVM is an extra layer that translates Byte code into Machine code. Java provides an additional layer of translating the Source code when compared to languages like C.

C++ Compiler – Source Code -> Machine Code

Java Compiler – Source Code -> Machine Code

JVM – Byte Code -> Machine Code

Want a Top Software Development Job? Start Here!

Full Stack Development-MEANExplore Program
Want a Top Software Development Job? Start Here!

Though it looks like an overhead, this additional translational allows Java to run Apps on all platforms since JVM provides the translation to Machine code as per the underlying Operating System.

#5 There are two objects – a and b – with the same hashcode. I will insert two objects inside the hashmap.

hMap.put(a,a);

hMap.put(b,b);

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

How many objects will be inside the hashmap?

Your answer: There can be 2 elements with the same hashcode. When two elements have the same hashcode, Java uses the equals to further differentiation. So there can be one or two objects depending on the content of the objects.

Get the Must-Have Skills of a Web Developer

Caltech Coding BootcampExplore Program
Get the Must-Have Skills of a Web Developer

#6 Could you provide some implementation of a Dictionary having a large number of words?

Your answer: The simplest implementation that can be given is that of a List wherein one can place ordered words and perform a Binary search. The other implementation with a better search performance is HashMap where the key is used as the first character of the word and the value as a LinkedList.

Up another level, there are HashMaps like:

hashmap {

a ( key ) -> hashmap (key-aa , value (hashmap(key-aaa,value)

b ( key ) -> hashmap (key-ba , value (hashmap(key-baa,value)

z( key ) -> hashmap (key-za , value (hashmap(key-zaa,value)

}

Up to n levels where n is the average size of the word in the dictionary.

#7 What do you think the output of this code will be?

enum Day {

 MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY,SUNDAY

}

public class BuggyBread1{

    public static void main (String args[]) {

     Set<Day> mySet = new TreeSet<Day>();

     mySet.add(Day.SATURDAY);

     mySet.add(Day.WEDNESDAY);

     mySet.add(Day.FRIDAY);

     mySet.add(Day.WEDNESDAY);

     for(Day d: mySet){

      System.out.println(d);

     }

    }

}

Your answer: WEDNESDAY

FRIDAY

SATURDAY

Only one FRIDAY will be printed since the Set doesn’t allow duplicated.

Elements will be printed in the order that the constants are declared in the Enum. TreeSet maintains the elements in the ascending order which is identified by the defined compareTo method. The compareTo method in the Enum has been defined such that the constant declared later are greater than the constants declared prior.

#8 What is the difference between System.out, System.err, and System.in?

Your answer: System.out and System.err represent the monitor by default and thus can be used to send data or results to the monitor. System.out is used to display normal messages and results. System.eerr is used to display error messages. System.in represents InputStream object which by default represents standard input device, i.e., keyboard.

#9 How does the substring() method of String class create memory leaks?

Your answer: The substring method can build a new String object with reference to the while char array, to avoid copying it. Thus, you can inadvertently keep a reference to a very big character array with just one character string.

Boost Your Coding Skills. Nail Your Next Interview

Full Stack Development-MEANExplore Program
Boost Your Coding Skills. Nail Your Next Interview

#10 Why is Char array preferred over String to store a password?

Your answer: String is immutable in Java and stored in the String pool. Once it is created it stays in the pool until the garbage is created making the password available in the memory. It is a security risk because anyone who has access to the memory dump can find the password as clear text.

So there you go. These 10 questions should prepare you well for your interview.


[Preparing for Java Certification? Here’re 50 Java Certification Practice Test Questions. Take this free practice test to know where you stand!]

Good Luck!

1. Can you differentiate between J2SDK 1.5 and J2SDK 5.0?

There is really no difference between J2SDK 1.5 and J2SDK 5.0. The versions have been rebranded by Sun Microsystems.

2. What is the number of bits used to represent ASCII, Unicode, the UTF-16, and the UTF-8 characters?

Unicode requires 16 bits. 1. ASCII requires 7 bits – however, it is usually represented as 8 bits. 2. UTF-8 presents characters in 8, 16, and 18 digit patterns. 3. UTF-16 requires 16 bit or larger patterns.

3. Is JVM an overhead?

No and Yes. JVM is an extra layer that translates Byte code into Machine code. Java provides an additional layer of translating the Source code when compared to languages like C. C++ Compiler – Source Code -> Machine Code, Java Compiler – Source Code -> Machine Code, JVM – Byte Code -> Machine Code

4. How many objects will be inside the hashmap?

There can be 2 elements with the same hashcode. When two elements have the same hashcode, Java uses the equals to further differentiation. So there can be one or two objects depending on the content of the objects.

5. What is the difference between System.out, System.err, and System.in?

System.out and System.err represent the monitor by default and thus can be used to send data or results to the monitor. System.out is used to display normal messages and results. System.eerr is used to display error messages. System.in represents InputStream object which by default represents standard input device, i.e., keyboard.

6. How does the substring() method of String class create memory leaks?

The substring method can build a new String object with reference to the while char array, to avoid copying it. Thus, you can inadvertently keep a reference to a very big character array with just one character string.

7. Why is Char array preferred over String to store a password?

String is immutable in Java and stored in the String pool. Once it is created it stays in the pool until the garbage is created making the password available in the memory. It is a security risk because anyone who has access to the memory dump can find the password as clear text.

8. Is it possible to import the same package or class twice? Will the JVM load the package twice at runtime?

It is possible to import the same package or class more than once. It will not have any effect on the compiler or JVM. The JVM will load the class more than once, irrespective of the number of times you import the same class.

9. Could you provide some implementation of a Dictionary having a large number of words?

The simplest implementation that can be given is that of a List wherein one can place ordered words and perform a Binary search. The other implementation with a better search performance is HashMap where the key is used as the first character of the word and the value as a LinkedList. Up another level, there are HashMaps like: hashmap {a ( key ) -> hashmap (key-aa , value (hashmap(key-aaa,value)b ( key ) -> hashmap (key-ba , value (hashmap(key-baa,value)z( key ) -> hashmap (key-za , value (hashmap(key-zaa,value)} Up to n levels where n is the average size of the word in the dictionary.

About the Author

KetkeeKetkee

Ketkee is a Java evangelist and an influencer with more than a decade of experience in Java/J2EE technologies. She has led successful projects for Fortune 500 companies in the past and also comes with a rich background of web technology.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.