Chapter III Java Fundamentals (ii)one, escape character
The escape character is "\", which can represent some special characters by escaping the character.
For example:
' \ n ' means carriage return
' \ t ' represents a tab character, a tab indicates a 8-10-character jump to the right
' \ \ ' means \
' \ ' denotes single quotation marks
' \ ' means double quotation marks
"\u4e2d" denotes the character (Kanji: medium) of the Unicode encoding.
Ii. Concept and usage of Boolean types
The Boolean type is used to indicate either affirmative or negative.
Boolean is commonly used in branch statements, circular statements.
True: indicates positive meaning;
false: denotes negative meaning;
Definition of Boolean variable: E.g:boolean ispass;
Initialization of a Boolean variable: Eg:boolean Ispass = true; ispass=59>=60;
three, small type to large type conversion
1, small type to large type of conversion will be done automatically, that is, the programmer does not need to write additional code, the JVM is responsible.
Tip: Automatic type conversions are also called "Hermit type conversions."
2, Automatic conversion rules: The sign bit will automatically expand, negative 1, positive 0.
3. Automatic type conversion consists of the following:
4, integer to floating point conversion will lose accuracy
5, small type to large type conversion is generally safe.
6, small type of accuracy is higher than the large type should pay attention to the loss of precision.
four, large type to small type conversion
1. Strong turn type conversion-strong turn
2. When forcing type conversion, pay attention to the problem of boundary number risk
v. int type and char type conversion
Java is handled by type int for data of type char at the bottom.
int type and char type are automatically converted when assigning values
Vi. getting data through the args array
1, the program run time choose RUn configurations ...,
2, in Java application to find the corresponding project run history information or right-click to add a new class,
3, select (x) =arguments in program Arguments input data, such as input 1 space 2,1 2 is the first second element of the array, and then click Run
Vii. Obtaining data from the console via scanner
1. The Scanner class is used to scan data entered from the console and can receive data from strings and basic data types.
2, the scanner class is located in the Java.util.Scanner package.
3. Common methods of scanner class:
-
-
String next (); Function: Receives a string from the console output.
-
String nextline (); Function: Receives a string from the console output.
-
int Nextint (); Function: Receives data of type int of the console input.
-
Double nextdouble (); Function: Receives a double type of data from the console input.
-
Boolean nextboolean (); function: Receives a Boolean type of data from the console input.
Enter data of type char: The scanner class does not provide a way to enter the char type directly, and the input character can be obtained from next () or nextline () through the Charat () method.
4. Implementation steps
Step 1, create an object of the scanner class.
Example: Scanner Scanner = new Scanner (system.in); (declared in stack space, new comes out in heap space)
Step 2, through the scanner call next method, receive the console input data.
Example: System.out.println ("Name:")
String Name=scanner.next ();
Viii. self-increment, self-reduction, squared, and self-subtraction of variables
1, the integer variable self-increment:
int i=0; i=i+1;
2. Self-increment of string type variable
String space = ""; space=space+ "";
3. Abbreviated form of self-increment operation:
Self-reduction empathy-I, I--,i-=n
Squared i*=n
Self-removal i/=n
ix. types of errors in Java
Program errors are divided into compile-time syntax errors, run-time exception errors, and run-time logic errors.
1. Compile-time syntax errors can easily locate errors and modify them with the help of Eclipse.
2, the operating period is abnormal, the system will prompt the wrong type and the location of the error.
3, logic error refers to the program can compile and run, but the results of program execution is not the expected effect.
10, Debug debugging
Debugging is an important means to find and solve the logic error code (BUG: Software bug) in software, which is an essential part of software development.
Eclipse provides powerful code debugging capabilities-debug, which can quickly locate logic errors in your code and improve software development efficiency with the debug view.
Debug View:
Open Eclipse and click the Debug button to enter the Debug view.
If the debug tag does not exist, you can click the White Add button to add the debug tag.
Breakpoint:
1. A breakpoint is a flag that is set on the specified line in the executable part of the source code, and in the debug run mode, the program runs to the breakpoint flag and automatically pauses waiting for the next action.
2, by setting a breakpoint can quickly execute the code before the breakpoint, and then pause at the breakpoint, you can change the way a single command run to run the program, find logic errors in the program.
Double-click the line number to add breakpoints and cancel breakpoints.
Reference: Geek College Course http://ke.jikexueyuan.com/zhiye/javaweb/
Java Web Learning Note Chapter III Java Foundation (II)