Getting Started with Java-object-oriented
- The difference between the public class and class declaration classes:
- public class Life: The file name must be the same as the class name
- The file name and class name can be inconsistent when the class declaration
- A file can have multiple class-defined classes, but only a class that is defined by a public class
- Recommendations for writing identifiers
- Do not use too many symbols, preferably starting with letters
- can have uppercase and lowercase letters, underscores, numbers, $
- Cannot start with a number
- Data types are classified as "base data type", "Reference data Type"
-
- Basic
| Integer type |
Byte |
Short |
int long |
| Floating-point types |
Float |
Double |
| Character type |
Char |
| Boolean type |
Boolean |
- Reference
| Class |
Class |
| Interface |
Interface |
| Array |
- Overflow of data
Public classDateDemo02 {/** * @paramargs*/ Public Static voidMain (string[] args) {//TODO auto-generated Method Stub intmax=Integer.max_value; System.out.println (The maximum value for int is: "+max); System.out.println ("The maximum value of int +1 is:" + (max+1)); System.out.println ("The maximum value of int +2 is:" + (max+2)); System.out.println ("The maximum value of int +3 is:" + (max+3)); }}The results of the operation are as follows:
The maximum value of int is: The maximum value of 2147483647int +1 is:The maximum value of -2147483648int +2 is: -2147483647int the maximum value of +3 is:- 2147483646
Will cause data errors, but the program will not error.
You can use forced type conversions to prevent data overflow:
Public classDateDemo02 {/** * @paramargs*/ Public Static voidMain (string[] args) {//TODO auto-generated Method Stub intmax=Integer.max_value; System.out.println (The maximum value for int is: "+max); System.out.println ("The maximum value of int +1 is:" + (max+1l)); System.out.println ("The maximum value of int +2 is:" + ((Long) max+2)); }}
The results are as follows:
The maximum value of int is: The maximum value of 2147483647int +1 is:The maximum value of 2147483648 int +2 is: 2147483649
Getting Started with Java-object-oriented basics