Java SE review _1 Basic formats and operators for Java

Source: Internet
Author: User
Tags case statement java se

. Represents the current directory. Classpath can access the class file under any path. Single-line comments can be nested, multiline comments cannot be nested in Java identifiers can only have numbers, letters, $ and _, the other symbols are wrong, Illegal. The number cannot be the beginning. The shortcut opens the Command window. Hold down SHIFT and right-click here to open the Command window. Cross-platform principle: Just install a Java Virtual machine (JVM Java VM) on the operating system that needs to run the Java application. The JVM is responsible for the operation of the Java program in the system.character constants: "Single quotes must be placed in a single number (0~9), 10 for 2 characters." Do not put the character also can not.The inside of the computer is stored in the form of source code, and is operated in the form of a complement in operation. In Java, other data types except char and Boolean are taken from negative numbers to positive numbers, such as int-2^31~2^31 byte:-128~127 char, which accounts for two bytes: 0~ 65535,boolean not explicitly specified size. (Sun Official document), float accounts for four bytes, and double accounts for 8 bytes.The >>> operator fills the high position with 0, and >> fills the high point with the sign bit. The parameter to the right of the shift operator needs to be modulo 32 for the operation of the shift operator for integers. For example: 1<<35 and 1< <3 and 8 are the same.The integer default type is type int and therefore cannot be used directly with a long x=999999999, which displays a data type error (out of range). It takes a long x=9999999999l to be able to. Identify the best plus L.the default type for decimals is the double type. so if float f=1.32; the display may lose precision. Need to identify float f=3.12f;outputting An integer divided by 0 will give an error ArithmeticException exception. However, by dividing the floating-point number by 0, the exception is not reported, resulting in Nan or infinity.byte b=2; does not appear to be the same as the float/double error, because the integer type (constants are determined at compile time.) But if it is a variable, it is a different thing (short). such as: Byte B=3+4; Compile time has been determined, will not error. Direct numeric additions are converted directly to Byte. Attention!! float is different. BYTE b1=3; BYTE b2=4;          B=B1+B2; Error, the addition of two byte variables will be converted directly to the Int.java compiler has a constant optimization mechanism. In addition: int x=32;byte b=32;b=b+x;     System.out.println (b); Compile error. This is because the b+x is converted to int bytes. An error occurs when converting to byte. A small data type is made up of large data types when it is operated on a large data type. Byte b=1;b+=1;//compiles through, hides a type of conversion, b++ the same, There will be no error. Instead of b=b+1, the int type is converted to a byte type, and an error is given (can not convert from int to byte) byte b= (byte) 129; a negative number is obtained. Because of truncation. and Byte b= (byte) 300; will not get negative numbers because 300>256, so the highest bit is 0 float f=123l; The compilation was successful because float is larger than long. So the upside is not right. Float is stored using the ieee754 format. With only 24 bits of precision, the distance between two floats can be large.
For a simple example, the two numbers are the same for 2000000000 and 2000000050 in float. Integers are precisely represented.     The 0 bits represent the sign bit, 8 bits represent the digits, and 23 bits represent the trailing digits. System.out.println (' a ' + 1); Output 98. Because in the conversion to int System.out.println ("Hello" + ' a ' + 1)//Output HELLOA1 System.out.println (' A ' +1+ "hello")// Output 98hello System.out.println ((float) (10/3))//Output 3.0, because 10/3 has been calculated beforehandwhen two values are added to the operation, the two operands are converted to the same type before the calculation.
    • If one of the two operands is of type double, the other operand is converted to a double type.
    • Otherwise, if one is a float type, the other operand is converted to the float type.
    • Otherwise, if one is a long type, the other operand will be converted to a long type.
    • Otherwise, the two operands are converted to the int type (end point).
The Math.Round method method represents a rounding operation that takes the nearest integer to a floating-point number. If the argument is a double type, returns a long. If the parameter is a float type, returns the Int. common right-to-left operator: +=,-=,*=,/=,=. For such operators, a right-to-left calculation is performed. A+=b+=c is equivalent to a+= (b+=c). Xor ^: The same on both sides is false on both sides is the true,&& is short-circuiting, while the single and also have the function of the bitwise operator. The difference between the IF statement and the ternary operator, a? B:c; B and C of the ternary operator must have a definite result, because the ternary operator is an operator and has a definite result.if (x<2)int z=3;//error. because int z=3; in fact, it is a two statement.switch (expression) {Case statement: statement 1; break;} The expression in the switch bracket Byte,short,char,int the enumeration (JSE 1.5), the string (JSE 1.7). If the case succeeds, the subsequent statements are not judged. Default: Even if placed in any position, it is the last to execute.         
int x =4;           Switch (x)          {               case 1:system.out.println ("a");                  Case 2:system.out.println ("C");                                       case 3:system.out.println ("B");                default: System.out.println ("D");                                 }

The output is now D. When default is on the last side, no break can end normally. When default is at the top, the default is executed and continues downward. Until you encounter a break or curly brace case 1:case 2:case 3: statement; possible. Break can be tagged with:            
U:              for int x=0; x<=4; x + +) {                 forint y=0; y<=3; y++) {                      if(y==2)                              Break U;                     " x= "+ x+", y= "+ y);                }           }

The actual tag with break can be used in the IF statement to jump out of the IF statement block. There is also a tagged continue statement, which acts as a break approximation. Static import: Imports a class to use static methods or static variables in the class, such as import static java.lang.math.*;UTF-8 A Chinese three byte, GBK code table one Chinese two bytes.

Java SE review _1 Basic formats and operators for Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.