Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/users/2/moriya-h5/web/confrage/java/java/declare_variable/declare_variable.html on line 2

Warning: include_once(http://www.confrage.com/bin/header.php): failed to open stream: no suitable wrapper could be found in /home/users/2/moriya-h5/web/confrage/java/java/declare_variable/declare_variable.html on line 2

Warning: include_once(): Failed opening 'http://www.confrage.com/bin/header.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/java/declare_variable/declare_variable.html on line 2
変数の宣言 | Java | 株式会社CONFRAGE
Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/java/declare_variable/declare_variable.html on line 17

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/java/declare_variable/declare_variable.html on line 17
変数の宣言
変数の宣言は以下のように宣言します。

public class Test{
    public static void main(String[] args) {
        int a;
        int b,c;
        int d=2;
        System.out.println(a);
    }
}
サンプルソース
public class Test{
    public static void main(String[] args) {
        int a=3;
        int b,c;
        int d=2;
        System.out.println(a);
    }
}
実行結果は以下の通りです。

3
static変数
static変数は、クラスに付随する変数です。その為、インスタンスを生成してもstatic変数は一つです。

private static boolean flg = true;

if(flg){
    //~何か実行~
    flg = false;
}

例えば、上記のようにboolean型のstatic変数flgが宣言されているとします。
マルチスレッド環境において、最初にクラスを実行したスレッドでstatic変数flgをfalseにした場合、以降のスレッドではif文の中は二度と通りません。
gcでも初期化されることはなく、アプリケーションサーバを再起動するまでずっと値を保持し続けます。

Back to top

Information

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/java/declare_variable/declare_variable.html on line 114

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/java/declare_variable/declare_variable.html on line 114

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/java/declare_variable/declare_variable.html on line 123

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/java/declare_variable/declare_variable.html on line 123