1.Java中不用goto語句(都不會用到),要是用到了非要用到跳轉的語句的話,就用帶标簽的continue 和break語句;
例如下:
/**
* 輸出101——150之間的質數;
* @author wang
*
*/
public class lableContinue {
public static void main(String[] args) {
outer:for(int i = 101; i <= 150; i++) {
for(int j = 2; j < i/2; j++ ) {
if(i % j == 0) {
continue outer;//如果不加outer 就會跳出if這個語句,加上的就會跳到指定的語句(帶标簽的的那個地方);
}
}
System.out.println(i);
}
}
}
2.方法:一段用來完成特定功能的代碼片段;
public class overload {
public static void main(String[] args) {
overload a = new overload();
a.add(3,4);
add(2.3,2.4);
}//注意方法必須寫到這個main()方法的外面 否則會報錯;
public void add(int i , int j ) {//這個方法不加static 就不能直接調用必須new一個對象
System.out.println(i+j);
}
public static void add (double i ,double j) {//加了static就可以
System.out.println(i+j);
}
}
上面牽涉到了overload很簡單的,不多說;
3.遞歸:自己調用自己

上面有一個System.currentTimeMillis();傳回目前的時間;
遞歸:很耗費時間和記憶體(一般不用)
public class diguiTest {
public static void main(String[] args) {
long time1 = System.currentTimeMillis();
long a = factorial(5);
System.out.println(a);
long time2 = System.currentTimeMillis();
System.out.println(time2 - time1);
}
static long factorial(int n) {
if(n == 1) {
return 1;
}
else {
return n * factorial(n - 1);
}
}
}
4.Unified Modeling Language (UML):标準模組化語言
5.Java虛拟機的記憶體有三個 棧(stack) 堆(heap) 方法區(method area 她其實屬于堆 因為有點特殊是以單獨列出來)
1.棧(stack):
2.堆(heap):
new 關鍵字就是建立對象;
3.方法區(method area)
來個例子:
/**
* 測試一個類并分析其記憶體
* @author Wang
*
*/
public class testClass {
int id;
String name;
String sex;
computer comp;
void tsetClass() {}
void study() {
System.out.println("我正使用我的" + comp.brand +"電腦在學習");
}
void play() {
System.out.println("我正在玩遊戲!");
}
public static void main(String[] args) {
computer c1 = new computer();
c1.brand ="HP";
testClass a = new testClass();
a.comp = c1; //把c1這個對象的值給a類中comp這個對象
a.study();
a.play();
}
}
class computer{
String brand;
void computer() {}
}
6.構造方法:作用初始化對象;要點如下;
注意:對于第三點C++也是如此;
public class user {
int id;
String name;
String screat;
public user() {}
public user (int a) {
id = a;
}
public user(int a, String name) {
id = a;
this.name = name; //第一個name前面加了一個this代表的是這個這個類的成員變量,後面是局部變量;要是不加this的話那麼就近原則都是局部變量
}
public user(int a,String b,String c) {
id = a;
name = b;
screat = c;
}
public static void main(String[] agrs) {
user a1 = new user(1);
user a2 = new user(11,"w");
user a3 = new user(111,"www","wangtong");
System.out.println(a3.screat);
}
}
7.垃圾回收機制(Garbage Collection)GC(C++沒有這個)
1.發現無用的空間;
2.回收;
了解就OK;(架構的時候可能會用)
分代的垃圾回收機制:
容易造成記憶體洩漏的操作: