【javaSE】Java for the first time

Table of contents

 what is java

A Brief History of Java Language Development

Get to know the main method of Java

run java program

The relationship between JDK, JRE, and JVM

Identifiers in Java


 what is java

Java is an excellent programming language with pleasing syntax and easy-to-understand semantics.

Not only that, Java is also a technical system formed by a series of computer software and specifications . This technical system provides a complete support environment for software development and cross-platform deployment, and is widely used in embedded systems, mobile terminals, enterprise servers, Various occasions such as mainframes.

A Brief History of Java Language Development

The Java language originated in April 1991, and the Green Project (Green Project) led by Dr. James Gosling of Sun Company started. ) program architecture running on it. This is the predecessor of Java: Oak (named after an oak tree outside the office of Java founder James Gosling), but because the market demand for these smart home appliances was not as high as expected, Sun gave up the plan. With the development of the Internet in 1995, Sun saw the prospect of Oak's application on the Internet, so it transformed Oak and officially released it under the name of Java in May 1995, and put forward the slogan "Write once, Run anywhere".

Get to know the main method of Java

public class HelloWorld{
    public static void main(String[] args){
        System.out.println("Hello,world");
    }
}

Through the above code, we can see the structure of a complete Java program, which consists of the following three parts:

1. Source file (extension *.java): The source file contains the definition of the class. A class is used to represent a component of a program, and a small program may only have one class. The contents of the class must be enclosed in curly braces.

2. Class: A class has one or more methods. Methods must be declared inside the class.

3. Method: Write the statement that the method should execute in the curly braces of the method.

To sum up: classes exist in source files; methods exist in classes; statements exist in methods.

Note: There can only be one public-modified class in a source file, and the name of the source file must be the same as the name of the public-modified class.

run java program

Java is a semi-compiled, semi-interpreted language. The source file is first compiled by the javac compiler program, and the .class file generated after compilation is a platform-independent and JVM-oriented file composed of bytecodes. Finally, start the java virtual machine to run the .class file. At this time, the JVM will convert the bytecode into a form that the platform can understand to run

 

1. Use Notepad or IDEA (Integrated Development Environment) to write the Java source program
2. Use the javac.exe compiler to compile the Java source program to generate a bytecode file of xxx.class Syntax format: javac xxx.java 3. Use java to run xxx.class bytecode file syntax format: java xxx

 

Note: Before running the Java program, you must first install the JDK (Java Development Kit, Java Development Kit). The JDK contains javac and java tools. The Java program is finally run in the JVM (Java Virtual Machine).

The relationship between JDK, JRE, and JVM

[Interview questions] The relationship between JDK, JRE, and JVM?

  • JDK (Java Development Kit): Java development kit, provided for Java programmers, including JRE, compiler javac and built-in debugging tools Jconsole, jstack, etc.
  • JRE (Java Runtime Environment): Java runtime environment, including JVM, Java basic class library. It is the required environment for programs written in the Java language to run.
  • JVM : Java virtual machine, running Java code

Identifiers in Java

Identifier: The name given by the user to a class name, method name, or variable in a program.

[hard rules]

Identifiers can contain: letters , numbers , underscores and $ symbols, etc. Note: Identifiers cannot start with a number , nor can they be keywords , and are strictly case-sensitive

【soft suggestion】

Class name: the first letter of each word is capitalized (big camel case)

Method name: the first letter is lowercase, and the first letter of each subsequent word is uppercase (small hump)

Variable names: Same rules as method names

Which of the following identifiers are legal?

 The correct answer is: BCEF

Note: main can be used as an identifier in java, but it is not recommended.

Guess you like

Origin blog.csdn.net/m0_73648729/article/details/131909565