200 common Java interview questions, with reference answers

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.

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 be used to 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 is used to 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 is used to 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 be used to 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 example, 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 is used to 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:

  1. All Exception must be a Throwable child.

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

  3. 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 is used to 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:

  1. Interface cannot be initialized.

  2. An interface does not contain any constructors.

  3. 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 is used to 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 is used to 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:

  1. Throw is used to trigger an Exception while throws are used in Exception's declaration.

  2. Without throw, Checked Exception cannot be processed, while throws are used to 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:

  1. public - it is Access Specifier.

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

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

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

  5. 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 is used to store XML, Java classes, and JavaServer pages, which are used to 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 is used to 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 are used to 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 usually 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 example: 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 is used to 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 is used to 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 example, 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 example, 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?

ArithmeticException được ném khi chia số nguyên cho số 0 hoặc lấy phần dư của phép chia cho số 0. Nó không bao giờ được ném trong các phép toán về số thực.

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

Một biến transient là một biến mà không thể được xếp theo thứ tự trong Serialization và nó được khởi tạo bởi giá trị mặc định của nó trong Deserialization.

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

Synchronization là khả năng điều khiển truy cập của nhiều Thread tới nguồn đã chia sẻ. Từ khóa synchronized trong Java cung cấp locking để đảm bảo sự truy cập tương hỗ mang tính loại trừ của nguồn đã chia sẻ và ngăn cản Data Race (Tranh đoạt dữ liệu).

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ớ?

Trình dọn rác không bảo đảm rằng một chương trình sẽ không chạy hết bộ nhớ. Nó là có thể để cho các chương trình sử dụng hết nguồn bộ nhớ nhanh hơn việc chúng bị thu thập bởi trình dọn rác. Các chương trình cũng là có thể tạo các đối tượng mà không phụ thuộc vào trình dọn rác.

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?

Không, một lớp cao nhất không thể là private hoặc protected. Nó chỉ có thể là public hoặc không có modifier nào.

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?

Một Error là một điều kiện không thể cứu chữa xuất hiện tại runtime, ví dụ OutOfMemory error. Các Exception là các điều kiện mà xuất hiện là do input không phù hợp, hoặc sai, … ví dụ FileNotFoundException sẽ bị ném nếu file đã cho không tồn tại.

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ì?

Gửi phương thức động hoặc đa hình tại runtime là một tiến trình trong đó một lời gọi tới một phương thức bị ghi đè được giải quyết tại runtime thay vì tại compile time. Trong tiến trình này, một phương thức bị ghi đè được gọi thông qua biến tham chiếu của một lớp cha.

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.

139. Constructor có thể được kế thừa không?

Không, Constructor không thể bị kế thừa.

140. Lợi thế của ArrayList so với các mảng?

ArrayList có thể tự động tăng kích cỡ và cung cấp một kỹ thuật chèn và tìm kiếm mạnh mẽ hơn khi so sánh với mảng thông thường.

141. Hoạt động xóa trong LinkedList là nhanh hơn trong ArrayList, tại sao?

Hoạt động xóa trong LinkedList là nhanh hơn bởi vì nó chỉ bao gồm việc cập nhật con trỏ kế tiếp trong node trước node bị xóa và cập nhật con trỏ đằng trước trong node sau node bị xóa.

142. Bạn quyết định khi nào sử dụng ArrayList và LinkedList?

Nếu bạn cần thường xuyên thêm và xóa các phần tử từ giữa danh sách và chỉ truy cập các phần tử theo dãy, thì LinkedList nên được sử dụng. Nếu bạn cần hỗ trợ truy cập ngẫu nhiên, mà không chèn hoặc xóa các phần tử từ bất kỳ vị trí nào khác ngoài vị trí cuối, thì nên sử dụng ArrayList.

143. Một Values Collection View là gì?

Nó là một Collection được trả về bởi phương thức values() của Map Interface. Nó bao gồm tất cả đối tượng hiện diện như là các value trong Map đó.

144. Dot Operator (Toán tử .) là gì?

Dot Operator được sử dụng để truy cập các biến và phương thức instance của các đối tượng lớp. Nó cũng được sử dụng để truy cập các lớp, các package con từ một Package.

145. Bạn có thể sử dụng Private Constructor ở đâu và như thế nào?

Constructor dạng private được sử dụng nếu bạn không muốn các lớp khác khởi tạo đối tượng và để ngăn cản việc xuất hiện các lớp con.

146. Type Casting (Ép kiểu) là gì?

Type Casting (Ép kiểu) nghĩa là xem một biến ở một kiểu này như thể nó là kiểu khác.

147. Miêu tả vòng đời (Life Cycle) của Thread?

Một Thread là một sự thực thi trong một chương trình. Vòng đời của Thread bao gồm:

  1. Trạng thái Newborn
  2. Trạng thái Runnable
  3. Trạng thái Running
  4. Trạng thái Blocked
  5. Trạng thái Dead

148. Điểm khác nhau giữa hai toán tử >> và >>> ?

Toán tử >> mang sign bit khi dịch chuyển sang phải. Toán tử >>> điền bit 0 khi đã được dịch chuyển.

149. Phương thức nào của lớp Component được sử dụng để thiết lập vị trí và kích cỡ của một component?

Sử dụng phương thức setBounds() cho mục đích này.

150. Dãy giá trị của kiểu short?

Dãy giá trị của kiểu short là từ -(2^15) tới 2^15 - 1.

151. Lớp cha gần nhất của Menu?

Là lớp MenuItem.

152. Java có cho phép các tham số mặc định không?

Java không cho phép các tham số mặc định (Default Argument).

153. Trong Java, hệ cơ số nào được biểu thị với số 0 bắt đầu?

Hệ cơ số 8, ví dụ: 06

154. Trong Java, hệ cơ số nào được biểu thị với phần bắt đầu là 0x hoặc 0X?

Hệ thập lục phân, ví dụ: 0XF.

155. Lệnh break có thể được sử dụng như là các nhãn (label) trong Java?

Có, ví dụ như break one;

156. Lệnh import được sử dụng ở đâu trong một chương trình Java?

Lệnh import được sử dụng ở phần đầu chương trình sau lệnh package.

157. Giải thích phương thức suspend() dưới lớp Thread?

Nó được sử dụng để tạm dừng sự thực thi của Thread.

158. Giải thích phương thức isAlive() dưới lớp Thread?

Nó được sử dụng để tìm xem có hay không một Thread là vẫn đang chạy.

159. Bạn hiểu gì về phương thức currentThread()?

Đây là một phương thức public và static để thu nhận một tham chiếu tới Thread hiện tại.

160. Giải thích main thread dưới sự thực thi của lớp Thread?

Main thread được tạo tự động và nó bắt đầu thực thi ngay khi một chương trình bắt đầu. Nó là một thread mà từ đó hình thành tất cả thread con khác.

161. Vòng đời của một Applet?

Vòng đời của một Applet gồm:

  1. Khởi tạo

  2. Begin

  3. Stop

  4. Cancel

  5. Painting

162. Vai trò của phương thức init() dưới Applet?

Nó khởi tạo Applet và là phương thức đầu tiên được gọi.

163. Phương thức nào được gọi bởi lớp Applet để tải một hình ảnh?

Sử dụng phương thức getImage(URL của đối tượng, tên file).

164. Định nghĩa phần code được sử dụng như là một thuộc tính của Applet?

Nó được sử dụng để xác định tên của lớp Applet.

165. Canvas là gì?

Nó là một bề mặt bản vẽ đơn giản mà được sử dụng để vẽ các hình ảnh hoặc để thực hiện các hoạt động đồ họa khác.

166. Định nghĩa Lập trình mạng?

Nó nói tới việc viết các chương trình mà thực thi qua nhiều thiết bị (máy tính), trong đó các thiết bị được kết nối với nhau bởi sử dụng mạng.

167. Socket là gì?

Socket cung cấp kỹ thuật giao tiếp giữa hai máy tính bởi sử dụng TCP. Một chương trình Client tạo một Socket trên đầu giao tiếp của nó và cố gắng kết nối Socket đó tới một Server.

168. Lợi thế của Java Socket?

Lập trình dựa trên Socket hiệu quả có thể dễ dàng được triển khai cho truyền thông chung. Các Socket là linh động và nó làm lưu lượng truyền qua mạng ít hơn.

169. Hạn chế của Java Socket?

Truyền thông dựa trên Socket chỉ cho phép gửi các gói dữ liệu thô giữa các ứng dụng. Cả Clietn-Side và Server-Side phải cung cấp các kỹ thuật để làm cho dữ liệu đó có thể dùng được trong bất cứ cách thức nào.

170. Lớp nào được sử dụng bởi các ứng dụng Server để thu nhận một cổng (port) và các yêu cầu từ Client?

Lớp java.net.ServerSocket được sử dụng cho mục đích này.

171. Lớp nào biểu diễn Socket mà cả Server và Client sử dụng để giao tiếp với nhau?

Đó là lớp java.net.Socket.

172. Tại sao Generic được sử dụng trong Java?

Generic cung cấp tính an toàn kiểu tại compile-time mà cho phép lập trình viên để bắt các kiểu không hợp lệ tại thời gian biên dịch. Các phương thức Generic và các lớp Generic trong Java cho phép lập trình viên xác định, với một khai báo phương thức đơn, một tập hợp các phương thức liên quan, hoặc với một khai báo lớp đơn là một tập hợp các kiểu liên quan.

173. Bạn cần thiết lập các biến môi trường nào trên thiết bị để có thể chạy các chương trình Java?

Hai biến môi trường CLASSPATH và PATH.

174. Có cần thiết phải nhập java.lang package không?

Is not. Nó được tải theo mặc định bởi JVM.

175. Lớp cao nhất được lồng là gì?

Nếu một lớp được khai báo bên trong một lớp và xác định Static Modifier, bộ biên dịch xem lớp đó giống như bất cứ lớp cao nhất nào khác. Lớp cao nhất bị lồng là một lớp Inner.

176. Trình bày Externalizable Interface?

Externalizable là một Interface chứa hai phương thức readExternal và writeExternal. Hai phương thức này cung cấp cho bạn một điều khiển thông qua kỹ thuật Serialization.

177. Khối finally sẽ vẫn thực thi nếu như có System.exit(0); được viết ở cuối khối try?

Trong trường hợp này, khối finaaly sẽ không thực thi, bởi vì khi bạn cung cấp System.exit(0); thì điều khiển ngay lập tức thoát khỏi chương trình đó, và vì thế khối finally này sẽ không bao giờ thực thi.

178. Bạn hiểu gì về Daemon Thread?

Daemon Thread là một Thread có quyền ưu tiên thấp, chạy không liên tục trong Background thực hiện hoạt động của trình dọn rác cho Java Runtime System.

179. Phương thức được sử dụng để tạo Daemon Thread?

Phương thức setDaemon được sử dụng để tạo một Daemon Thread.

180. Tất cả Thread phải triển khai phương thức nào?

Tất cả tác vụ phải triển khai phương thức run().

181. Lớp GregorianCalendar là gì?

Lớp GregorianCalendar cung cấp sự hỗ trợ Western Calendar truyền thống.

182. Bạn hiểu gì về lớp SimpleTimeZone?

Lớp SimpleTimeZone cung cấp sự hỗ trợ cho một Gregorian Calendar.

183. Điểm khác nhau giữa hai tham số size và capacity của một Vector?

Tham số size là số phần tử thực sự được lưu giữ trong Vector đó, trong khi capacity là số phần tử tối đa nó có thể lưu giữ tại một thời điểm nào đó.

184. Một Vector có thể chứa các đối tượng hỗn tạp không?

Có, một Vector có thể chứa các đối tượng hỗn tạp. Bởi vì một Vector lưu trữ mọi thứ theo khái niệm Đối tượng.

185. Trình bày Enumeration?

Một Enumeration là một Interface chứa các phương thức để truy cập cấu trúc dữ liệu lớp dưới mà từ đó Enumeration

5 ★ | 1 Vote | 👨 101 Views
« PREV POST
NEXT POST »