Java tuts notes - ch1

来源:互联网 发布:玻璃优化软件下载 编辑:程序博客网 时间:2024/05/20 13:38

Environment Configuration:

Java_Home: xxx/xxx/java/jdl-....

path: the path of jdk including bin directroy. Defined as %Java_Home% variable

        classpath: the path of jdk library     %Java_Home%\lib\tools.jar     dt.jar

!!!!classpath should contain   " . " (current working directory)  otherwise every time u compile should add the parameter -classpath . 


Basic data type:

char 16

byte 8, short 16, int 32, long 64 default is int

float 32, double 64 -default double


tips: 

Small automatically converts into Big eg. "int = byte" is valid 



Output:

1. console

System.out.printLn("XXXX");

System.out.printf("%d %d", x, y);

2. message box

String s="x="+x;

JOptionPane.showMessageDialog(null, s);


Input:

Type in:

System.in

import java.util.Scanner;

Scanner scan = new Scanner(System.in);


Message Box:

import javax.swing.JOptionPane;

String = "";

s = JOptionPane.showInputDialog(null, "Please type in a number: ");

int x = Integer.parseInt(s);


Java Programming Structure:

1. Branch

a. 

If (condition) {

.....

}

b.

if (condition) {

} else {

}

c.

if (condition) {

} else if () {

} else if () {

} else {

}

d.

switch(expression) { //int, char

    case value1:

         ...;

    case value2:

         ...;

    [default]:...;

}


2. Loop

    while() {}

    do {} while();

    for (;;)


As the grammar in C++


3. Logic Expression

    !, &&, ||        -      logic op(short-circuit evaluation)

       &, |           -      bit op





0 0
原创粉丝点击