Getting started with Java

An overview of the Java language

⭕ is a high-level programming language launched by SUN (Stanford University Network) in 1995.

⭕ is an Internet-oriented programming language. Java was initially attractive because Java programs could be run in a web browser. These Java programs are called Java applets. Applets use a modern graphical user interface to interact with web users. The applet is embedded in the HTML code.

⭕ With the continuous maturity of Java technology in the web, it has become the preferred development language for web applications.

⭕ When the team of James Gosling, the father of java, developed the "Green" project, they found that C lacked a garbage collection system, as well as portable security, distributed programming and multi-threading capabilities . In the end, they wanted a platform that was easy to port to a variety of devices.
Java indeed inherits many components from C language and C++ language, and Java can even be regarded as a product of the development and derivation of C-like language . For example, the variable declaration, operator form, parameter passing, flow control and other aspects of Java language are exactly the same as those of C language and C++ language. But at the same time, Java is a pure object-oriented programming language , which inherits the core of C++ language object-oriented technology. Java abandons the characteristics of pointers (replaced by references), operator overloading, and multiple inheritance (replaced by interfaces) that are prone to errors in the C language, and adds a garbage collector function to recycle objects that are no longer referenced. occupied memory space. JDK1.5 introduced generic programming (Generic Programming), type-safe enumeration, variable length parameters and automatic loading/unboxing

2. A Brief History of Java

⭕ In 1991 Green project, the development language was originally named Oak (Oak)
⭕ In 1994, the development team realized that Oak is very suitable for the Internet
⭕ In 1996, JDK 1.0 was released, and about 83,000 web pages were made with Java technology
⭕ In 1997, JDK 1.1 was released, and the JavaOne conference was held, which was the largest conference of its kind in the world at that time.
In 1998, JDK 1.2 was released, and the enterprise platform J2EE was released in the same year. In
1999, Java was divided into J2SE, J2EE and J2ME, and JSP/Servlet technology
was born . Release milestone version: JDK 1.5, to highlight the importance of this version, renamed JDK 5.0
⭕ 2005, J2SE -> JavaSE, J2EE -> JavaEE, J2ME -> JavaME
⭕ In 2009, Oracle Corporation acquired SUN, transaction price 74 USD 100 million
⭕ In 2011, JDK 7.0 was released
In 2014, JDK 8.0 was released, which is the most changed version since JDK 5.0
⭕ In 2017, JDK 9.0 was released to maximize modularity
⭕ In March 2018, JDK 10.0, version Also known as 18.3
⭕ September 2018, JDK 11.0 was released, version number also known as 18.9

Three, the main features of Java

Java language is easy to learn.

The syntax of the Java language is very close to the C and C++ languages, making it easy for most programmers to learn and use Java.

The Java language is mandatory object-oriented.

The Java language provides primitives such as classes, interfaces and inheritance. For the sake of simplicity, it only supports single inheritance between classes, but supports multiple inheritance between interfaces, and supports the implementation mechanism between classes and interfaces (the keyword is implements) .

The Java language is distributed.

The Java language supports the development of Internet applications. There is a network application programming interface (java net) in the basic Java application programming interface, which provides a class library for network application programming, including URL, URLConnection, Socket, ServerSocket and so on. Java's RMI (Remote Method Activation) mechanism is also an important means of developing distributed applications.

Java language is robust.

Java's strong type mechanism, exception handling, and automatic garbage collection are important guarantees for the robustness of Java programs. Discarding pointers is a sensible choice for Java.

Java language is safe.

Java is usually used in the network environment, for this, Java provides a security mechanism to prevent malicious code attacks. Such as: safety precautions (class ClassLoader), such as assigning different namespaces to prevent replacement of local classes of the same name, byte code checking.

The Java language is architecture neutral.

Java programs (files suffixed with java) are compiled into an architecture-neutral bytecode format (files suffixed with class) on the Java platform, and can then be run on any system that implements the Java platform.

The Java language is interpreted.

As mentioned earlier, Java programs are compiled into bytecode format on the Java platform, which can then be run in the interpreter of any system that implements this Java platform.

Java is slightly more performant.

Compared with those interpreted high-level scripting languages, Java's performance is better.

The Java language natively supports multithreading.

In the Java language, a thread is a special object that must be created by the Thread class or its sub (grandchild) class.

Fourth, the environment to build the Java language

1. Download and install JDK

official website:

⭕ www.oracle.com click to download
⭕ java.sun.com
insert image description here

insert image description here insert image description here
Download according to your needs, how do you know if you are x86 or x64? insert image description here
Knowing this, you can go to download: insert image description here

Install JDK:

⭕ The installation path should not contain special symbols such as Chinese or spaces.
⭕ If the operating system is 64-bit, the software should try to support 64-bit (unless the software itself does not distinguish).
⭕ When prompted to install JRE, it is normally installed when JDK is installed, but in order to avoid errors when using development tools such as Eclipse, it is recommended to install JRE according to the prompt.
⭕ Java has a default installation location, but you can also specify it yourself. The author's jdk installation directory is in this location, remember to remember the installation directory!insert image description here

2. Configure the environment variable path:

⭕ Type javac on the dos command line, and an error message appears:
insert image description here

⭕ Cause of the error:
If the currently executed program does not exist in the current directory, the Windows system will search in the directory specified by an environment variable named path already in the system. If it is still not found, the above error message will appear. So enter the jdk installation path \bin directory, execute javac, you will see the javac parameter prompt information.
insert image description here

⭕ It is very troublesome to enter the bin directory every time the java tool is executed. Is it possible to execute java tools in any directory?
According to the principle that the windows system searches for executable programs, you can define the path where the java tool is located in the path environment variable, and let the system help us find the program to run and execute.

⭕ Configuration method:
(1) My Computer - Properties - Advanced System Settings - Environment Variables
(2) Edit the path environment variable, add the directory where the java tool is located at the beginning of the variable value, and separate it with " ; " and other values. That's it.
(3) Open the DOS command line and type javac in any directory. If the parameter information of javac appears, the configuration is successful.
insert image description here
Follow the step by step picture below:
Right-click this computer, and then click Properties
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

insert image description here insert image description here insert image description here
At this point, the configuration is complete!

3. Verify after configuring the path environment variable

Open the console

insert image description here

5. Development experience - HelloWorld

step:

  1. Write your Java code into a file with a .java extension.
  2. Compile the java file with the javac command .
  3. Run the generated class file through the java command .
    insert image description here

Step 1: Write

  1. Choose the easiest editor: Notepad.
  2. Type in the code, and save the file as Test.java, which is the file that stores the java code, called the source file.
class Test{
    
     
  public static void main(String[] args) {
    
    
   System.out.println(“Hello World!);
  }
}

Notice:
insert image description here

Step 2: Compile

  1. With the java source file, the compiler compiles it into a bytecode file that the JVM can recognize.
  2. In the source file directory, compile the Test.java file through the javac compilation tool.
  3. If there is no error in the program, there is no prompt, but a Test.class file will appear in the current directory, which is called a bytecode file, and is also an executable java program.
    insert image description here

Step 3: Run

  1. With executable java program (Test.class bytecode file)
  2. Execute the bytecode file by running the tool java.exe.

summary:

⭕ Java source files have the extension "java". The basic building block of a source file is a class, such as the HelloWorld class in this example.
⭕ The execution entry of a Java application is the main() method. It has a fixed writing format: public static void main(String[] args) {...}
⭕ The Java language is strictly case-sensitive.
⭕ A Java method consists of statements, each of which ends with ";".
⭕ The curly brackets are all in pairs and are indispensable.
⭕ There can only be at most one public class in a source file. The number of other classes is not limited. If the source file contains a publicclass, the file name must be named after the class name.

Six, Java basic knowledge diagram

insert image description here
Your three connections and attention are the motivation for me to publish articles with my heart!

Guess you like

Origin blog.csdn.net/weixin_52533007/article/details/123494047