1 Public classJavase {2 3 Public Static voidMain (string[] args) {4 /*5 * JDK JRE JVM6 * Notes7 * Identifiers: Naming variables, classes, methods8 * The first character can only be preceded by a letter, an underscore, a $9 * Other parts can be any combination of letters, underscores "_", $, numbersTen * Case-sensitive and unlimited length One * Can not be Java keyword A * Can be in Chinese - * - * The Unicode character set is used inside Java (2 bytes for one character), Universal the * 8 Basic types: (numeric) byte, int, short, long, (char) char, (floating-point) double, float, (Boolean) Boolean - * Numeric Type: Byte (1 bytes -128~127), short (2 bytes -2^15~2^15-1 -32768~32767) - * INT (4 bytes -2^31~2^31-1), Long (8 bytes -2^63~2^63-1) - * int a1 = 10; (decimal) int a2 = 010; (octal) int a3 = OXF; (hex) + * 10--and II: integer.tobinarystring (A1); - * 10--Eight: integer.tooctalstring (A1); + * 10--16: integer.tohexstring (A1); A * byte a4 = 10;short A5 = 100;long A6 = +; at * If the size of the data does not exceed the Byte/short/long's stated range, it can be automatically transformed - * long a7 = 1000L; - * Floating point number: double (default), float - * Double d = 3.14; float = 0.1f; - * Float (4 bytes): -3.403e38~3.403e38 - * Double (8 bytes): -1.798e308~1.798e308 in * Usage Summary: There are rounding errors in floating-point numbers, many of which cannot be represented accurately. - * Because of the infinite number of decimals, we can not use a finite number to express infinite numbers, only as accurate as possible. to * If you need an exact numeric calculation that does not produce rounding errors, you need to use the BigDecimal + * Character type: char (2 bytes 0~2^16 (65536)) char type used to represent characters in Unicode encoded table - * Unicode encoding is designed to handle all text in a variety of languages, it accounts for 2 bytes and can allow 65,536 characters the * Unicode has encodings from 0 to 65535, they are usually represented by a hexadecimal value from ' \u0000 ' to ' \uffff ' (the prefix is u for Unicode) * * ASCII code occupies 1 bytes and can be 128 characters, which is the first 128 characters in the Unicode encoding table. $ * Char is calculated directly as an integer in the 0~65535 range. Panax Notoginseng * can convert integers between 0~65535 directly to Char - * Escape characters: \ t, \ n, \ r, \ \, \b, \ ', \ ' the * Boolean Type: Boolean (1 bits, not 1 bytes, one byte has 8 bits, only two values are true and false) + * A * Automatic type conversion and forced type conversion the * Automatic type conversion rules: (1) Byte-->short-->int-->long + * (2) No data loss: Char-->int float, int-->double - * (3) Possible loss of precision: long-->float, double int-->float $ */ $ - //print A-Z - Charc = ' a '; the for(inti = 0; I < 26; i++) { - Chartemp = (Char) (C +i);Wuyi System.out.print (temp); the } - Wu //Test Cast - intA =-100; About CharB = (Char) A; $System.out.println (b);//?, there are meaningless numbers -System.out.println ("---------------------"); - - //type-promotion issues in expressions A intI1 = 3; + LongLo = 4; the DoubleDou = 5.3; - //do all two-dollar operators (+-*/% will have type elevation issues) $ intI2 = (int) (lo+dou); the floatF1 = (float) (i1+lo); the the intMoney = 1000000000;//1 billion the intyears = 20; - //Long total = (long) (money*years);//returns a negative number that exceeds the range of values that is represented by the type conversion first in LongTotal = (Long) Money *years; the System.out.println (total); theSystem.out.println ("---------------------"); About the //How many times does a man have a 70 heartbeat? the Longtimes = 70l*60*24*366*70*60;//It is best to put the long type at the front, in case the preceding number multiplies easily. the System.out.println (times); + - //JDK7 new features: Underscore delimiter the inti3 = 0b0000_0000_0000_0011;//3, if there is no 0b, it is the octal number 9Bayi inti4 = 1_1234_1234;//112341234 the System.out.println (i3); the System.out.println (I4); - - //The Java language supports the following operators: the /*arithmetic operators: + 、-、 *,/,%, + + 、--、 the * Assignment Operator: = the * Relational operators:>, <, >=, <=, = =,! =, instanceof the * logical operators:&&, | |,! - * Bitwise operators:&, |, ^, ~, >>, <<, >>> the * conditional operator:?: the * Extended assignment operator: + =,-=, *=,/= the */94 the //Debug Debugging the /** the * Control Statements: Order, select, Loop98 * If statement, If/else statement, Switch/case/default statement About * JDK1.7 new feature: Switch case: "string" can be written - */101 DoubleD =math.random ();102 intE = 1 + (int) (D*6);//cast number result take integer part103 System.out.println (e);104 if(E > 3) { theSystem.out.println ("Elephant! ");106}Else {107System.out.println ("Lili");108 }109 } the}
Review notes for my Java Knowledge review