each Java programs start with a class declaration in which the class name is immediately following the keyword class.
eg:
public class computearea{}
each Java applications must have a Mian method where the program starts executing, so the program should be extended to public class computearea{
public static void Main (string[] args) {
}
}
the two meanings of the + sign:
1. do the addition.
2. make a string connection (if the two operands are strings, the string connector connects the two strings together.) If an operand is not a string, the value of the non-string is converted into a string and then connected to another string. )
constants must be declared and assigned in the same statement, and the word final is the Java keyword that declares the constants .
System.currenttimemillis() returns The number of milliseconds since the UNIX timestamp.
String class strings, predefined classes in the Java library.
coercion type conversion (int)4.5
Convert a string to a number Integer.parseint (String)
Math.random () returns a double-precision random value of D, and satisfies 0.0<=d<1.0.
that (int) (Math.random () *10) returns a random integer (that is, the 0~9 ).
Output System.out.printf (format,item1,item2,... itemn) here, format is a string that consists of a substring and a format identifier.
The%b represents a bool type.
%d indicates decimal.
%s represents a string.
Syntax for defining methods:
modifier return value type Method Name (parameter list) {
method Body ;
}
The only difference between the Main method and other methods is that it is called by the Java virtual machine
the statements in main can call Other methods defined in the same class as the main method, or you can call methods defined in other classes. If you are in a new class, you can use the class name . The method name to invoke.
overloaded methods (methods with the same name, with different parameter lists,the Java compiler uses that method according to the method signature, and cannot overload the method based on different modifiers or return value types)
A+math.random () *b returns a between a and a+b but does not include a+b The random number.
Array declaration double[] Nums=new double[10];
In order to use an array in a program, you must declare a variable that references an array and indicate the element type of the array. (unlike the declaration of a basic data type variable, declaring an array variable does not allocate any space to the array in memory.) It simply creates an array of references to the storage location).
Java supports a for Loop, called a for-each Loop, that does not apply subscript variables that can sequentially traverse the entire array.
For(double u:mylist){System.out.print (U);}
List2=list1;
The statement does not copy the contents of the array referenced by List1 to list2. instead, the List1 Copy the reference value of the List2. after this statement, List1 and the List2 all point to the same array, and the previously referenced array can no longer be referenced. Garbage is automatically reclaimed by the Java virtual machine.
Variable-length parameter list
public static void Printmax (Double...numbers)
Note: You can use numbers as an array in the method
Eg:printmax (345,3,4);
Printmax (New double[]{1,2,3})
This article is from the "Small Stop" blog, please be sure to keep this source http://10541556.blog.51cto.com/10531556/1880755
Java Trivia points