[JavaSE] Getting to know the Java language

I hope to communicate and learn from each other through the blog. If there are any mistakes, please correct me in the comment area.

content

Getting to know the Java language

1. What is Java

programming environment

What is JRE

writing tool

Why is Java so popular

2. The first Java program

code above

Notice

About the main method

run the code

 JDK, JRE, JVM difference

Why Java can be cross-platform


Getting to know the Java language

1. What is Java

The Java language originated from the Oak project led by James Gosling of Sun Corporation in 1991. In 1995, Sun Corporation officially named it Java and put forward the slogan of "Write once, Run anywhere".

Java is an object-oriented programming language. It not only absorbs various advantages of C++ language, but also abandons the incomprehensible concepts of multiple inheritance and pointers in C++. Therefore, Java language has two characteristics of powerful functions and simplicity and ease of use. As a representative of static object-oriented programming language, Java language perfectly implements object-oriented theory, allowing programmers to perform complex programming in an elegant way of thinking.

Java has the characteristics of simplicity, object orientation, distribution, robustness, security, platform independence and portability, multithreading, and dynamism . Java can write desktop applications, web applications, distributed systems and embedded system applications

programming environment

JDK (Java Development Kit) Java development kit is a program development environment for writing Java applet programs and applications. JDK is the core of the entire Java, including the Java Runtime Environment (Java Runtime Environment) , some Java tools and Java's core class library (Java API) .

What is JRE

JRE (Java Runtime Environment) is a runtime environment, and JDK is a development environment. Therefore, JDK is required when writing Java programs, and JRE is required when running Java programs. The JDK already contains the JRE, so as long as the JDK is installed, you can edit Java programs and run Java programs normally. However, since JDK contains a lot of content unrelated to operation, it takes up a lot of space. Therefore, it is not necessary to install JDK to run ordinary Java programs, but only need to install JRE.

writing tool

At present, the mainstream Java writing tools mainly include the following:

Eclipse : An open source, Java-based extensible development platform.

NetBeans : An open source Java integrated development environment for a variety of client and Web applications.

IntelliJ IDEA : It has good functions in code automatic prompting, code analysis, etc.

MyEclipse : A commercial software developed by Genuitec , which is a widely used Java application integrated development environment.

EditPlus : If the Java compiler " Javac " and the interpreter "Java" are configured correctly, you can directly use EditPlus to compile and execute Java programs.

Among the above writing tools, IntelliJ IDEA is more recommended. This tool feels more convenient to use and more friendly to beginners.

Why is Java so popular

1. First of all, please look at the ranking of Java in the TIOBE programming language rankings in recent years

2. Let's look at a set of official Java data

  • 97% of enterprise desktops run Java

  • 89% of desktops (or computers) in the US run Java

  • 9 million Java developers worldwide

  • The number one choice for developers

  • #1 Deployment Platform

  • 3 billion mobile phones run Java

  • 100% of Blu-ray Disc players come with Java

  • 5 billion Java Cards in use

  • Java ME is available from the top 5 OEMs

  • 125 million TV devices run Java

3. The advantages of the Java language

The syntax is relatively simple, and developers who have learned computer programming can quickly get started

It has strong competitiveness in several fields, such as server-side programming, high-performance network programs, enterprise software transaction processing, distributed computing, Android mobile terminal application development, etc.

Therefore, Java is not just a programming language, it is a comprehensive technical system and a specification of object-oriented thinking.

2. The first Java program

code above

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

First of all, HelloWorld in the first line is called the class name

Notice

  1. There can only be one public class in a Java file

  2. The class name needs to be the same as the file name

  3. Programming specification: the left parenthesis immediately follows the current line, and the class name adopts the big camel case method

  4. One class corresponds to one bytecode file

System.out.println() This is equivalent to printf in C language, it will print the contents in parentheses and wrap

About the main method

  1. public static must have

  2. The return value type of the main method is void (no return value)

  3. The part inside the curly braces of the main method is called the method body

Summary: classes exist in source files; methods exist in classes; statements exist in methods

run the code

The above code I wrote in Notepad (the file is placed on the desktop), now if we don't have IDEA, how to run it?

Let's take a look at the experience of Java source files

 Here you need to use some JDK commands

First we open cmd, enter the file path where the current HelloWorld.java is located, type javac HelloWorld.java, press Enter, you will find that there is a java.class file on the desktop, which is the bytecode file generated after compilation (binary file), then type java HelloWorld, the result will be printed, as shown below

 

 JDK, JRE, JVM difference

After the HelloWorld.class file is generated, how does the .class file run?

There is a thing called JVM , it will .classload the file into the JVM (Java Virtual Machine Java Virtual Machine) to run

JDK: Java Development Kit

JRE: Java Runtime Environment

JDK: Java Virtual Machine

The relationship between the three is shown in the following figure:

JDK includes JRE, and JRE includes JVM. JVM is equivalent to virtualizing a computer. All bytecode files must be loaded into the virtual machine to run, and the virtual machine is included in the JDK.

Why Java can be cross-platform

JDK is upwardly compatible. If JDK1.8 is used, then the code written on JDK1.8 can also run on other machines, even on different operating systems. Java programs run on On the JVM, the so-called "Write once, Run anywhere".

Why does one class correspond to one bytecode file

First we can look at the following code

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

use the following command

javac HelloWorld.java

After compiling the above code, you will find that two bytecode files are generated

This is for the convenience of use, which class is used to load which class, and the corresponding bytecode file will be loaded if the HelloWorld class is needed.

Note : If a class is public, the class name of the class must be the same as the file name, and there can only be one public class in a Java file

Welcome everyone to pay attention! ! !

Learn to communicate together! ! !

Let's get programming to the end! ! !

--------------It's not easy to organize, please support three consecutive ------------------

Guess you like

Origin blog.csdn.net/weixin_46531416/article/details/121988237