Java face question (ii)

Source: Internet
Author: User
Tags define local event listener finally block

Link above: Click to jump

Garbage collector (Garbage collectors)

What is the purpose of garbage collection in 35.Java? When does garbage collection take place?

The purpose of garbage collection is to identify and discard objects that the app is no longer using to free and reuse resources.

What will 36.system.gc () and RUNTIME.GC () do?

These two methods are used to prompt the JVM for garbage collection. However, starting or delaying a garbage collection immediately depends on the JVM.

When is the 37.finalize () method called? What is the purpose of the destructor (finalization)?

The garbage collector calls the object's Finalize () method before releasing the memory occupied by the object. It is generally recommended that the resources held by the object be disposed of in this method.

38. If the object's reference is set to NULL, will the garbage collector immediately release the memory occupied by the object?

No, in the next garbage collection cycle, this object will be recoverable.

What is the structure of the 39.Java heap like? What is the permanent generation in the heap (Perm Gen space)?

The JVM's heap is the run-time data area, and all instances and arrays of classes are allocated memory on the heap. It is created when the JVM is started. The heap memory that the object occupies is reclaimed by the automatic memory management system, which is the garbage collector.

Heap memory is made up of surviving and dying objects. The surviving objects are accessible to the app and are not garbage collected. The object of death is the object that the app is inaccessible and has not been reclaimed by the garbage collector. Until the garbage collector reclaims these objects, they will occupy the heap memory space.

40. What is the difference between a serial (serial) collector and a throughput (throughput) collector?

The throughput collector uses a parallel version of the new generation garbage collector, which is used for medium-sized and large-scale data applications. The serial collector is sufficient for most small applications, which require about 100M of memory on modern processors.

41. In Java, when can objects be garbage collected?

When an object becomes inaccessible to an application that is currently using the object, the object can be recycled.

Is there a garbage collection in the permanent generation of 42.JVM?

Garbage collection does not occur in a permanent generation, and a full garbage collection is triggered if the permanent generation is full or the threshold is exceeded. If you look closely at the output of the garbage collector, you will find that the permanent generation is also recycled. This is why the correct permanent generation size is very important for avoiding full GC. Please refer to the following Java8: from the permanent generation to the metadata area, JAVA8 has removed the permanent generation, adding a new native memory area called the metadata area

Exception handling

What are the two types of exceptions in 43.Java? What difference do they have?

There are two types of exceptions in Java: Checked (checked) exceptions and unchecked (unchecked) exceptions. An unchecked exception does not need to be declared on a method or constructor, even if the execution of a method or constructor may throw such an exception, and an unchecked exception can be propagated to the outside of the method or constructor. Instead, the checked exception must be declared on the method or the constructor with the throws statement.

What is the difference between Exception and Error in 44.Java?

Both exception and Error are subclasses of Throwable. Exception is used for exceptions that can be captured by the user program. Error defines an exception that is not expected to be caught by the user program.

What is the difference between 45.1 throw and throws?

The Throw keyword is used to explicitly throw an exception in a program, whereas a throws statement is used to indicate an exception that the method cannot handle. Each method must specify which exceptions cannot be handled, so the caller of the method will be able to ensure that the exceptions that may occur are handled, and that multiple exceptions are separated by commas.

45.2 what is the importance of the finally code block when handling exceptions?

The finally block of code is always executed, regardless of whether an exception is thrown. Even if there is no catch statement and throws an exception, the finally code block will still be executed. Finally, the final code block is primarily used to release resources, such as: I/O buffers, database connections.

46. What happens to the Exception object after the exception handling is complete?

The Exception object is reclaimed during the next garbage collection.

What is the difference between a 47.finally code block and a Finalize () method?

The finally code block executes regardless of whether or not an exception is thrown, and it is primarily used to release resources that the application occupies. The Finalize () method is a protected method of the object class that is called by the Java virtual machine before the objects are garbage collected.

Java applets (applets)

48. What is an Applet?

Java applets are programs that can be included in an HTML page and can be executed by a Java-enabled client browser. Applets are primarily used to create dynamically interacting Web applications.

49. Explain the life cycle of the Applet

Applets can go through the following states:

Init: It will be initialized every time it is loaded. Start: Executes the applet. Stop: Ends the execution of the applet. Destroy: Before uninstalling the applet, do the final cleanup work.

50. What happens when an applet is loaded?

First, create an instance of the Applet control class, then initialize the applet, and finally start running.

What is the difference between 51.Applet and normal Java applications?

Applets are run in Java-enabled browsers, and Java applications are standalone Java programs that can run outside the browser. However, they all need to have a Java virtual machine.

Further, the Java application requires a main function with a specific method signature to begin execution. Java applets do not need such a function to begin execution.

The last applet generally uses a very strict security policy, and Java applications generally use a more lenient security policy.

What are the limitations of the 52.Java applet?

Primarily for security reasons, the following restrictions are imposed on applets: applets are not able to load class libraries or define local methods. Applets cannot read and write files on a host. Applets cannot read specific system properties. An applet cannot initiate a network connection unless it is an on-boarding host. Applets are not able to open any other programs on the host.

53. What is an untrusted applet?

Untrusted applets are Java applets that cannot access or execute Local system files, and all downloaded applets are untrusted by default.

54. What is the difference between an applet loaded from a network and an applet loaded from a local file system?

When the applet is loaded from the network, the applet is loaded by the applet ClassLoader, which is limited by the Applet security Manager.

When the applet is loaded from the client's local disk, the applet is loaded by the file system loader.

Applets loaded from the file system allow the client to read files, write files, load class libraries, and also allow other programs to execute, but not byte-code verification.

What is a 55.applet class loader? What does it do?

When the applet is loaded from the network, it is loaded by the applet ClassLoader. The class loader has its own Java namespace hierarchy. The class loader guarantees that classes from the file system have a unique namespace, and that classes from network resources have unique namespaces.

When a browser loads an applet over a network, the applet's class is placed in a private namespace associated with the source of the applet. Then, the classes that are loaded into the ClassLoader are validated by the validator. The validator checks to see if the class file format adheres to the Java language specification, ensures that no stack overflow (stacks overflow) or underflow (underflow) is present, and that the parameters passed to the bytecode directive are correct.

What is the 56.applet security Manager? What does it do?

The Applet security Manager is a mechanism that imposes restrictions on applets. Browsers can have only one security manager. The security Manager is created at boot time and cannot be overwritten or extended after it is replaced.

Swing

57. What is the difference between the pop-up selection menu (Choice) and the list

The Choice is presented in a compact form that requires a drop-down to see all the options. Only one option can be selected at a time in Choice. List can have multiple elements visible at the same time, supporting the selection of one or more elements.

58. What is a layout manager?

The layout manager is used to organize components in containers.

59. What is the difference between the scroll bar (Scrollbar) and the scroll panel (jscrollpane)?

ScrollBar is a component that is not a container. And ScrollPane is a container. ScrollPane handles scrolling events on its own.

60. Which Swing methods are thread-safe?

There are only 3 thread-safe methods: Repaint (), revalidate (), and invalidate ().

61. Say three types of components that support redrawing (painting).

Canvas, Frame, Panel, and Applet support redrawing.

62. What is clipping (clipping)?

Limits the drawing operations on a given area or shape to be clipped.

What is the difference between 63.MenuItem and Checkboxmenuitem?

The Checkboxmenuitem class inherits from the MenuItem class, and the Support menu options can be checked or unchecked.

64. How are the elements in the Edge layout (borderlayout) laid out?

The elements inside the borderlayout are laid out according to the east of the container.

65. How are the elements in the grid package layout (gridbaglayout) laid out?

The elements inside the gridbaglayout are laid out according to the grid. Elements of different sizes may occupy more than 1 rows or columns in the grid. Therefore, the number of rows and columns can be different sizes.

What is the difference between 66.Window and Frame?

The Frame class inherits the window class, which defines a main application window that can have a menu bar.

67. What is the connection between cropping (clipping) and redrawing (repainting)?

When the window is redrawn by the AWT redraw thread, it sets the clipping region to the area of the window that needs to be redrawn.

68. What is the relationship between the event listener interface (Event-listener interface) and the event adapter (event-adapter)?

The event listener interface defines the methods that the event handler must implement for a particular event. The event adapter provides the default implementation for the event listener interface.

How does a 69.GUI component handle its own events?

The GUI component can handle its own events as long as it implements the corresponding event listener interface and takes itself as an event listener.

What are the advantages of the 70.Java Layout Manager over traditional window systems?

Java uses the layout manager to place components on all Windows platforms in a consistent manner. Because the layout manager does not bind to the absolute size and location of the component, they are able to adapt to the specific platform of a cross-window system.

What design pattern does the 71.Java Swing component use?

The Swing component in Java uses the MVC (view-model-Controller) design pattern.

link above: Click to jump

Java face question (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.