Before starting the Java basic syntax, explain the basic specifications of the Java program:
- Case sensitive, such as person and person are different
- The first letter of the class name is capitalized, and if the class name consists of multiple words, the first letter of each word is capitalized, for example HelloWorld
- Method names should follow the hump naming method, beginning with a lowercase letter, if it contains multiple single, followed by a single capitalization, such as Findminnumber
- The source file name must be the same as the class name
- Java program starts execution by public static void main (string [] args) method
Java identifiers, such as class name, variable name, method name
- All representations are (A-Z) or (A-Z) or ($) or (_) Start
- The first character is followed by a (A-Z) or (A-Z) or ($) or (_) or (any number) combination
- Keyword cannot be used as an identifier
- Identifier Case sensitive
- Examples of legal identifiers: Age, $salary, _value
- Examples of illegal identifiers: 2twice,-salary
Java modifiers, modifying methods and properties in a class
- Access control modifier: default,public,protected,private
- Non-access control modifier: FINAL,ABSTRACT,STRICTFP
Java variables
- class variables
- Member variables
- Local variables
Java arrays
An array of objects on the heap that can hold multiple variables of the same type, named Specification byte[] Buffer
Java Enumeration
Enumerations can only be pre-set values.
class HelloWorld { public static void main(String[] args) { FreshJuice juice = new FreshJuice(); juice.size = FreshJuice.FreshJuiceSize.MEDIUM; }}class FreshJuice { enum FreshJuiceSize { SMALL, MEDIUM, LARGE } FreshJuiceSize size;}
Java keywords, keywords are lowercase access control
Class, method, and variable modifiers
- Abstract
- Class
- Extends
- Final
- Implements
- Interface
- Native
- New
- Static
- Strictfp
- Synchronized
- Transient
- Volatile
Program Control statements
- Break
- Continue
- Do
- While
- For
- If
- Else
- instanceof
- Return
- Switch
- Default
- Case
Error handling
- Assert
- Catch
- Finally
- Throw
- Throws
- Try
Package related
Basic type
- Boolean
- Byte
- Char
- Double
- Float
- Int
- Long
- Short
- Null
Variable reference
Reserved keywords
Java Basic Syntax