Java (程式語言)

From Wikipedia, the free encyclopedia

Remove ads
  想搵第二個意思嘅話,請睇Java

Java係一種可以撰寫跨平台應用軟件物件導向程式語言,由昇陽電腦占士哥斯連英文James Gosling響1990年代初開發,本來用響智能家庭電器度,但後尾發展成網絡程式語言。

Quick Facts 編程範式, 設計者 ...
Remove ads
Remove ads

語言特性

Java之所以被開發,係要達到以下五個目的:

  • 應當使用物件導向程式設計方法學
  • 應當允許同一程式喺唔同嘅電腦平台執行
  • 應當包括內建嘅對電腦網絡嘅支援
  • 應當被設計成安全地執行遠端程式碼
  • 應當易於使用,並借鑑以前嗰啲物件導向語言(例如C++)嘅長處。

Java技術主要分成幾個部分:Java語言、Java執行環境、類別庫。一般情況下說Java時並唔區分指嘅係邊個部分。

Java喺1.5版本時,做咗重大改變,Sun公司並將1.5版本重新命名為Java 5.0。

例子:出「Hello World」

public class HelloWorld {

public static void main(String[] args) {
		
       System.out.println("Hello, World!");
	}
}

基本條件例子

public class IF {

public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
        int i=sc.nextInt();
        if(i>=1)
        {
			System.out.println("Hello, World!");
        }
	}
}
public class IfElse {

public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
        int i=sc.nextInt();
        if(i>=1)
        {
			System.out.println("Hello, World! \n And i >= 1. ");
        }
        else
        {
        	System.out.println("Hello, World! \n But i < 1.");
        }
	}
}
public class SwitchCase {

public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
        int i=sc.nextInt();
        switch(i)
        {
		cass 1:
            System.out.println(" i = 1 ");
            break;
        cass 2:
        	System.out.println(" i = 2 ");
            break;
        cass 3:
            System.out.println(" i = 3 ");
            break;
        cass 4:
        	System.out.println(" i = 4 ");
            break;
        cass 5:
            System.out.println(" i = 5 ");
        default:
        	System.out.println(" i >= 5 ");
        }
	}
}

基本迴圈例子

import java.util.*;
import java.text.*; 
import java.math.*; 
public class grade {
	public static void main(String [] argv){
		int i,j=0;
		float mx=0,mn=100,av,a,sum=0;
		System.out.println("逐一輸入班級分數,欲中止請輸入-1");
        Scanner sa = new Scanner(System.in);
        for(i=0;;i++){
            a=sa.nextFloat();
            if(a==-1)break;
            sum=sum+a;
            if(a>=60)j++;
            if(a>mx)mx=a;
            if(a<mn)mn=a;
        }
        av=sum/i;
		NumberFormat ddf1=NumberFormat.getNumberInstance() ;
		ddf1.setMaximumFractionDigits(2); 
        System.out.println(" 班級分數統計");
        System.out.println("==============");
        System.out.println(" 最高分數 "+mx);
        System.out.println(" 最低分數 "+mn);
        System.out.println(" 全班人數 "+i);
        System.out.println(" 及格人數 "+j);
        System.out.println(" 平均分數 "+ddf1.format(av));
        System.out.println("\n==============");
	}
}
Remove ads

  1. Java 5.0 增加咗多種新特性(包括foreach循環自動裝箱、拆箱英文Object type (object-oriented programming)#Autoboxing可變參數函數以及annotations), after they were introduced in the similar (and competing) C# language.[3][4]
  2. Niklaus Wirth stated on a number of public occasions, e.g. in a lecture at the Polytechnic Museum, Moscow in September, 2005 (several independent first-hand accounts in Russian exist, e.g. one with an audio recording: Filippova, Elena (2005-09-22). "Niklaus Wirth's lecture at the Polytechnic Museum in Moscow". 原先內容歸檔喺2020-12-01. 喺2015-12-22搵到.), that the Sun Java design team licensed the Oberon compiler sources a number of years prior to the release of Java and examined it: a(relative)compactness, type safety, garbage collection, no multiple inheritance for classes – all these key overall design features are shared by Java and Oberon.
  3. Patrick Naughton cites Objective-C as a strong influence on the design of the Java programming language, stating that notable direct derivatives include Java interfaces(derived from Objective-C's protocol)and primitive wrapper classes.[8]
  4. In the summer of 1996, Sun was designing the Contact Yahoo Support precursor to what is now the event model of the AWT and the JavaBeans TM component architecture. Borland contributed greatly to this process. We looked very carefully at Delphi Object Pascal and built a working prototype of bound method references in order to understand their interaction with the Java programming language and its APIs.[11]
Remove ads

參考資料

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads