An overview of Java program apes

Source: Internet
Author: User

A program written in the Java language requires a compilation step, but this compilation step does not generate a platform-specific machine code, but instead generates a platform-independent bytecode (that is, the *.class file). This bytecode must have a Java interpreter to execute. Therefore, it can be considered that the Java language is both a compiled language and an interpreted language, or that Java is not purely a compiled language, nor is it purely an interpreted language.

The execution of a Java program must be compiled first and then interpreted in two steps.

Java is the Java virtual machine that interprets the execution of bytecode files, which is the JVM (Java Vsan). The JVM is an abstract computer that has instruction sets and uses different storage areas. It is responsible for executing instructions and managing data, memory, and registers. The Java Virtual Machine specification, developed by Oracle, specifies a uniform standard for the JVM, defining the following details of the JVM: instruction set, register, class file format, stack, garbage collection heap, storage area, provide a unified standard, and finally implement the cross-platform independence of Java programs.

Devepment Tools component in JDK: This is the core of the JDK, including the command tools necessary to compile the Java program. In fact, this option already contains the JRE that runs the Java program, which is installed in a subdirectory of the JDK installation directory, which is why there is no need to install a public JRE.

Why not install a public JRE? The public JRE is a standalone JRE system that is installed separately under the system's other paths. The public JRE registers the Java Runtime Environment with Internet Explorer and the system. In this way, the public JRE can be used by any application in the system. There is not much need to install a public JRE because there are fewer opportunities to execute applets on a Web page, and it is entirely possible to run Java programs using the JRE in the JDK directory.

Source code: Installing this option will install all of the Java Core Class library sources.

After installing the JDK, you can see the following path:

  Bin: Various tool commands for JDK are stored under this path, and common Javac and Java commands are placed under this path.

  DB: Path To install Java DB for this path

Include: some platform-specific header files

  JRE: The JRE environment required to run the Java program is installed under this path

  Lib: The actual execution of the JDK tool command is stored under this path

  Javafx-src.zip: The compressed file is stored in Java FX All core class library source code

  Src.zip: The zip file contains the source code for all Java Core class libraries

The Java program must go through two steps: 1, compile the file into bytecode, 2, explain the execution platform-independent bytecode program using Java and javac two commands respectively.

If the compilation appears ' XXX ' is not an internal or external command, it is not a running program, because the program cannot find the command (Windows system is not case-sensitive, so path and path is the same, and Linux is case-sensitive, setting path and path is different, only need to set the PATH environment variable can be 。 Whatever the system, simply add the path of the Java and Javac two commands to the PATH environment variable and you can compile and run the Java program.

Setting the environment variable in the user variable is the environment variable that is used to set the current user, and the system variable is used to set the environment variable for the entire system. Windows system, the system makes the path already exist, can be changed directly, after adding the JDK installation directory bin file installation directory, it is generally recommended to add user variables.

Java is a strictly case-sensitive language.

Java programs are purely object-oriented programming languages, so Java programs must exist in the form of classes (class), which is the smallest program unit of a Java program. Java programs do not allow executable statements, methods and other components to exist independently, all the program parts must be placed in the class definition.

If a class can be interpreted directly by the compiler, the class must contain the main method, and the main method must be decorated with public static void, and the formal parameter of the main method must be a string array type (string[] args is a string array type). That is, the main method is almost fixed. The Java virtual machine begins to interpret execution from this main method, so the main method is the entry for the Java program.

Typically, the main file name of the Java program source file is arbitrary, except in one case, if the Java program source code defines a public class, the source code must have the same primary file name as the class name of the public class (that is, the class definition uses the Public keyword), so , the Java source file contains a maximum of a public defined class.

All the keywords in Java are lowercase.

The memory allocation and recycling of Java programs is done automatically by the JRE in the background, and the JRE is responsible for reclaiming memory that is no longer used, a mechanism known as garbage collection. Typically, the JRE provides a background thread for detection and control, typically by automatically garbage collection when the CPU line or memory is low, and the programmer cannot precisely control the time and order of garbage collection.

Java heap Memory is a run-time data area that holds instances (objects) of a class, and Java heap memory stores all objects created by running applications that do not require the program to be explicitly released through code. Recycling of heap memory is the responsibility of garbage collection, and all JVM implementations have a heap memory managed by the garbage collector. Garbage collection is a dynamic storage management technology that automatically frees objects that are no longer referenced by the program and implements the automatic recovery of memory resources according to a specific garbage collection algorithm.

In order for the garbage collection mechanism to reclaim objects that are no longer in use, you can set the reference variable of the object to null, implying that the garbage collection mechanism can reclaim the object.

When writing Java programs, a basic principle is: do not drink them for objects that are not needed. If you keep a reference to these objects, the garbage collection mechanism will not reclaim the object for the time being, resulting in less available memory for the system, and more frequent garbage collection execution when the system is free of memory, resulting in degraded system performance

  


  

  

Overview of Java program Apes

Related Article

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.