Java Tutorial-Introduction to Java Language

Reference herein Hey passenger network Java Tutorial

Java tutorial

Java tutorial

To learn a computer language, we first need to understand the characteristics of the language, what is the language, and what can be done? Then understand the basic grammar and characteristics of the computer language.

Java features

Simplicity

The design of Java looks like C++ , but in order to make the language small and easy to be familiar with, the designers have removed all the features that need to be available in the C++ language. There are no pointers in Java. Java can automatically handle object references and indirect references, and realize automatic garbage collection. Regardless of storage management issues, users can spend more time and energy on research and development.

Object-oriented

Java is an object-oriented language. Makes the code call more clear, without the need to think about programming in the process.

Distribution

The Java language supports network communication, which allows multiple applications to be deployed separately and call each other.

Compilation and interpretation

The Java compiler produces byte-code instead of normal machine code. Java code cannot be run directly after being compiled, it is interpreted and run on the JVM .

Robustness

Java is a strongly typed language that allows extensions to check for potential type mismatches at compile time. It does not support pointers, eliminating the possibility of rewriting stored data. Exception handling is another characteristic of its robustness.

safety

Java's storage allocation model is one of its main methods to defend against malicious code. Java has no pointers, so programmers cannot directly manipulate the data in the memory.

portability

As long as it is an environment where jre is installed , you can run the corresponding Java program.

high performance

Java is a language that is compiled and then interpreted, so it is not as fast as a fully compiled language. But in some cases performance is very important. To support these situations, Java designers have created a "just-in-time" compiler that can translate Java bytecode into machine code for a specific CPU (central processing unit) at runtime. It is to achieve full compilation.

Multithreading

Java supports multi-threading. In some scenarios, a reasonable use of multi-threading will make the program processing faster.

Dynamic

The Java language is a dynamic language. As long as its class loading is in the correct format, it can be obtained through the network or in a file.

Java language tutorial

Object-oriented

The Java language is object-oriented, and it conforms to people's daily language habits. Object-oriented is actually relative to process-oriented. Process-oriented refers to the step-by-step execution according to the process of things. All operations will be a whole. As we know that C language is process-oriented.

Object-oriented is a way of understanding and abstracting the real world. It organizes related data and methods as a whole to look at it. Modeling the system from a higher level is closer to the natural operation mode of affairs. Object-oriented has three characteristics: encapsulation, inheritance, and polymorphism.

type of data

Data types Java language into basic data types and reference types. The basic data types booleanare: byte, char, short, int, long, , floatand doublethe eight data types.

The reference data type refers to the entity of the variable in a special way, and this mechanism is similar to the C++ pointer. Such variables will not allocate memory when they are declared, and additional memory space must be opened up. When declaring a variable of a reference type, there is a fixed format or fixed steps:

数据类型  变量名  =  new 数据类型();

Operator

Java program is composed of many statements, and basic operation of the unit statement is an expression with the operator . Operator is the mathematical operation symbol, such as +, -, *, /and the like.

Java provides many operators, these operations can handle not only general mathematical operations, but also logical operations and bit operations. According to the different roles used, operators can be divided into assignment operators, arithmetic operators, relational operators, logical operators, conditional operators, bracket operators, and so on.

Process control

Process control is a relatively important function in a programming language. It provides a basic means of controlling the operating steps of the programming language. It is mainly divided into if , if...else , for , while , do...while , switch these flow control statements.

Array

An array is a collection of fixed-length elements of a specific type. Their data types must be the same, and parameter types must be specified when declaring variables.

method

The smallest unit of program execution, which defines the execution process of the program.

abnormal

In the Java language, in addition to interrupting the execution of a method through return, the execution of the method can also be interrupted through the exception mechanism. It will cause unexpected situations and make the system unable to execute according to the original wishes, causing unnecessary losses.

During the running of the program code, exceptions will always exist, and they will occur in scenarios that you don't know, so we need to use exception control statements to handle the code and let the code logic execute in the direction we want.

Package and access permissions

The establishment of a package allows the same classes of functional modules to be stored together, making the project look clearer and easier to maintain in the later stage. The attributes or methods in each class, or the class itself, are all authorized. The delimitation of permissions makes the class more secure. Only the data or functions that it wants to display externally can be called, otherwise it cannot be called.

Thread

Java language, the thread is the smallest unit of program execution operations, is the most basic program is scheduled to run the unit. Reasonable use of multi-threading can make the execution of the program faster, higher performance, and better utilization of computer resources.

Generic

If you use a specific type of class can not be determined, you want to use in a variety of types of the above, we can use generics .

I

Java language to document the interaction between operations and network data, we have to use Java's IO technology. Through IO, the access and interaction between the system and these data is more convenient.

Java collection

The underlying data structure of the collection includes arrays, linked lists, trees, graphs, and so on. They encapsulate operations on arrays or linked lists, and provide a unified method for programmers, allowing programmers to quickly use these methods at low cost.

enumerate

Enumeration in the class and an interface based on a newly added type. It can exhaust the data that it already knows, and its function is to be normal if the data is in these exhaustion, and abnormal if it is not.

reflection

We can get an object through Class , and then through it we can access all the information in the accessed class, including properties, methods, and so on.

Operating database

Operating the database is a relatively common operation and the main operation in production programming. It stores the user's data in the database according to certain rules, and then retrieves it and displays it to the user. Operate the corresponding database system through the database driver provided by each database manufacturer.

The first Java program

Java program is used as a suffix .java, we create a Java program , and enter the following code:

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

First, we use the class keyword to define a HelloHaiCoder class. Then, in this class, we define a main function. In the main function, we use print to print Hello HaiCoder.

Run the program, the terminal will output Hello HaiCodera string.

Java tutorial summary

When learning the Java tutorial, we mainly need to understand object-oriented, data types, operators, flow control, arrays, methods, exceptions, packages and access permissions, threads, generics, IO, Java collections, enumeration, and reflection technologies.

Guess you like

Origin blog.csdn.net/weixin_41384860/article/details/107894100