Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

200 Common Java Interview Questions, with Reference Answers

Explore 200 Common Java Interview Questions, with Reference Answers with concise explanations, useful comparisons, and practical context to help you...

Table of Contents

200 Common Java Interview Questions, with Reference Answers is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.

If you are going to a Java interview, preparing for Java programming language questions is necessary. These Java interview questions are compiled from Tutorialspoint and are accompanied by reference answers. Good employers often don't come up with questions to ask, they often start with basic concepts about the topic and then rely on your answers to come up with the next discussion. The answer is quite concise and compact, so if you want to impress an employer, you must have a strong knowledge base for Java to implement further when asked to explain it thoroughly. Don't worry, the most important factor in your interview is still confidence, believe in your ability, combined with this questionnaire, make sure you get a successful interview..

1. What do you know about Java?

Java is a high-level programming language, first developed by Sun Microsystems and published in 1995. Java runs on diverse platforms, such as Windows, Mac OS, and diverse UNIX versions.

More reference: What is Java? Why choose Java?

2. Which platforms are supported by the Java programming language?

Java is a cross-platform programming language that can run on Windows, Mac OS, and various UNIX versions such as HP-Unix, Sun Solaris, Redhat Linux, Ubuntu, CentOS,.

3. List 5 any features of Java?

Some characteristics of Java are Object Oriented, Platform Independent, Interpreter, Multi-thread, robust.

4. Why is Java independent of structure?

Its compiler creates a structure-independent file format, making the compiled code executable on any processor, in the presence of the Java runtime system.

5. How high performance (High Performance) is enabled in Java?

Java uses the Just-In-Time compiler to enable high performance. This compiler turns Java Bytecode (a program containing instructions that need to be interpreted) into directives that can be sent directly to the processor.

6. Why is Java considered dynamic (Dynamic)?

It is designed to adapt to a growing environment. Java programs can carry a large amount of information at runtime that can help test and process access to objects at runtime.

7. What is Java Virtual Machine and what role does it play in Java's platform independence?

When Java is compiled, it is not compiled into a specific machine platform, but is translated into platform-independent Bytecode. This bytecode is distributed through the Web and interpreted by the Java Virtual Machine (JVM) on any platform it is running.

8. List two JDE of Java?

Netbeans, Eclipse,. (let's say more JDE or talk a little more detail about these 2 JDE to score with employers).

9. List some keywords in Java (unlike keywords in C, C ++)?

Some keywords in Java are import, super, finally,.

10. What do you understand about the subject?

The object is an entity at runtime, its state is stored in the fields and the behavior is expressed through methods. Methods operate on the intrinsic state of the object and act as the main mechanism for communicating between objects.

11. Class definition (class)?

A class is a design (blueprint) from which individual objects are created. A class can contain fields and methods to describe the behavior of an object.

12. What types of variables can a class contain?

A class can include local variables, instance variables, and class variables.

13. What is the local variable or local variable?

Variables defined inside methods, constructors or blocks are called local variables. This variable will be declared and initialized inside the method and it will be destroyed when the method ends.

14. What is an instance variable?

Instance variables are variables inside a class but outside any method. These variables are initialized when the class is loaded.

15. What is class variable?

These are variables declared with a class, outside any method, with the static keyword.

16. What is the Singleton class?

The Singleton class in Java controls object creation, limiting the number of objects to one, but it is also flexible to allow you to create more objects if the situation changes.

17. What do you understand about Contructor?

Contructor is called when a new object is created. Each class has a Constructor. If we don't explicitly write constructors for the class, then the Java compiler will build a default constructor for that class.

18. List three steps to create an object for a class?

First, an object is declared, then initialized and finally launched.

19. Default value of byte data type in Java?

The default value of the byte data type is 0.

20. Default value of data type float and double in Java?

The default value of data types float and double in Python is different from in C / C ++. The default of float is 0.0f and the double is 0.0d.

21. When is the byte data type used?

This data type helps store space in wide arrays, primarily to replace integers, because a byte is 4 times smaller than an int.

22. What is static variable (static variable)?

Class variables are also known as static variables (static variables) that are declared with the static keyword in a class, but outside a method, constructor, or block.

23. What do you understand about Access Modifier?

Java provides several Access Modifiers to set the access level for classes, variables, methods and constructors. A member has default access when no Access Modifier is specified.

24. What is Protected Access Modifier?

Variables, methods and constructors, which are declared protected in a superclass, are only accessible by parent classes in another package or any class within that class of the protected class.

25. What is Synchronized Non Access Modifier?

Java provides Synchronized Non Access Modifier to bring features other than Access Modifier, from Synchronized indicating that a method is only accessed by one thread at a time.

26. Under the precedence of operators in Java, which operator has the highest priority?

Postfix operators like (), [],. is the highest priority.

27. What types of variables can be used in the switch command?

The variables used in a switch command can only be one byte, string, enum, short, int or char.

28. When can the parseInt () method be used?

This method helps retrieve the original data type of a given string.

29. Why is String class considered immutable?

String class is invariant or immutable, and when it has been created, a String object cannot be altered. Because String is immutable, it can be safely shared between multiple threads. This is a very important part for multi-threaded programming.

30. Why is StringBuffer called variable?

StringBuffer objects can be modified. If there is a situation where you need to make multiple modifications to strings, use StringBuffer.

31. What is the difference between the StringBuffer and StringBuilder classes?

Use StringBuilder whenever possible because it's faster than StringBuffer. But, if thread safety is needed, you should use StringBuffer objects.

32. Which packages are used for pattern matching (Pattern Matching) with Regular Expression in Java?

For this purpose, you use package java.util.regex.

33. Which java.util.regex classes?

java.util.regex consists of three classes: Pattern class, Matcher class and PatternSyntaxException class.

34. What does finalize () do?

You can define a method that will be called immediately before destroying the object by the Garbage Collector. This method is called finalize (), and it can help ensure that an object is completely finished.

35. What is Exception?

An Exception is an issue created during the execution of a program. The Exception captured by Handler is determined along with the Thread method call.

36. What do you know about Checked Exception?

The feature of this Exception is a user error or an unforeseen problem by the developer. For instance,, if a file has been opened, but the file cannot be found, an Exception will appear. These exceptions cannot be simply ignored at compile time.

37. Explain Runtime Exception?

It is an Exception that can be avoided by programmers. In contrast to Checked Exception, Runtime Exceptions are ignored at compile time.

38. What are the two classes of Exception Class?

The Exception class has two main subclasses: IOException class and RuntimeException class.

39. When will the keyword throws be used?

If a method doesn't handle a Checked Exception, the method must be declared with the keyword throws. Keywords throws appear at the end of a method.

40. When does the keyword throw be used?

An Exception can be thrown, either by initialization or an Exception you just captured, by using the keyword throw.

41. How is finally used under Exception Handling?

The finally keyword helps create a block of code that follows a try block. A finally block always executes, whether or not an Exception appears.

42. What should you keep in mind when creating your own Exception in Java?

While creating my own Exception:

  • All Exception must be a Throwable child.

  • If you want to write a Checked Exception that is automatically followed by Handler or Declare Rule, you need to inherit the Exception class.

  • If you want to write a Runtime Exception, you need to inherit the RuntimeException class.

43. What is Inheritance?

It is a process in which an object obtains attributes of another object. Using inheritance, you can more easily manage information created in a hierarchical structure.

44. When to use super keywords?

If the method overrides one of the methods of the superclass, the overridden method can be recalled using the super keyword. It can also be used to reference a hidden field.

45. Definition of polymorphism?

Polymorphism is the ability to help an object with many forms. In OOP, the most common use of polymorphism is when a parent class reference helps refer to a subclass object.

46. What is abstraction?

It involves the ability to create an abstract class (abstract class) in OOP. It helps minimize complexity and also improves system retention.

47. What is Abstract class?

These classes cannot be initialized and deployed either partially or not. This class contains one or more abstract methods, where the method declaration is simplified with no body.

48. When is the abstract method used?

If you want a class to contain a specific method but you want the actual implementation of that method to be decided by subclasses, you can declare the method in the superclass in abstract form.

49. What is Encapsulation?

It is a technique for creating fields in a private class and providing access to fields via public methods. If a field is declared private, it cannot be accessed by any method outside that class, from which to hide the fields inside the class. Therefore, closure is also referred to as Data hiding.

50. Main benefits of closure?

The main advantage of closure is the ability to modify your deployed code without destroying someone's code. It is like a code protection code and avoids your code and data from being accessed randomly from outside code. Close-up provides code retention, flexibility, and scalability.

51. What is an interface?

An interface is a collection of abstract methods. One class implements an Interface, which inherits the abstract methods of that Interface.

52. Some characteristics of Interface?

Include:

  • Interface cannot be initialized.

  • An interface does not contain any constructors.

  • All methods in an Interface are Abtract.

53. In Java, what is Package?

A Package can be defined as a group of related types (classes, interfaces, enumerations), providing access protection and namespace manager.

54. Why is Package used?

Package is used in Java to prevent naming conflicts, to control access, to find and locate, and to use classes, Interface, enumeration. more easily.

55. What do you understand about Multi-Thread?

A multithreaded program consists of two or more parts that can run simultaneously. Each part of that program is called a Thread, and a Thread defines a different executable.

56. How can a thread be created in two ways?

Thread can be created by: Runable Interface deployment, inheriting Thread class.

57. What is an Applet?

An Applet is a Java program that runs in a Web browser. An Applet can be a full-featured Java application because it has the entire Java API in its layout.

58. What class does an Applet inherit?

An Applet inherits the java.applet.Applet class.

59. Explain Garbage Collector in Java?

Java uses a garbage cleaner to free up memory. By deleting objects that are no longer used by any program.

60. Definition of objects cannot be changed?

An immutable object cannot be changed since it was created.

61. Explain the use of this () with Constructors?

It is used with variables or methods and helps call the Constructor of the same class.

62. What do you know about Set Interface?

It is an element set that cannot contain duplicate elements. Set Interface only includes methods that are inherited from Collection and add limits to prohibit the duplicate element from appearing.

63. Presenting TreeSet?

It is a Set deployed when we want elements in a sorted order.

64. What is Comparable Interface?

It helps sort collections and object arrays using collection.sort () and java.utils methods. Objects of class Comparable Interface implementation can be sorted.

65. What is the difference between throws and throw?

Include:

  • Throw helps trigger an Exception while throws are used in Exception's declaration.

  • Without throw, Checked Exception cannot be processed, while throws help denote Exception not handled by the function.

66. Explain the following code in Java language?

 public static void main (String args[ ]) 

Below is a detailed analysis:

  • public - it is Access Specifier.

  • static - it allows main () to be called without initializing a specific instance of a class.

  • void - it tells the compiler that no value is returned by main ().

  • main () - this method is called at the beginning of the Java program.

  • String args [] - args parameter is an instance array of String class.

67. What is JRE (Java Runtime Environment)?

The JRE is a deployment of Java Virtual Machine that executes Java programs. It provides the minimum conditions for executing a Java application.

68. What is JAR file?

JAR stands for Java Archive and it combines multiple files into one. It holds Java classes in a library. JAR file is built in ZIP file format and has a.jar extension.

69. WAR file is what?

This is the Web Archive File and helps store XML, Java classes, and JavaServer pages, which help distribute a set of JavaServer Page, Java Servlet, Java classes, XML files, static Webpage, and so on.

70. JIT Compiler definition?

It improves the runtime performance of Bytecode-based computer programs.

71. What is the difference between object-oriented programming language and object-based programming language?

Object-based programming languages have all the characteristics of OOP except Inheritance. JavaScript is an example of Object-based Programming Language.

72. The purpose of the default Constructor?

Java Compiler creates a default Constructor only if there is no constructor in the class.

73. Can a Constructor be created as a final?

No, this is impossible.

74. What is a static block?

It helps initialize static data members. It is executed before the main method at the time of loading that class.

75. Definition of Composition?

Keeping references of other layers within several other layers is known as Composition.

76. What is Method Overloading?

If a class has multiple functions with the same name but has different parameters, it is treated as Method Overloading or Function Overloading.

77. What is method override (Method Overriding)?

If a subclass provides a specific implementation of a method that is provided by its parent class, then it is Override the method.

78. What is the difference between overwriting and overwriting (Overloading vs Overriding)?

Overload method to increase readability of the program. Overriding the method provides a specific implementation of the method that is provided by its parent class. The parameter must be different from the overloaded type, and in the override, the parameters are the same type.

79. What is the final class?

Final classes are created so that methods implemented by that class cannot be overwritten. It cannot be inherited.

80. What is NullPointerException?

A NullPointerException is thrown when calling the instance method of a Null object, accessing or modifying the fields of a Null object,.

81. How can a Thread enter a waiting state?

A Thread can enter the Waiting state by summoning its sleep () method, either by locking on IO, or failing to attempt to acquire the object's lock, or by summoning. the wait () method of the object. It can also enter a wait state by summoning its suspend () method (this method is old).

82. How does Multi-Thread happen on a computer with a single CPU?

Scheduler of the operating system allocates execution time for Tasks. By quickly switching between executing tasks, it gives us the impression that these Tasks are executed simultaneously.

83. What is the run () method of a Thread?

After a Thread is created, through its start () method in the Thread class, the JVM summons the Thread's run () method when this Thread starts executing.

84. Is there a problem with the order of the catch commands written for FileNotFoundException and IOException?

Have. FileNotFoundException is inherited from IOException. The subclasses of Exception must be captured first.

85. What is the difference between yield and sleep?

When a task summons its yield () method, it becomes ready. When a task summons its sleep () method, it switches to the wait state.

86. Why is Vector class used?

The Vector class provides the ability to deploy an expandable array of objects. Vector is useful if you don't know the size of the array in advance, or if you only need an array that can be resized during a program's lifetime.

87. How many bits help represent Unicode, ASCII, UTF-16 and UTF-8 characters?

Unicode requires 16 bits and ASCII requires 7 bits. Although ASCII character set only uses 7 bits, it is typically represented by 8 bits. UTF-8 represents characters using 8 bits and is 16 bits for UTF-16.

88. What are Wrapper classes?

These are the classes that allow the original data types to be accessed as objects. For instance,: Integer, Character, Double, Boolean,.

89. What is the difference between a Window and a Frame?

The Frame class inherits Window to define a main application window that may have a bar menu.

90. Which packages have lightweight components?

That is javax.Swing. All components in Swing, except JApplet, JDialog, JFrame and JWindow, are lightweight components.

91. What is the difference between the paint () and repaint () methods?

The paint () method supports drawing through a Graphics object. The repaint () method used to make the paint () method can be summoned by AWT Thread.

92. What is the purpose of the File Class?

It helps create objects that provide access to local file system files and directories.

93. Differences between Reader / Writer class structure and class structure InputStream / OutputStream.

The Reader / Writer class structure is character-oriented, and the class structure of InputStream / OutputStream is byte-oriented (Byte-oriented).

94. What class do you use to get design information about an object?

Class Class helps obtain information about the design of an object and the representation of the java.lang.Class class represents classes, Interface in a running Java application.

95. What are the different static and non-static variables?

Static variables (static variables) are bound to the entire class rather than an instance of a class. Non-static variables get unique values with an object representation.

96. What is Serialization and Deserialization?

Serialization is the process of writing the state of an object to a Byte Stream. Deserialization is the process of recovering these objects.

97. What is a case?

It is part of the process of analyzing a program and describes a situation that a program may encounter and which program should take action in that situation.

98. Explain the use of subclasses in a Java program?

Subclasses inherit all public and protected methods and deploy deployment. It also inherits all the default modifier methods and their implementers.

99. How to add menushtcut to menu item?

If there is an instance of the button called b1, you can add the menushcut by calling the b1.setMnemonic method ('F'), from which the user can use the shortcut Alt + F to click the button. there.

100. Can you write a Java class that can be used as an Applet as well as an application?

Yes, just add a main () method to the Applet.

101. What is the difference between Swing and AWT components?

The AWT components are heavy-weight, while the Swing components are lightweight. Heavy components depend on the Local Windowing Toolkit. For instance,, java.awt.Button is a heavy component, when it is running on the Java platform for the Unix platform, it maps to Motif Button really.

102. What is the difference between Constructor and other methods?

The constructor must have the same name as the class name and cannot return a value. They are only called while normal methods can be called multiple times.

103. Are there any limitations when using Inheritance?

Yes, when inheritance is inherited from both parent and interface classes, sometimes it can generate error-prone with dynamic overwriting and dynamic loading in some situations.

104. When is ArrayStoreException thrown?

When copying elements between different arrays, if the source parameter or the destination parameter is not arrays or their types are incompatible, then an ArrayStoreException will be thrown.

105. Can you call this Constructor from Constructor other than a class with multiple Constructors?

Yes, use this () syntax.

106. What is the difference between sleep () and wait () methods?

For instance,, sleep (2000); Make Thread wait 2 seconds correctly. While wait (2000); It can take up to 2 seconds for the Thread to wait. A Thread may stop waiting earlier if it receives a notify () or notifyAll () call. The wait () method is defined in the Object class and the sleep () method is defined in the Thread class.

107. When was ArithmeticException thrown?

108. M?t bi?n là transient (t?m th?i) là gì?

109. Synchronization (??ng b? hóa) là gì?

110. Collection API là gì?

Collection API là m?t t?p h?p các l?p và Interface mà h? tr? các ho?t ??ng trên các Collection c?a ??i t??ng.

111. Trình d?n rác có b?o ??m r?ng m?t ch??ng trình s? không ch?y h?t b? nh??

112. L?p cha g?n nh?t (tr?c ti?p) c?a l?p Applet?

Panel là l?p cha g?n nh?t (tr?c ti?p). M?t panel cung c?p không gian trong ?ó m?t ?ng d?ng có th? ?ính kèm b?t c? thành ph?n nào, bao g?m các panel khác.

113. Toán t? nào trong Java là Right-Associative?

Toán t? = là Right-Associative. (N?u b?n ch?a hi?u right và left associative, b?n theo dõi: Toán t? = cho phép b?n th?c hi?n nhi?u phép gán trong cùng m?t l?nh. Ví d?: a=b=c=d=99;)

114. ?i?m khác nhau gi?a l?nh break và l?nh continue?

L?nh break ch?m d?t m?t l?nh mà nó áp d?ng (switch, for, do, ho?c while). M?t l?nh continue ???c s? d?ng ?? k?t thúc vòng l?p hi?n t?i và tr? v? ?i?u khi?n cho l?nh vòng l?p.

115. N?u m?t bi?n ???c khai báo là private, thì nó có th? ???c truy c?p trong ph?m vi nào?

Bi?n private ch? có th? ???c truy c?p bên trong l?p mà nó ???c khai báo.

116. M?c ?ích c?a l?p System?

M?c ?ích c?a l?p System là cung c?p truy c?p t?i ngu?n h? th?ng.

117. Li?t kê các ki?u g?c trong Java?

Có 8 ki?u d? li?u g?c trong Java là byte, char, short, int, long, float, double và Boolean.

118. M?i quan h? gi?a Clipping và Repainting d??i AWT?

Khi m?t c?a s? ???c repaint b?i AWT Thread, nó thi?t l?p các khu v?c Clipping thành khu v?c c?a c?a s? mà c?n Repainting.

119. L?p nào là l?p cha g?n nh?t (tr?c ti?p) c?a l?p Container?

L?p Component là l?p cha g?n nh?t.

120. L?p Exception nào ???c t?o b?i Java runtime?

Java runtime t?o các RuntimeException và Error.

121. D??i các ?i?u ki?n nào thì m?t ph??ng th?c finalize() c?a ??i t??ng ???c tri?u h?i b?i trình d?n rác (Garbage Collector)?

Trình d?n rác tri?u h?i m?t ph??ng th?c finalize() c?a ??i t??ng khi nó phát hi?n r?ng ??i t??ng ?ã th?t b?i.

122. M?t Thread ?ã ch?t có th? ???c restart l?i nh? th? nào?

M?t Thread ?ã ch?t không th? restart l?i ???c.

123. Các toán t? s? h?c nào có th? gây ra s? ki?n ném m?t ArithmeticException?

Phép chia / và l?y ph?n d? % s? nguyên có th? gây ra s? ki?n ném m?t ArithmeticException.

124. Bi?n ki?u Boolean ???c t? ??ng kh?i t?o v?i giá tr??

Giá tr? m?c ??nh c?a ki?u Boolean là false.

125. Các l?nh try có th? l?ng nhau không?

Have.

126. ClassLoader là gì?

ClassLoader là m?t ??i t??ng mà ??m nhi?m vi?c t?i các l?p. L?p ClassLoader là m?t l?p abstract.

127. ?i?m khác nhau gi?a m?t Interface và m?t l?p Abstract?

M?t l?p Abstract là m?t l?p có th? có các ph??ng th?c instance mà tri?n khai m?t hành vi m?c ??nh. M?t Interface ch? có th? khai báo các h?ng và các ph??ng th?c instance, nh?ng không th? tri?n khai hành vi m?c ??nh và t?t c? ph??ng th?c là abstract ng?m ??nh. M?t Interface có t?t c? thành viên public và không có trình tri?n khai.

128. ?i?u gì x?y ra n?u Static Modifier b? g? b? t? ph??ng th?c main?

Ch??ng trình ném l?i NoSuchMethodError t?i runtime.

129. Giá tr? m?c ??nh c?a m?t tham chi?u ??i t??ng ???c khai báo nh? là m?t bi?n instance?

Giá tr? Null, tr? khi nó ???c khai báo t??ng minh.

130. L?p cao nh?t có th? là private ho?c protected không?

131. T?i sao chúng ta c?n các l?p wrapper?

Chúng ta có th? truy?n chúng ? d?ng các tham s? ph??ng th?c khi m?t ph??ng th?c ch? ??i m?t ??i t??ng. Nó c?ng cung c?p các ph??ng th?c ti?n ích.

132. ?i?m khác nhau gi?a Error và Exception?

133. Có c?n thi?t ?? m?i kh?i try ph?i ???c theo sau b?i m?t kh?i catch không?

Không c?n thi?t ?? m?i kh?i try ph?i ???c theo sau b?i m?t kh?i catch. M?i kh?i try nên ???c theo sau b?i ho?c m?t kh?i catch ho?c m?t kh?i finally.

134. Khi m?t Thread ???c t?o và b?t ??u, tr?ng thái ban ??u (initial state) c?a nó là gì?

M?t Thread sau khi ???c t?o và ???c b?t ??u, nó trong tr?ng thái s?n sàng (ready state).

135. L?p Locale là gì?

L?p Locale ???c s? d?ng ?? thi?t k? ??u ra output c?a ch??ng trình theo các qui ??c c?a m?t khu v?c ??a lý, chính tr?, ho?c v?n hóa c? th?.

136. Ph??ng th?c synchronized và l?nh synchronized là gì?

Các ph??ng th?c synchronized là các ph??ng th?c ???c s? d?ng ?? ?i?u khi?n truy c?p t?i m?t ??i t??ng. M?t l?nh synchronized có th? ch? ???c th?c thi sau khi m?t Thread ?ã thu ???c lock cho ??i t??ng ho?c l?p ???c tham chi?u trong l?nh synchronized ?ó.

137. G?i ph??ng th?c ??ng ho?c ?a hình t?i runtime là gì?

138. Dynamic Binding (Late Biding) là gì?

Binding là nói t?i vi?c g?n k?t l?i g?i m?t t?i code ?? ???c th?c thi ?? ph?n h?i l?i l?i g?i ?ó. Dynamic Binding ngh?a là code ???c liên k?t v?i l?i g?i m?t th? t?c ?ã cho không ???c bi?t cho t?i th?i ?i?m c?a l?i g?i ?ó t?i runtime.

FAQ

What should readers know about 200 Common Java Interview Questions, with Reference Answers?

Start with the core concepts and examples in this guide. They provide the context needed to understand the topic accurately and apply the information with fewer mistakes.

Why is 200 Common Java Interview Questions, with Reference Answers important?

Understanding this topic helps readers make better technical decisions, recognize common problems, and choose safer or more efficient solutions.

How should beginners use this guide?

Work through each section in order, test unfamiliar steps in a safe environment, and keep a backup of important files or settings before making significant changes.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.