Java learning notes (1)
2003/04/26 xuyunsheng
First, the life cycle of the applet applet:
Init () -> Start () -> stop () -> destroy ()
| | | | | | Re-load, refresh the web page or close Browser (terminate applet)
| | | | __ Call when you leave the web page containing the applet (pause or close applet)
| | __ Turn on the web page containing the applet (start applet)
| __ (complete the initialization of the primary class instance, only call once)
The following incident will cause the Browser to automatically call the Paint () method:
1) When the applet is started, the Browser automatically calls the start () method.
2) The Browser window is enlarged, narrowed, and moving
3) When other related methods are called, if the repaint () method is called, Browser will first call the Update () method, clear the screen of the Applet applet, and then call the Paint () method to re-draw.
Second, the conversion of strings and other data types
----------------
Other objects are converted to strings:
----------------
1) For basic data types, the static valueOf () method provided by the String class itself can be used to convert logical variables, characters, character arrays, double precision, floating point, integer to string type.
INT NINT 10;
Float ffloat = 3.14f;
// Call the Valueof static method separately
String str1 = String.Valueof (nint);
String str1 = String.Valueof (nfloat);
..........
..........
2) For the basic data type packages (Character, INTEGER, FLOAT, DOUBLE, Boolean, Short, Byte, Lont) and other classes derived from the Java.Lang.Object class (such as Exception, StringBuffer, etc.) can be used. The toString () method converts the class into a string.
INT nint = 10;
Float ffloat = 3.14f;
// Convert to integer, floating point
Integer Obj1 = new ingeger (nint);
FLOAT OBJ2 = New float (nfloat);
// Call the TOSTRING method to convert to a string
String str1 = obj1.toString ();
String str2 = obj2.tostring ();
..........
..........
----------------
String Convert to Other Objects:
----------------
1)
String strstring = new string ("i love java");
String strinteger = new string ("10");
String strfloat = new string ("3.14");
// Call the static method in various types, respectively
CHAR [] carray = strstring.tochararray ();
INT nint = integer.parseint (Strinteger);
Float ffloat = float.parsefloat (strfloat);
......
......
2) Similarly, the user can call the valueof method in Integer, Double, Long, Float and other classes to convert the string to the corresponding package data type, which is converted to a simple data type. String strpi = "3.1415926";
Double DPI = Double.Valueof (STRPI);
Double ddpi = dpi.doublevalue ();
Third, the date of Java is acquired, set and formatted
1) Java provides 3 date classes: Date, Calendar and DateFormat.
The Date () method is mainly used to create a date object and obtain the date;
The Calendar () method is mainly used to obtain and set the date;
The dateformat () method is primarily used to create a date formatting, and then convert the date to a variety of date format string outputs by the formatter.
2) The benchmark date specified in Java language is 1970.1.1.00:00:00, and the current date is converted from the number of milliseconds experienced by the benchmark date.
3) The DateFomat class is in the Java.Text package, the Date and Calendar classes are in the java.util package.