javac XXX.java. java XXX . main method. public static void main(String[] args) java ClassName . String[].
The return tpye is void. It is no different from other methods. args is a String array. You can use
args.length to access the length of args.args[0], args[1]... to access the elements in
the array args[i] (i.e.
i >= args.length ) an error will occur
during runtime. java ClassName string0 string1 .. String[] args = {string0, string1 , ... } is created args pass to main(String[] args) and the method body is
executedargs is a null . java ClassName "Charles Li". System.out.println(string) to print out a string
and then go to next line.System.out.print(String) to print out a string without
going to a new line at the end. System.out.println(....) can print out
int, float,... as well. public, class, void
....myName is different from
MyName. byte, short, int, long, float, double, char, boolean. long is more precise than int,
double is more precise than float etc etc. int a, b, c
double are
double a = 3.14, b = 3, c = 2.713e10, d = 34.665e5d;
float are very similar to
double. You have to add f at the end of the number.
float a = 3.14f, b= 34.665e5f;
float a = 3.14 causes an compiling error because
3.14 is a double by defalt long x = 58819394L; . int char represents a character. boolean a = true; boolean b = false;
if, else, while, do-while, for, switch .
break and continue
ClassName[] arrayName arrayName = new
ClassName[size]. null.
int[] array1 = {1,2,3,4,5};
String[] array2 = {"this", "is" , "review" , "notes"}
array.length to get the size of the array.
String by
String s = "Hi"; + String
class. But you should understand the methods. Documentation will be
provided if I ask questions on this class. new. private, protected and public and their meaning. static variables and
non-static variables. this and super. final. BorderLayout, GridLayout, FlowLayout BorderLayout.NORTH, BorderLayout.SOUTH,... to
specific the direction. add(component) or add(component,
BorderLayout.CENTER) to add to the center. add(component, BorderLayout.NORTH) etc to add to the
north remove(int) to remove BorderLayout. getContentPane().add(...) to add components. or
getContentPane().setLayout(..) to set layout. setSize, pack,
setVisible, setLocation,
setBackground and all other methods I mentioned in the handout. JFrame, we can add components to it directly. ImageIcon and set the image
icon. JFrame(), JFrame(String title) |
two useful constructors. |
getContentPane() |
you getLayout and add, remove through the
contentPane. |
setVisible(boolean) |
set the frame visible |
setSize(int width,int height) |
set the dimension of the frame |
pack() |
use the most "prefect" size for the frame. |
setLocation(int x, int y) |
Set the location of the upper left corner at (x,y). The upper left corner of you screen is (0,0) |
setLayout , add and remove has to be
used through getContentPane(). add/remove/setLayout without getContentPane(),
it will be a compiling error. JFrame is BorderLayoutJPanel(),JPanel(LayoutManager) |
constructors |
void add(Component),void add(Component, int), void remove(int) |
add, remove components |
void setLayout(LayoutManager),LayoutManager
getLayout() |
the meaning is obvious |
JFrame, the class use add, remove,
setLayout directly.FlowLayoutJFrame throught
getContentPane().setLayout(....)JPanel by setLayout(). BorderLayout(), BorderLayout(int hgap,vgap).
The gap is 0 if you don't specify themadd(Component comp, int direction), remove(int direction):
direction can be BorderLayout.NORTH,.... add(Component comp): add the CENTER CENTER index in
add(comp,index), remove(index)
index in
add(comp,index), remove(index)row = 0 or
col = 0.