public class App {
public static void main(String[] args) {
System.out.println("Hello, World !");
}
}
javac App.java
java App
javap -c App
class App {
public static void main(String[] args) {
System.out.println("Hello, World !");
}
}
class App {
public static void main(String[] args) {
System.out.println("Hello, " + args[0]);
}
}
class Person {
// corps de la classe Person
}
class Car {}
class Animal {}
class HttpClient {}
class Batmobile {}
class App {
public static void main(String[] args) {
new Batmobile();
new Batmobile();
new Batmobile();
}
}
class Batmobile {}
class Program {
public static void main(String[] args) {
Batmobile batmobile; // On déclare la variable de type Batmobile
batmobile = new Batmobile(); // On initialise la variable
}
}
Batmobile batmobile;
batmobile = new Batmobile();
class Batmobile {}
class Program {
public static void main(String[] args) {
Batmobile batmobile = new Batmobile();
}
}
class Batmobile {
// on déclare une méthode de la classe Batmobile
void goFast() {
// corps de la méthode goFast()
}
}
void goFast() { }
class Batmobile {
void goFast() {}
}
class Program {
public static void main(String[] args) {
Batmobile batmobile = new Batmobile();
batmobile.goFast(); // On appelle la méthode goFast()
}
}
System.out.println("Hello, World !");
System.out.println(); // saute une ligne
System.out.println(42);
class Batmobile {
void goFast() {
System.out.println("You can't catch me !");
}
}
class Program {
public static void main (String[] args) {
Batmobile batmobile = new Batmobile();
batmobile.goFast();
}
}
String greeting = "Hello";
String name = "Bob";
String message = greeting + ", " + name + " !";
System.out.println(message) // Affiche "Hello, Bob !"
class Person {
void sayHello() {
System.out.println("Hello !");
}
}
class Person {
String name = "Bob";
void sayHello() {
System.out.println("Hello, my name is " + name);
}
}
class Person() {
String name;
Person(String name) {
this.name = name;
}
}
class Program {
public static void main(String[] args) {
new Person("Bob");
}
}
class Person() {
String name;
Person() {
this.name = "Default name";
}
Person(String name) {
this.name = name;
}
}
class Person() {
String name;
}
class Program {
public static void main(String[] args) {
new Person(); // Constructeur généré par le compilateur Java
}
}
class Program {
static void sayHello() {
System.out.println("Hello, World!");
}
public static void main(String[] args) {
sayHello();
}
}
byte, short, int, long
float, double
boolean
char
+ - / * %