Java (程式語言)
想搵第二個意思嘅話,請睇Java。
Java係一種可以撰寫跨平台應用軟件嘅物件導向嘅程式語言,由昇陽電腦嘅占士哥斯連響1990年代初開發,本來用響智能家庭電器度,但後尾發展成網絡程式語言。
編程範式 | 多重範型:物件導向(類別基礎)、結構化、指令式、泛型、反射式編程、並發計算 |
---|---|
設計者 | 詹姆斯·高斯林 太陽電腦系統 |
編程員 | 甲骨文公司 (太陽電腦系統) |
第一次出現 | 1995年[1] |
穩定版本 | Java SE 17.0.1 2021年10月19號[2]
|
類型系統 | 靜態、安全、強類型、標明類型、弱類型 |
軟件授權 | GNU通用公共許可協議、JCP |
副檔名 | .java、.class、.jar |
網站 | java |
Major 實作版本 | |
OpenJDK、GCJ、其他 | |
衍生變體 | |
泛型Java、Pizza | |
啟發語言 | |
Ada 83、 Generic Java、 | |
影響語言 | |
Ada 2005、 | |
語言特性
編輯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==============");
}
}
註
編輯- ↑ Java 5.0 增加咗多種新特性(包括foreach循環,自動裝箱、拆箱,可變參數函數以及annotations), after they were introduced in the similar (and competing) C# language.[3][4]
- ↑ 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.
- ↑ 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]
- ↑ 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]
參考資料
編輯- ↑ "The History of Java Technology". 原先內容歸檔喺2012-11-06. 喺2012-10-06搵到.
- ↑ https://www.oracle.com/java/technologies/javase-downloads.html
- ↑ "Java 5 catches up with C#". www.barrycornelius.com. 原先內容歸檔喺2011-03-19. 喺2006-11-30搵到.
- ↑ Lévénez, Éric. "Computer Languages History". www.levenez.com. 原著喺2006-01-07歸檔. 喺2006-11-30搵到.
- ↑ Gosling, James; McGilton, Henry (May 1996). "The Java Language Environment". 原先內容歸檔喺2014-05-06. 喺2015-12-22搵到.
- ↑ Gosling, James; Joy, Bill; Steele, Guy; and Bracha, Gilad. "The Java Language Specification, 2nd Edition". 原先內容歸檔喺2013-05-12. 喺2013-02-28搵到.
{{cite web}}
: CS1 maint: multiple names: 作者名單 (link) - ↑ "The A-Z of Programming Languages: Modula-3". Computerworld.com.au. 原著喺2009-01-05歸檔. 喺2010-06-09搵到.
- ↑ "Java Was Strongly Influenced by Objective-C". cs.gmu.edu. 原先內容歸檔喺2011-07-13. 喺2013-02-28搵到.
- ↑ TechMetrix Research (1999). "History of Java" (PDF). Java Application Servers Report. 原著 (PDF)喺2010-12-29歸檔. 喺2015-12-22搵到.
The project went ahead under the name "green" and the language was based on an old model of UCSD Pascal, which makes it possible to generate interpretive code
- ↑ "A Conversation with James Gosling – ACM Queue". Queue.acm.org. 2004-08-31. 原先內容歸檔喺2015-07-16. 喺2010-06-09搵到.
- ↑ White Paper About Microsoft's "Delegates"
- ↑ "Facebook Q&A: Hack brings static typing to PHP world". InfoWorld. 2014-03-26. 原先內容歸檔喺2015-02-13. 喺2015-01-11搵到.