JDK、JRE/JVM

MyApp.java -> Compile -> MyApp.class

Write once, run anywhere

ではjavaの基礎から行きます。

public class MyApp {

	public static void main(String[] args){
		System.out.println("Hello world");
	}
}

[vagrant@localhost java]$ javac MyApp.java
[vagrant@localhost java]$ ls
AdminUser.class MyApp.class MyInteger.class User.class
AmericanUser.class MyApp.java MyRunnable.class com
JapaneseUser.class MyData.class Printable.class java1
MyApp$1.class MyException.class Result.class
[vagrant@localhost java]$ java MyApp
Hello world

変数

public class MyApp {

	public static void main(String[] args){
		// 変数
		String msg;
		msg = "hello world again";

		System.out.println(msg);
	}
}
public class MyApp {

	public static void main(String[] args){

		char a = 'a';
		// 整数 byte short int long
		int x = 10;
		long y = 55555555L;
		double d = 23423.344;
		float f = 32.33F;
		boolean flag = true; // flase
		// \n, \t

		String msg = "hello w\norld a\tgain";

		System.out.println(msg);
	}
}

[vagrant@localhost java]$ javac MyApp.java
[vagrant@localhost java]$ java MyApp
hello w
orld a gain

public static void main(String[] args){

		int i;
		i = 10 / 3;
		System.out.println(i);
		i = 10 % 3;
		System.out.println(i);
		int x = 5;
		x++;
		System.out.println(x);

	}

[vagrant@localhost java]$ javac MyApp.java
[vagrant@localhost java]$ java MyApp
3
1
6

ほ~