Java Interview Questions

Question 1:

How can you manipulate String in Java without creating String garbage?

StringBuffer and StringBuilder provides the feature to manipulate the existing object as these class are mutable classes in java.

Question 2:

Can we use String in switch case?

Yes, in Java 7 String can be used in switch case.

Question 3:

What does equals() does in String class?

equals() method compares the content/data of two String object whereas “==” checks whether reference of two objects are same or not.

Question 4:

How can we convert String to Integer?

String value can be converted to Integer using parseInt() method:-
                     Integer demo = Integer.parseInt(“10”);
Note :- If String provided as parameter is not an numeric value, it throws NumberFormat Exception.

Question 5:

What is difference between length and length() in Java?

length() is a method for a String class whereas length is a property used to check number of element only for array.

Question 6:

Can we create daemon thread?

Yes, we can create daemon thread using setDaemon(true) method.

Question 7:

How to check whether any thread is dameon or not?

You can check any theread is daemon or not using isDaemon() method.

Question 8:

Explain Daemon thread.

Daemon thread in java is a service provider thread that provides services to user thread. It’s life depends upon user threads. When all user threads terminate, JVM terminates this thread automatically.

Question 9:

What are the OOPs features provided by Java?

The OOPs features provided by Java are:-

  • Encapsulation
  • Polymorphism
  • Inheritance
  • Abstraction
Question 10:

Define abstraction in Java.

Abstraction is the concept of hiding the implementation details and exposing only the required essential characteristics and behavior.
Abstraction in java is achieved using interface and abstract classes.

Share interview questions


comments powered by Disqus


Social Media