Write Java programs
1 Notepad, write code
2 file name is consistent in the class name ".java"
3 compiler compiler creates a class file
Compile
Open a command line window, go to the directory where the Java file, execute the command: javac Welcome.java last generated class file.
Note
1 // single line comment
2 / ** / multi-line comments can not be nested
2 Documentation comments / ** * * * * * * * * * / comments include some descriptive text and some JavaDoc notes (written during the latter part project, you can generate API project)
3
Java
- java is a case-sensitive language
- Public key is called an access modifier (access modifier), the level of access to the code for other parts of the control program]
- Keyword class java class called object-oriented class which code must therefore
- As much as a source file only declare a public class Any number of other classes, if the source file contains a public class, the original file name must be a class name which is the same as the public, and to ".java" suffix name
- A source file can contain multiple classes
- After compilation of the source file correctly, will give the corresponding byte code file, the compiler generates a separate class for each of the byte code files, and the file is automatically named bytecode class name, and to ".class" is extension name
- The main method is the entry for Java applications, it has a fixed writing mode:
- public static void main(String[] args){…..}
- Braces to divide each location in the program
- Java is the end of each statement must be a semicolon, not a carriage return marks the end of the statement, and a statement may span multiple lines
Java output stream System.out.println ();
The most common DOS commands
1 cd into the directory path to a directory
2 cd .. command into the parent
3 dir find a list of files and subdirectories in the catalog
4clr Clear Screen command
5 Find command more than the up and down keys
6Tab completion of both command
Identifier
$ 1 identifier must begin with a letter it is underlined portions may have other numbers
2Java case sensitive identifier, and a length no limit
3 identifier can not be a Java keyword
Identifier Use
Identifier 1 indicates the class name: the letters of each word capitalized
Identifier 2 indicates the methods and variables: the first word lowercase, beginning from the second word capitalized, which we call "hump principle"
Keywords can not be used as an identifier;
It represents a variable memory space operable
Double long (8 bytes) int (4 bytes)
Categorical variables
{Local variable valid after the first use of the range defined}
Member variables: class member variables are automatically initialized digital defaults to 0; char '\ u0000' Boolean false
Static variable static subordinate class longest life cycle;
constant
In the Java language mainly use the keyword final to define a constant, constant whose value can not be changed once initialized
Binary 0b 0B
Octal 0 ..
Hex 0X 0x
Byte 1 byte
Short 2 bytes
Float variables and constants
· Float decimal scientific notation 1e1 = 10
· Floating point imprecision must not be used for comparison
If desired comparison, you need to use the following two package Java.math useful classes: BigInteger and the BigDecimal, these two classes can handle any length value. BigInter achieve arbitrary-precision integer arithmetic, BigDecimal achieve any floating point intensive
Character variables and constants
char
String character sequence
Boolen type variables, constants
Boolen type has two constant values, true and false, occupied in a memory, can not be used to replace non-zero 0 or true and false, with different c
Operator (operator)
Arithmetic operators + - * / (binary operator)
Binary operator calculation rules:
1 If both operands have one of Long, Long the results of
2 no Long, result int, i.e., operands are all short, byte, the result is int
Floating-point operations:
1 If both operands have a double, the result is the double
2 only two operands are float, the result was to float
% Remainder operator operand left the same symbols I
++ - Operator
Java can not be used during operation rules defined edge using the edge
Relational operators true or false
Logical operators: Boolean operator
Logic & (and) logical or | (or) logical not! We need to look at both sides
Short-circuit and short circuit && or || logic can just see the leftmost
Logical XOR ^
Bitwise Operators
~
&
|
^
<< >> left right (3 * 4 Fast arithmetic method is left to the right corresponds to 2/2);
String connector
(Both sides as long as there is a string, then the string can be considered connector)
"+": Only the combination of strings and the plus sign to display the string, otherwise only shows values;
Ternary operator: x y:? Z
Priority problems (Non logic> logic> logical OR)
Automatic type conversions: a small capacity type data can be automatically converted into a large capacity of data types.
(Integer constant directly assigned byte short char type variable like, without the need for cast, no more than a range which can be expressed)
Cast:
Use Scanner keyboard input
import java.util.Scanner;
Scanner scanner=new Scanner(System.in);
System.out.println ( "Please enter your name:");
String name=scanner.nextline();
System.out.println ( "Please enter your name:");
String hobby=scanner.nextline();
System.out.println ( "Please enter your age:");
int age=scanner.nextInt();
Flow control statement is used to control the order of execution of each statement in the program statements (and similar language c)
Sequence structure of the cyclic structure selected structure
If single-selection structure
If - else selection structure bis
If-else else if else if else multiple selection structure
Switch multi-selection structure
When the cyclic structure-type structure until the structure
While (Boolean value determination)
{} Loop
do
{
Loop
} While (Boolean)
For loop
(C communicates with language)
Java printout is distinguished progressive print and C language
Output stream: print (print as lines)
Println (in columns print)
Break forced to exit the loop continue to exit this cycle
Tagged break and continue statements
A:
If(s){ continue A;}
The basic method of use (function similar to the C language -----)
Experience: In Java class to define and then implement a variety of functions in the class, the main function of which is still the main function, so you can define an object class in the main function, (then) in order to call a member of the class function.
Defining classes of objects: [object name] [name] = new arbitrary object name [] ();
Return value of the function: return
Public static int [] function name () {}
When the call is no need to redefine the object class; can be used directly
Note judgment conditions in Java boolean value must be ture or false
Method overloading: all different ways, but the same name only
Different meanings: number of different parameters and different parameter types, different parameter order (if different argument types)