目次

使用するサイト

前提知識

  1. ↓の使い方
    
        $ cd ~
        $ code . # run vscode
        
  2. VSCode

初期設定

Git


    $ git config --global user.name "username" # usernameをGitHubで設定したusernameに変更
    $ git config --global user.email "email" # emailをGitHubで設定したemailに変更
    

VSCodeの拡張機能をインストール

基本の使い方

プログラムの共有

他の人の変更を受け取る

他の人に変更を送る

プログラムの実行

知っておくと便利な情報

便利なショートカットキーの一覧

キー 動作
Ctrl + s 保存
Ctrl + c コピー
Ctrl + v 貼り付け
Ctrl + z 元に戻す(編集を一つ前の状態にする)
Ctrl + y やり直す(編集を一つ後の状態にする)
Ctrl + Shift + i フォーマット(プログラムをきれいにする)

Issueを使う

ドキュメントを書く

コンパイルエラーを読む

  1. セミコロン忘れ

    
        aya@aya-HP-Pavilion-Plus-Laptop-14-eh0xxx:~/ドキュメント/projects/contest$  cd /home/aya/ドキュメント/projects/contest ; /usr/bin/env /usr/local/jdk-21/bin/java @/tmp/cp_50qtb720qcmgzwak7zhts86dd.argfile MapGame # 実行
        Exception in Application start method # 例外が発生したよ
        java.lang.reflect.InvocationTargetException
                at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
                at java.base/java.lang.reflect.Method.invoke(Method.java:580)
                at [email protected]/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
                at [email protected]/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
                at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
                at java.base/java.lang.reflect.Method.invoke(Method.java:580)
                at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1135)
        Caused by: java.lang.RuntimeException: Exception in Application start method # 以下の理由によって
                at [email protected]/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
                at [email protected]/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
                at java.base/java.lang.Thread.run(Thread.java:1583)
        Caused by: java.lang.Error: Unresolved compilation problem: # 以下の理由によって
                Syntax error, insert ";" to complete LocalVariableDeclarationStatement # 構文エラー, ";"入れろ
        
                at MoveChara.setCharaDirection(MoveChara.java:82) # MoveChara.setCharaDirection, MoveChara.javaの82行目
                at MoveChara.<init>(MoveChara.java:73)
                at MapGameController.initialize(MapGameController.java:25)
                at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2670)
                at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2563)
                at [email protected]/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2531)
                at StageDB.getMainStage(StageDB.java:59)
                at MapGame.start(MapGame.java:15)
                at [email protected]/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
                at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
                at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
                at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
                at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
                at [email protected]/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
                at [email protected]/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
                at [email protected]/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$10(GtkApplication.java:263)
                ... 1 more
        Exception running application MapGame
        
  2. 型間違い

    
        aya@aya-HP-Pavilion-Plus-Laptop-14-eh0xxx:~/ドキュメント/projects/contest$  cd /home/aya/ドキュメント/projects/contest ; /usr/bin/env /usr/local/jdk-21/bin/java @/tmp/cp_50qtb720qcmgzwak7zhts86dd.argfile MapGame # 実行
        Exception in Application start method # 例外が発生したよ
        java.lang.reflect.InvocationTargetException
                at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
                at java.base/java.lang.reflect.Method.invoke(Method.java:580)
                at [email protected]/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
                at [email protected]/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
                at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
                at java.base/java.lang.reflect.Method.invoke(Method.java:580)
                at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1135)
        Caused by: java.lang.RuntimeException: Exception in Application start method # 以下の理由によって
                at [email protected]/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
                at [email protected]/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
                at java.base/java.lang.Thread.run(Thread.java:1583)
        Caused by: java.lang.Error: Unresolved compilation problem: # 以下の理由によって
                Type mismatch: cannot convert from String to int # Stringをintに変換できません
        
                at MoveChara.setCharaDirection(MoveChara.java:83) # MoveChara.setCharaDirection, MoveChara.javaの83行目
                at MoveChara.<init>(MoveChara.java:73)
                at MapGameController.initialize(MapGameController.java:25)
                at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2670)
                at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2563)
                at [email protected]/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2531)
                at StageDB.getMainStage(StageDB.java:59)
                at MapGame.start(MapGame.java:15)
                at [email protected]/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
                at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
                at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
                at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
                at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
                at [email protected]/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
                at [email protected]/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
                at [email protected]/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$10(GtkApplication.java:263)
                ... 1 more
        Exception running application MapGame
        

コーディング規約

その他の補足

  1. nullの可能性を考える
    
        /**
         * 2つの文字をつなげる
         */
        private static String concatString(String before, String after) {
            return before + after;
        }
        
    
        /**
         * 2つの文字をつなげる
         */
        private static String concatString(String before, String after) {
            if (before == null) return after;
            if (after == null) return before;
            return before + after;
        }
        
    
        /**
         * 2つの文字をつなげる
         */
        private static String concatString(String before, String after) throws IllegalArgumentException {
            // beforeやafterがnullのとき
            if (before == null || after == null) throw new IllegalArgumentException(); // コメント省略
            return before + after;
        }
        
  2. ゲッタとセッタ
    
        class Something {
            /** 0以上の整数 */
            private int value = 0;
            Something() {}
            public int getValue() {
                return this.value;
            }
            public void setValue(int val) throws IllegalArgumentException {
                // valueは0以上の整数である必要がある
                if (val < 0) throw new IllegalArgumentException();
                value = val;
                return;
            }
        }