Basic syntax for Java 1. Key Concepts
A Java program can be thought of as a collection of objects, and these objects work together by invoking each other's methods;
- Class: A class is a template. Describing the behavior and methods of a class of objects is an abstraction of a class of objects;
- Object: An object is an instance of a class that has state and behavior, such as a dog is an object whose state is: color, name, variety, behavior: to call, to walk, to eat;
2. Helloword instances
// 文件名:HelloWord.java// 结果输出:Hello!public class HelloWord { public static void main( String[]args){ System.out.println("Hello !") }}
- The Java program file suffix is named
.java ;
- Java programs need to be compiled after
.class the file is generated before it can be run;
- Java is case sensitive;
- All Java programs are executed by the public static void Main (String[]args) method;
3. Java modifier:
Like other languages, Java can use modifier classes to decorate methods and properties in a class, mainly with two types of modifiers:
- Access control modifiers:
default ,, public protected ,private
- Non-access control modifiers:
final , abstract ,strictfp
4. Java variables:
Java variables are divided into the following 3 categories:
- Local variables: Variables defined in methods, construction methods, statement blocks, variable fame and initialization are all in the method, and automatically destroyed when the method is finished;
- class variables (static variables): Fame in the class, outside the method body, but must be static type;
- Member variables (non-static variables): In the class, outside the method body, when the object is created, it can be accessed by methods, construction methods and specific statements in the class;
5. Inheritance
A class in Java can be derived from another class, and the newly created class can be inherited by a class that has the required properties or methods.
With inherited methods, you can reuse methods and properties of existing classes without rewriting them; Inherited classes are called superclass (Super Class), and derived classes are called subclasses (subclass)
6. Interface
Interfaces can be understood as protocols that communicate with each other, and interfaces specify the methods to be used for derivation, but the concrete implementation of the method depends on the derived class;
7 basic data types in Java 8 types
- ① Boolean type:
boolean ,
- ② character type (single byte):
byte ,
- ③ character type (2 bytes)
char ,
- ④ Short-integer (2 bytes)
short ,
- ⑤ integral Type (4 bytes):
int ,
- ⑥ floating-point type (4 bytes):
float ,
- ⑦ Long Integer (8 bytes):
long ,
- ⑧ Double Precision (8 bytes):
double ,
Wait and see Java-02: Basic grammar