Home >Java >javaTutorial >Java overview + environment construction

Java overview + environment construction

巴扎黑
巴扎黑Original
2017-06-23 16:27:321237browse

Written before:

I have read the basics of Java several times, but I forgot about it after a while, so this time I decided to spend some time organizing it. A series of blogs for easy reference in the future. This series is compiled based on two books on Java programming ideas + Java core technology. These two books are also two books that I highly recommend everyone to read, because each time you read them, you will get different results. The two books are horizontal. Seeing how they complement each other will definitely benefit you a lot, so stay tuned!

Section 1: Introduction to Java

##Java was developed by Sun in 1995 An object-oriented programming language launched in May, which implements the object-oriented theory extremely well, pays more attention to the object itself and does not need to pay too much attention to the process of events.  

Java consists of four parts: Java programming language + Java class format file + Java virtual machine + Java application program interface. We define different class files through the IDE. Access the resource system by calling the class method (Java API), compile the source file into a .class file, and run the file through the Java virtual machine.  

Java White Paper:

    Simplicity: The syntax is simple and easy to understand, eliminating C++ It is difficult to understand the header file pointers, etc. The class library is small, but as the class library increases and the thread support size increases, it is object-oriented: pay more attention to the object itself, and do not need to pay too much attention to the implementation process.
  • Network Skills: Java's networking capabilities are simple and easy to use, used to handle TCP/IP protocols like http or ftp, allowing opening or Access objects on the network.
  • Robustness: Java’s strong typing mechanism, exception handling, automatic garbage collection, etc. are important guarantees for the robustness of Java programs. Java uses a pointer model to eliminate the possibility of overwriting memory and damaging data. Java does not need to use pointers to construct string arrays and other institutions, but if necessary Java also has pointer capabilities such as linked lists.
  • Security: Java has no pointers, so programmers cannot get hidden secrets and fake pointers to point to memory. More importantly, the Java compiler does not handle storage arrangement decisions, so the programmer cannot guess the actual storage arrangement of the class by looking at the declaration. Storage references in compiled Java code have the actual storage address determined by the Java interpreter at runtime.
  • #Portability: Java makes language declarations independent of implementation aspects. For example, Java explicitly states the size and operation behavior of each basic data type (these data types are described by Java syntax). The Java environment itself is portable to new hardware platforms and operating systems. The Java compiler is also written in Java, while the Java runtime system is written in ANSIC language.
  • #Explanation: Java programs are compiled into bytecode format on the Java platform and can then be run on any system that implements this Java platform. At runtime, the Java interpreter in the Java platform interprets and executes these bytecodes, and the classes required during the execution are loaded into the running environment during the connection phase.
  • High performance: Java programs can run on any system that implements a Java interpreter and run-time system.
  • #Multi-threading: Multi-threading can bring better interactive response and user behavior.
  • Dynamicity: The Java language is designed to adapt to changing environments. It is a dynamic language. For example, classes in Java are loaded on demand, and some are even obtained over the network.
Section 2: History of Java Development

    1991 In 2008, Sun was preparing to develop a device similar to a cable TV converter box, and the project was named: Green. The code is short and compact and has nothing to do with the platform. Based on the Pascal language, a virtual machine-generated intermediate code is designed for portability, namely the Java virtual machine
  1. 1994 Green Project (First Pascal Company) disbanded

  2. May 23, 1995 Java on SunWorld After getting the demonstration, the great Java language was born

  3. In early 1996, Sun released the first version of Java, but the Java1.0 version could not be actually used in development

  4. Java 1.2 version (Standard Edition-J2SE-JavaSE) was released in December 1998. This version is closer to Java's write once and run anywhere concept and was released three days later ( Micro Edition-J2ME-JavaME) and (Enterprise Edition-J2EE-JavaEE)

  5. Released Java1.3 in 2000

  6. Java 1.4 was released in 2002

  7. In 2004, Java made major improvements to the language, which can be described as another major improvement Milestone, and officially named Java 5.0 version, and adding concepts such as generics, foreach loops, enumerations, etc.

  8. Released Java 6 version in 2006

  9. In 2009, Sun's once glorious empire finally fell. After being acquired by Oracle, Java entered a period of stagnation

  10. Java 7 version released in 2011

  11. Java 8 version released in 2014

Section 3: Java development environment setup

  • JDK (Java Development Kit): Programmers who write Java programs Software used

  • JRE: Software used to run Java programs

  • IDE: Integrated development environment such as: eclipse, idea, etc.

JDK download address:. Note: The default installation path is under Program Files. It is best to change the path or replace the spaces to avoid unnecessary trouble.

Directory Structure:


    • bin: Compiler and tools

    • db: Relational database file developed by Java

    • include: File used to compile native methods

    • javafx-src: JavaFX Script is a declarative, statically typed programming language

    • jre: Java runtime environment file

    • ##lib: Class library file

    • src: Class library source file

## Environment variable configuration:

JAVA_HOME: D:\Java\jdk1.8.0_31 It points to the jdk installation directory. Software such as Eclipse/NetBeans/Tomcat searches for the JAVA_HOME variable to find and use the installed jdk.

PATH: %JAVA_HOME%\bin; Its function is to specify the command search path. When executing a command such as javac on the command line to compile a java program, it will go to the path specified by the PATH variable. Search to see if you can find the corresponding command program. We need to add the bin directory under the jdk installation directory to the existing PATH variable. The bin directory contains frequently used executable files such as javac/java/javadoc. After setting the PATH variable, you can enter it in any directory. Execute javac/java and other tools.

CLASSPATH: .;%JAVA_HOME%/lib/dt.jar;%JAVA_HOME%/lib/tools.jar is used to specify the class search path. To use the already written class, The prerequisite is of course that they can be found. The JVM uses CLASSPATH to find classes. We need to set dt.jar and tools.jar in the lib subdirectory under the jdk installation directory to CLASSPATH. Of course, the current directory "." must also be added to this variable.

Environment variable verification:

CMD verification: Enter Java -version and press Enter. The console will output the jdk version number, indicating that the installation is successful.

Create a new HelloWorld.java file, enter the corresponding directory, enter javac HelloWorld.java and press Enter, then enter java HelloWorld and press Enter to output Hello World on the console, indicating that the environment variables are configured successfully.

Note: The javac program is a Java compiler. It compiles HelloWorld.Java into a HelloWorld.class file and sends it to the Java virtual machine. The virtual machine executes the compiler and places it in the class file. bytecode.

Note: When compiling, you need to provide a suffix for the file to be compiled, namely: HelloWorld.java, and when running, you only need to specify the class name, and no suffix is ​​required: HelloWorld. .

The above is the detailed content of Java overview + environment construction. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn