Java syntax basics 1. java syntax Basics
JavaSyntax 1
All program code in Java must exist in a class. class is defined using the class keyword. Some modifiers can be provided before the class. The format is as follows:
Modifier class Name
{
Program code
}
Note: 1. Java is strictCase Sensitive.
2. A continuous string in a Java program cannot be written in two separate rows.
There are three types of annotations in Java:
1. Single line comment
Add "//" to the comment in the format:
Code; // comment content
2. Multi-line comment
It starts with a slash and ends with a star plus a slash.
3. document comments
Start with a slash and add two asterisks. end with an asterisk and a slash.
The content annotated with this method is interpreted as a formal document of the program and can be included in a document generated by a tool program such as javadoc to describe the hierarchy of the program and its method.
The names of packages, classes, methods, parameters, and variables in Java can be composed of uppercase/lowercase letters, numbers, underscores (_), and dollar signs ($) in any order, it cannot start with a number or be a reserved keyword in Java.
Note: We recommend that you use the hump type when writing the names of packages, classes, methods, parameters, and variables in Java. For example, HelloWorld
1. Declaration for classes and interfaces: class, extends, implements, interface
2. package introduction and package Declaration: import and package
3. Data Types: byte, boolean, char, double, int, long, float, short
4. Literal values of some data types: flase, ture, null
5. Process Control: break, case, continue, default, do, else, for, if, return, switch, while
6. Exception Handling: catch, finally, throw, throws, and try
7. modifiers: abstract, final, native, private, protected, public, static, synchronilzed, transient, volatitle
8. OPERATOR: instanceof
9. Create an object: new
10. Reference: this, supper
11. Method return type: void
12. Reserved Words: const, goto
1. There is no relation between the underlying operating system or platform of the basic data type language of Java, and the numeric values are signed
A positive number can also be stored as a negative number. The char type is 16 bits and has no symbols. The boolean type can only contain
True and false.
2. All literal values of an integer are of the int type by default. To use the long type, you must add L or l at the end of the string,
Float literal values are of the double type by default. If float type is used, F or f must be added at the end of the float.
3. The reference does not contain the actual data of the object it refers to, but points to the location of the object in memory.
Contains actual data. In java, references either point to an object or to null. This is exactly what java
One of the security features: programmers are not allowed to access the memory directly.
Common escape characters include:
\ R -- accept keyboard input, which is equivalent to pressing the Enter key
\ N -- indicates line feed
\ T -- indicates a Tab, which is equivalent to a Tab key.
\ B -- indicates the backspace key, which is equivalent to the Back Space key.
\ '-- Single quotes
\ "-- Double quotation marks
\ -- Indicates the Backslash "\"