(根据网上Derek Banas 教学视频整理的笔记)
1. 基本word
1)
Public: All users can use this function
Static: Only one class can use this function
Void: This function does not return any values
Main: It's required in every Java program. It's always excuted first
2)
Every main function must accept an array of string objects
Class variables must start with static if you want to access them with any other methods in the class
2. Define数字类型 (例子)
1)
byte theByte = 45;
short theShort = 12345;
int theInt = 1234567890;
long theLong = 9223372036854775807L; //记得后面有个“L"
float theFloat = 3.14F; //记得后面有个”F"
double theDouble = 3.1234567890;
boolean theTrue = true;
2)
用Java本身的指令显示最大、最小值
System.out.println(Float.MAX_VALUE);
System.out.println(Double.MAX_VALUE);
System.out.println(Byte.MIN_VALUE);
3. Define char (例子)
char randomChar =65;
char anotherChar='A';
//Character Code for A is 65 Minimum value 0 Maximum value 65535
char backSpace='\b';
char formFeed='\f';
char lineFeed='\n';
char carriageReturn='\r';
char horizontalTab='\t';
char doubleQuote='\"';
char singleQuote='\'';
char backSlash='\\';
System.out.println(randomChar);
System.out.println(backSpace);
System.out.println(formFeed);
System.out.println(lineFeed);
System.out.println(carriageReturn);
System.out.println(horizontalTab);
System.out.println(doubleQuote);
System.out.println(singleQuote);
System.out.println(backSlash);
// chars can also contain escaped characters
4. Define String (例子)
String randomStrings = "random";
String anotherString="string";
String lastString= randomString +" "+anotherString;
System.out.println(lastString);
// How to convert other type to string
String byteString=Byte.toString(bigByte);
String shortString=Short.toString(bigShort);
String intString=Integer.toString(bigInt);
String longString=Long.toString(bigLong);
String floatString=Float.toString(bigFloat);
String doubleString=Double.toString(bigDouble);
String booleanString=Boolean.toString(trueOrFalse);
String charString=Character.toString(randomChar);
System.out.println(charString);
System.out.println(doubleString);
5. 转换
前面加括号,里面是要转换的类型
double doubleValue= 3.1234;
int doubleToInt=(int)doubleValue;