Java Programming Ideas (fourth edition)
First to play a simple program,
So we're going to print the current date, and here we use the date class in the Java standard library.
The procedure is as follows:
1 Packagestudy. Demo;2 3 Importjava.util.Date;4 5 Public classHellodate {6 7 Public Static voidMain (string[] args) {8System.out.println ("Hello." It ' s: ");9System.out.println (NewDate ());Ten } One}
We come to print another small program, slowly, for a long time did not forget the almost, hey, later still have to play more code to good. Master Java at the very least a programming language//
The nonsense is not tender to see the following procedures,
1 Packagestudy. Demo;2 3 Importjava.util.Date;4 5 Public classHellodate {6 7 Public Static voidMain (string[] args) {8System.out.println ("Hello." It ' s: ");9System.out.println (NewDate ());Ten } One}
The first row of main () displays all the properties obtained from the system on which the program is running, thus showing the environment information. The list () method sends the result to its arguments: System.out can also be sent to any place, such as sent to a file, you can also ask specific properties, such as above, we queried the user name and Java.library.path
----------------------------------------------
Basic syntax
Assignment, it should be reviewed, don't say I waste time, memory is a little so forgetful *\\
Give the code First:
1 Packagestudy. Demo;2 3 classtank{4 intLevel ;5 }6 7 Public classAssignment {8 Public Static voidMain (string[] args) {9Tank T1 =NewTank ();TenTank t2 =NewTank (); OneT1.level = 9; AT2.level = 57; -System.out.println ("1:t1.level:" + T1.level + ", T2.level:" +t2.level); -T1 =T2; theSystem.out.println ("2:t1.level:" + T1.level + ", T2.level:" +t2.level); -T1.level = 27; -System.out.println ("3:t1.level:" + T1.level + ", T2.level:" +t2.level); - + } -}
Output *
1 1:t1.level:9, t2.level:572 2:t1.level:57, t2.level:573 3:t1.level:27, t2.level:27
This is very simple, does not explain.
----------------------------------------------
alias problem in method invocation --when passing an object to a method, an alias problem is also generated.
The procedure is as follows:
1 Packagestudy. Demo;2 3 4 classletter{5 CharC;6 }7 Public classPassobject {8 Static voidf (letter Y) {9y.c = ' Z ';Ten } One Public Static voidMain (string[] args) { ALetter X=NewLetter (); -x.c = ' a '; -System.out.println ("1, x.c:" +x.c); the f (x); -System.out.println ("2, x.c:" +x.c); - } -}
Output *
1 1, x.c:a2 2, X.c:z
Method F () seems to copy a copy of its argument letter y within its scope, but in fact it simply passes a reference. So the line of code:
1 y.c = ' Z ';
The actual change is an object other than F (). The problems and solutions of aliases are complex topics. Know on the line, should pay more attention to this trap.
----------------------------------------------
Arithmetic operators
The simple operation program is as follows:
1 /**2 * 3 * Arithmetic Operators4 * 5 */6 7 Packagestudy. Demo;8 9 ImportJava.util.*;Ten One Public classMathops { A Public Static voidMain (string[] args) { - //Create A seeded random number generator. - //Create a seed random numeric generator theRandom Rand =NewRandom (47); - intI, J, K; - //Choose value from 1 to. - //Select a value between 1 and 100 +j = Rand.nextint (100) + 1; -System.out.println ("J:" +j); +k = Rand.nextint (100) + 1; ASystem.out.println ("K:" +k); ati = j +K; -System.out.println ("J + K:" +i); -i = J-K; -System.out.println ("J-k:" +i); -i = k/J; -System.out.println ("k/j:" +i); ini = k *J; -System.out.println ("K * J:" +i); toi = k%J; +System.out.println ("K% J:" +i); -J%=K; theSystem.out.println ("J%= K:" +j); * $ //floating-point number tests:Panax Notoginseng //floating-pointing number test - floatu, V, W; the //applies to doubles. Too + //apply to doubles. Too Av =rand.nextfloat (); theSystem.out.println ("V:" +v); +W =rand.nextfloat (); -System.out.println ("W:" +W); $U = v +W; $System.out.println ("V + w:" +u); -U = v-W; -System.out.println ("V-w:" +u); theU = v *W; -SYSTEM.OUT.PRINTLN ("V * w:" +u);WuyiU = V/W; theSystem.out.println ("v/w:" +u); - //The following also works for Char. Wu //The following also applies to characters - //byte, short. Int. Long. and double. AboutU + =v; $System.out.println ("U + = V:" +u); -U-=v; -System.out.println ("U-= V:" +u); -U *=v; ASystem.out.println ("U *= V:" +u); +U/=v; theSystem.out.println ("U/= V:" +u); - $ } the}
Output *
1 j:59 2 k:56 3 j + k:115 4 j-k: 3 5 k/j: 0 6 k * J:3 304 7 k j:56 8 J%= k:3 9 v:0.5309454 w:0.0534122 One v + w:0.584 3576 v-w: 0.47753322 v * w:0.028358962 v/w: 9.940527 U + = V: 10.471473 U-= v:9.940527 -u *= v:5.2778773 u/= v:9.940527
Look slowly, multiple dozen code//
Java first day start//