跳轉到內容

軟體工程師手冊/語言詞典/Visual J++

來自華夏公益教科書,開放的書籍,開放的世界

Visual J++

[編輯 | 編輯原始碼]

以下是 Java 維基百科條目

Visual J++ 是一種完整的、過程式的、面向物件的、視覺化的語言。

執行入口點

[編輯 | 編輯原始碼]
public static void main(String args[])
{
    // some functionality here
}

通用語法

[編輯 | 編輯原始碼]

典型的語句以分號結尾。要將 b 賦值給 a,請使用

a = b;
// this is an inline comment.  Everything after the // is a comment.

塊註釋以 /* 開頭,以 */ 結尾。它們可以跨越多行。

/*
 * this is a block comment 
 */

變數宣告

[編輯 | 編輯原始碼]
int x = 9;
Integer y = new Integer(4);

方法宣告/實現

[編輯 | 編輯原始碼]
// declaration
private return_type class_name::function_name(argument_1_type arg_1_name, 
                          argument_2_type arg_2_name, 
                          default_argument_type default_arg_name)
{ // implementation
    // work with arg_1_name, arg_2_name, and default_arg_name
    // depending on the argument types the variables are passed by 
    //   value, reference, or are constant
    // don't forget to return something of the return type
    return 36;
}

範圍由大括號定義。

{ // this the beginning of a scope
    // the scope is about to end
}

條件語句

[編輯 | 編輯原始碼]

當且僅當 A 等於 B 時,將 C 賦值給 D,否則,將 E 賦值給 F。

if( A == B )
{
    D = C;
    // more code can be added here.  It is used if and only if A is equal to B
}
else
{
    F = E;
    // more code can be added here.  It is used if and only if A is not equal to B
}

if( A == B ) 
    D = C; //more lines of code are not permitted after this statement
else
    F = E;

或者,可以使用 switch 語句進行多選操作。此示例將數字輸入轉換為文字。

switch( number_value )
{
    case 37:
        text = "thirty-seven";
        break; // this line prevents the program from writing over this value with the
               //   following code
    case 23:
        text = "twenty-three";
        break;
    default: // this is used if none of the previous cases contain the value
        text = "unknown number";
}

迴圈語句

[編輯 | 編輯原始碼]

此程式碼從 0 計數到 9,將陣列的內容加起來。

int i = 0;
for( int index = 0; index < 10; index = index + 1 )
{
    i = array[index];
}

此程式碼重複執行,直到找到數字 4。如果這超出了陣列的末尾,則可能存在問題。

int index = 0;
while( 4 != array[index] )
{
    index = index + 1;
}

此程式碼在檢查之前遞增計數器,因此它從元素 1 開始。

int index = 0;
do
{
    index = index + 1;
}
while( 4 != array[index] );

輸出語句

[編輯 | 編輯原始碼]
System.out.println( "Hello World!" );

以及將文字新增到可視元件中。

容器繼承自 Collection 類。有關特定容器,包括 Vector,請參閱 java.util 包。

演算法

[編輯 | 編輯原始碼]

它有哪些演算法?排序在 J++ 中有效嗎?

垃圾回收

[編輯 | 編輯原始碼]

垃圾回收是自動的。

物理結構

[編輯 | 編輯原始碼]

程式碼通常儲存在副檔名為 .java 的檔案中。它被編譯成 Java 位元組碼,放入副檔名為 .class 的檔案中。

  • 該語言非常類似於 Java。
  • 視覺化表單佈局和元件訪問類似於其他 Microsoft Visual 開發語言。
  • Java 包中的類以大寫字母開頭,方法則沒有。
  • 一切都是指標。使用 clone 方法以避免操作 Collection 的原始元素。
  • 陣列從索引 0 開始。
  • 不要混淆這兩個
=  // assignment
== // comparison, is equal to

通常使用你不想要的那個會編譯,並且會產生你沒有預期的結果。

網路參考

[編輯 | 編輯原始碼]

書籍和文章

[編輯 | 編輯原始碼]

紙質參考文獻在此

華夏公益教科書