The article directories

  • Overview of the Java language
    • 1. What is Java
    • 2. Popularity of Java
    • 3. The features of Java
    • (1) Simplicity
    • (2) Object oriented
    • (3) Distributed (microservices)
    • (4) Robustness
    • (5) Security
    • (6) Portability
    • (7) Explanatory type
    • (8) High performance
    • (9) Multi-threading
    • (10) Dynamic
  • Second, the history of Java
  • Java development environment installation
    • The first step is installing the JDK
    • Step 2 IDEA installation procedure
  • 4. Run Java programs
  • 5. Analyze basic Java syntax from Hello World
  • 6. Write Java code using IDEA
    • Create a project
  • Seven, Java learning details
    • 1. Java annotations
    • 2. String concatenation
    • 3. In Java int
  • To be continued…….

Overview of the Java language

\

The outline of the content is as follows

1. What is Java

\

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

In addition, Java is a technical system formed by a series of computer software and specifications. This technical system provides a complete supporting environment for software development and cross-platform deployment, and is widely used in embedded systems, mobile terminals, enterprise servers, mainframes and other occasions.

\

To get a sense of how popular Java is, let’s take a look at a set of data from Java officials

\



\

2. Popularity of Java

\

In the list of major programming languages, Java language has been ranked in the forefront, is a very mainstream computer language.

\

Below is a list of recent computer languages

\



Java still dominates the world’s computer languages.

\

3. The features of Java

\

(Just for understanding, we will gradually feel in the later study)

\

(1) Simplicity

Java syntax is a “clean version” of C++ syntax. There are no headers, pointer operations (or even pointer syntax), structures, unions, operator overloading, virtual base classes, and so on. Not only that, the Java development environment is far beyond that of most other programming languages.

\

(2) Object oriented

What is object orientation? Let’s use the analogy of a carpenter. An “object-oriented” carpenter is always focused on the chair he makes, and the tool he uses comes second. A “non-object-oriented” carpenter, on the other hand, thinks first of the tools he uses.

In the Java world, everything is an object.

Java’s object-oriented features are on par with C++, but the main difference is multiple inheritance. In Java, the simpler concept of interfaces has taken its place. And Java offers much richer run-time introspection than C++.

\

(3) Distributed (microservices)

Java has a rich library of routines for handling TCP/IP protocols such as HTTP and FTP. Java applications can open and access objects on the network through urls as easily as they can access local files.

\

(4) Robustness

The biggest difference between Java and C++ is that Java’s pointer model eliminates the possibility of overwriting memory and corrupting data (a feature that will be appreciated by anyone who has spent hours checking for memory collisions due to pointer bugs). Not only that, but the Java compiler can detect many problems that other languages can only detect at run time.

\

(5) Security

Java is suitable for network/distributed environments. In order to achieve this goal, a great deal of effort has been put into security. Use Java to build antivirus, tamper-proof systems.

(6) Portability

Unlike C/C++, there is no “implementation dependency” in the Java specification. The size of the base data type and related operations are specified. For example, an int in Java is always a 32-bit integer, whereas in C/C++ an int may be a 16-bit integer, a 32-bit integer, or any other size specified by the compiler provider. In Java, data types have a fixed size, which eliminates a major headache when porting code.

\

(7) Explanatory type

The Java interpreter can execute Java bytecode on any machine that has ported the interpreter. Because linking is an incremental and lightweight process. So the development process has become faster and more exploratory.

\

(8) High performance

Although the interpreted bytecode performance is satisfactory, there are situations where more efficient performance may be required. Bytecode can be translated dynamically (at run time) to the machine code corresponding to the particular CPU running the application.

\

(9) Multi-threading

Java was ahead of its time. It was the first major language to support concurrent programming. Multithreading leads to better interactive responses and real-time behavior. Concurrent programming is never easy, but Java does a great job of managing it.

\

(10) Dynamic

Java is much more dynamic than C/C++. It can adapt to the evolving environment. New methods and instance variables can be added freely to the library without any impact on the client. Finding run-time type information in Java is simple (reflection’s nature, learned later)

\

Second, the history of Java

Here we briefly introduce that Java language originated from the Oak project led by James Gosling of Sun Company in 1991. In 1995, Sun Company officially named Java and proposed “Write once, Run anywhere”.

\

The founder of Java

James Gottling



The origin of Java naming

\

Gosling enjoyed coffee as a pick-me-up while writing computer programs. So when he named Java, he thought of something related to coffee — Java is rich in coffee, so named Java, we can observe the official icon of Java, is a cup of hot coffee.

\

\

Java development environment installation

\

The first step is installing the JDK

\

Install JDK, blog version:

www.cnblogs.com/gaobo123/ar…

\

Install JDK, video tutorial version:

www.bilibili.com/video/BV1N5…

\

1. Variable name: JAVA_HOME

Variable value: The value is the JDK installation directory

\

2. Variable name: Path

Variable value: C: Program Files\Java\jdk1.8.0_131\bin

\

3. Configure CLASSPATH

Variable name: CLASSPATH

Variable value:. %JAVA_HOME%\lib\dt.jar; %JAVA_HOME%\lib\tools.jar

Notice that the dot must not be omitted


\

Step 2 IDEA installation procedure

\

www.bilibili.com/video/BV1HA…

Here we explain the concepts of what the JDK is and what the IDEA runtime environment is.

\





4. Run Java programs

\

We first do not use IDEA Java code editor, first use notepad to write code, try to run the Java code program

\

Create a file in a folder, create a Text file, change the suffix to.java, then open it with Notepad ++ or Sublime Text, and write out the Java language Hello World code.

\



\

Press Ctrl + S, save the code, and the Java file is written to disk. The Java code is just a bunch of strings written to disk, so how do we run it?

\

Win +R Open the run box and enter CMD to open the command line.

\



It now prints Hello World! String, running Java code successfully.

In this process, the compilation process is as follows:



\

Bytecode files store binary numbers of information about class classes in Java files, and the bytecode files continue to run on the JVM.

\

5. Analyze basic Java syntax from Hello World

\



So if we write a public class in Java Notepad

\

The Javac + file name is as follows:

\

\

What does this compilation error mean?



When we remove public from the Java file before test

\



Compile again

\



A Test class is generated in the folder. What does that mean?



Notes for Writing:







Add public static to main

\

Functions are called methods in Java, and methods are written in much the same way as in C, as shown above, except that the return value is preceded by an access modifier qualifier.

\

Access restriction modifiers are briefly discussed here



What is this?

Equivalent to the array int arr in C []

This can be written as int []

What is this?

Printf (” % d \ n “, 10);

\

6. Write Java code using IDEA

\

How to use IDEA? \

Create a project











\

Finally we write the code in the corresponding edit area.

\

How does the code you write work?

\



\

PSVM is the main key and sout is printf{” \n “,}.

\

Seven, Java learning details

\

1. Java annotations

2. String concatenation

\

public class Test {

    public static void main(String[] args) {
        int a=10;
        System.out.println(a);  / / comment line

        int b=20;
        System.out.println(b);

        System.out.println("a:"+a+" b:"+b); }}Copy the code

\

What is the output result?



Description:

\

(1). String concatenation of any variable will become a string, where the + means concatenation

\

So in this code, does a plus b compute?

  System.out.println("a:"+a+b);
Copy the code

Code display effect:



There is no addition, as long as there is a string in front of it, there is no operation behind the +, just the meaning of concatenation.

So in this code, what results are displayed?

  System.out.println(a+b+"hehe");
Copy the code

Compile result:

Description: \

(2) If the string is not preceded by the first occurrence, then the operation is performed first

\

3. In Java int

\

In C, ints account for 2 bytes on 16-bit platforms, 4 bytes on 32-bit platforms, and 8 bytes on 64-bit platforms.

\

However, in Java, int is 4 bytes!! There is no such thing as a multi-bit platform, this is called Java portability!!

\

Portability: Java code can run on any bit platform!!

Cross-platform \

It means that code written on Windows can run on a Mac. Why? Because Java code runs on the virtual machine (JVM) -> JDK.

\

5. The range that int can represent in Java

\

In C, there are signed and unsigned numbers, but remember, there is no such thing as unsigned numbers in Java!!

Int binary representation:



So the range of int is zero







\

Thank you for your appreciation and attention!! \

To be continued…