Mitsugu Oyama のソフトウェア倉庫
 > ツール関連資料
  > Java Cheat Sheet for ME

  1. public class helloworld {
      public static void main(String[] args){
        System.out.println("Hello World!!");
      }
    }
          
  2. boolean, byte, short(16bit), int(32bit), long(64bit), char(unsigned 16bit), float, double, String
          
  3. class MyClass {
      MyClass(){
        ...
      }
      MyClass(p1,p2,....){
        ...
      }
      int iHoge;
      int method_name(){
        ...
      }
      int method_name2();
    }
          
  4. final
    オーバーライド不可
    abstract
    抽象クラス、抽象メソッド
    static
    C と一緒 ( と思う )
    synchronized
    同期 ( メソッドの同期指定 )
    native
    Java 以外で書かれた言語
  5. private, public, protected
          
  6. class MyClass extends super_class {
      MyClass(){
        super();
        ...
      }
      MyClass(p1,p2,...){
        super(p1,p2,...);
        ...
      }
      ...
    }
          
  7. interface MyInterface {
      int func1();
      int func2();
      ...
    }
    
    class MyClass implements MyInterface {
      int func1() {
        ...
      }
      int func2() {
        ...
      }
      ...
    }
          
  8. interface MyInterface extends SuperInterface1, SuperInterface2, ... {
      void func();
      ...
    }
          
  9. インターフェースのフィールドは定数
  10. 例外はドキュメント見ろ
  11. Runtime.getRuntime().freeMemory()
    Runtime.getRuntime().totalMemory()
    Runtime.getRuntime().gc()
          
  12. public class MakeThread extends Thread {
      public static void main(String[] args) {
        MakeThread mt = new MakeThread();
        mt.start();
        ...
      }
      public void run() {
        ...
      }
    }
          
  13. public class MakeThread implements Runnable {
      public static void main(String[] args) {
        MakeThread mt = new MakeThread();
        Thread st = new Thread(mt);
        st.start();
        ...
      }
      public void run() {
        ...
      }
    }
          
  14. class Runner extends Thread {
      private boolean running = true;
      public void stopRunning() {
        running = false;
      }
      public void run() {
        while (running) {
          ...
        }
      }
    }
          
  15. try {
      Thread.sleep(m_sec)
    } catch ( InterruptedException e ) {
    }
          
  16. public class MakeThread implements Runnable {
      public static void main(String[] args) {
        MakeThread mt = new MakeThread();
        Thread st = new Thread(mt);
        st.start();
        ...
        try {
          st.join();
        } catch (InterruptedException e) {
          ...
        }
      }
      public void run() {
        ...
      }
    }
          
  17. void join() throws InterruptedException
    void join(long msec) throws InterruptedException
    void join(long msec, int nsec) throws InterruptedException
          
  18. try {
      wait();
    } catch (InterruptedException e) {
    }
          
  19. Object.wait()
    Object.notify()
    Object.notifyAll()
          
  20. public final int getPriority()
    public fine void setPriority(int newPriority)
    public static final int MIN_PRIORITY
    public static final int NORM_PRIORITY
    public static final int MAX_PRIORITY
          
  21. import package_name1[.pakage_name2[.package_name3[...]]].class_name;
          
  22. package package_name;
    [public|private|protected] class class_name {
      ...
    }
          
  23. JDK Programmer Guides