Java program operating mechanism and development environment

Source: Internet
Author: User
Tags garbage collection

  1. Java is both a compiled and interpreted language
    Java source files are first required to generate a bytecode file with a. class suffix (Platform-agnostic, only for the JVM) through Javac compilation, and then use a Java virtual machine to interpret the bytecode as a machine code run on a particular platform.
  2. Java Virtual Machine JVM
    The JVMs on different platforms are different, but they all provide the same interface.
  3. Developing Java Preparation
    • Download the JDK that installs the JAVA8 and add the JDK's installation path to the environment variables.
    • Developing Java requires the installation of JDK,JDK with the Java compiler (Javac command tool), Java Runtime Environment (JRE), Common Java class libraries, and so on.
    • The JRE contains the JVM, as well as the class loader, bytecode checker, and a large number of base class libraries for environmental support.
    • If you are just running a Java program, you can install only the JRE.
  4. The first Java program
    • Writes the first well-known program: HelloWorld.

      pulic calss helloworld{public  static  void  main  (string[] args) { System. out . println 
        ( "HelloWorld" );}  
    • The
    • compiles the Java program using the Javac command.
      • command Line Enter cmd, enter the path to the Java source file
      • Enter the following command, where Destdir is the target build path
        javac-d destdir Helloworld.java
      • to enter the Destdir path, you can see that a bytecode file with the suffix. Class has been generated
    • Use the Java command to interpret the execution bytecode file.
      • Run the following command to execute the program
        java HelloWorld
  5. Basic rules for Java programs
    • Java is a purely object-oriented language, and the class is the smallest program unit of a Java program.
    • Javac can compile a class, while explaining that executing a class requires the Main method as the entry, and the main method is fixed.
    • Java is strictly case-sensitive, the class name is capitalized, the first letter of the method name is lowercase, and the keyword is lowercase.
    • A Java source file can define at most one public class, because the source file name needs to be the same as the class name of the public class.
  6. Garbage collection mechanism
    • Disadvantages of explicit garbage collection
      • Forgetting to recycle leads to memory leaks and reduces system performance
      • Error Recycling Program core class library memory, causing system crash
    • The heap memory of the Java Virtual machine is used to hold the object of the class, and a super thread of the JVM detects that if an object is not referenced for a long time, the GC frees up the memory space it occupies, while defragmenting the heap memory to the end of the heap, sorting out the new memory allocated to other objects.
    • Advantages of using GC
      • Improve programming efficiency
      • Protection of the integrity and security of the program
    • Disadvantages of using GC
      • Garbage collection occurs when the CPU is idle or low on memory, which affects program performance
    • Characteristics of GC
      • Only the memory space of the JVM heap memory can be reclaimed and the resources of physical memory cannot be reclaimed
      • Setting the object's reference variable to NULL can imply that the GC reclaims the object
      • Calling the runtime object's GC () or System.GC () is only a recommended system for garbage collection and cannot be controlled precisely
  7. Using IDE Tools
    • Download and install Eclipse development tools
    • Configuring Auto-completion
      • Windows-preferences-java-editor-content Asist, change auto activation triggers for Java to ". ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ "Can
    • Familiarity with shortcut keys
      • Auto-Import related package: Ctrl+shift+o
      • ...

Java program operating mechanism and development environment

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.