Home / Computer Science / Java Language / Top 20 Interview Questions in Java

Top 20 Interview Questions in Java

Expert answers to top Java interview questions for your coding journey.Here are top interview questions in Java for both freshers and experienced.

Interview questions in java

Interview Questions in Java

1) String is mutable or immutable in java?

Ans: In java all string are immutable. ( a mutable string can be changed but immutable string cannot be changed).

2) StringBuffer is thread safe or not?

Ans: A StringBuffer is thread safe because it is synchronized. StringBuffer object is mutable.

3)What is StringTokenizer?

Ans: StringTokenizer is a class in java.util package this allows the string into tokens (pieces).

4)What is StringBuffer?

Ans: The StringBuffer is a class provided by java which is used to represent characters that can be modified.

5)What is StringBuilder?

Ans: StringBuilder is class in java introduced in java5. It allows you to expand the number of characters that it encapsulates it you can specify a value for the maximum number of characters that it can hold. if you need to concatenate a large number of strings, appending to a StringBuilder object is more efficient.

6) What is String in java?

Ans: String is a class in Java and available in java.lang package.String is immutable and final in Java and JVM uses String Constant Pool to store all the String objects.

7) What is the operator is used to compare two strings?

Ans: equals() or equalsIgnoreCase() method should be used to compare two string objects in Java.

8) How to create String objects in java?

Ans: Creating string objects in java is of two types.

1.String s1 = new String(“java”);

2. String s1=”java”;

9). What does intern() method do in Java?

Ans: String object created by new() operator is by default not added in String pool as opposed to String literal the intern() method allows putting string object into pool.

10) What is the difference when String is gets created using literal or new() operator ?

Ans: When we create string with new() its created in heap and not added into string pool while String created using literal are created in String pool itself which exists in Perm area of heap.

11) Can we write multiple main() methods in java program?

Ans: Yes, we can write by override the main() method but there should be only one main() method with the standard signature like public static void main(String args[ ]).

 

12) What is transient in Java?

Ans: A transient is a key word which is used to a variable that may not be serialize.

13)Explain about main() method in java?

Ans: Public: This is the first method called by java environment when the program starts its execution. So the access specifier is public.

Static: Java environment should call this method without creating any instance, hence static is used.

Void: main() method does not return any thing so return type should be void.

14) Can we make abstract class as final?

Ans: Abstract class may not be declared as final.

15)Which package is import always by default in java program?

Ans: By default java.lang package is always imported.

16) What are the four main pillars of Object Oriented Programming?

Ans: Inheritance, Abstraction,Encapsulation and Polymorphism.

17) What is JVM?

Ans: In expansion of JVM is Java Virtual Machine. JVM is an abstract computing machine that enables a computer to run a Java program. There are three notions of the JVM specification, implementation and instance. The specification is a document that formally describes what is required of a JVM implementation.

18) What is a Singleton property in Java?

Ans: Singleton is good property, java has this property. Singleton is to control the object creation by creating constructor in private. This singleton is useful to keep only one instance per class at any time.

19) What is WORA?

Ans: Write Once Run Anywhere (WORA) This is a slogan for java. Means java can be developed on any device and compiled into a standard byte code and expected to run any where or any device / platform equipped with JVM.

20) List Java features?

Ans: Object Oriented, Robust,Secure,Simple,Platform Independent, Architectural neutral, Portable and Dynamic.

Practise Java Online while learning with W3Schools.

About Santosh Kumar Gadagamma

I'm Santosh Gadagamma, an Experienced Software Engineer passionate about sharing knowledge in technologies like Java, C/C++, DBMS/RDBMS, Bootstrap, Big Data, Javascript, Android, Spring, Hibernate, Struts, and all levels of software design, development, deployment, and maintenance. I believe computers are essential for the world's functioning, and I'm committed to helping others learn the skills they need to succeed in tech. My website is a valuable learning tool to help you reach greater heights in your education and career, and I believe that education has no end points.

Check Also

String Builder

String Builder : A Comprehensive Guide

String builder in Java is a class. It is like string objects, except that they …