PROGRAMMING

m9/ JAVA
REMEMBERS




Last update:   22-10-2021

Classes

p9 ! In Java, everything goes into a class, into a file with .java extension.
 
/**
 * In Java, everything goes into a class (.java file)
 * Compilation generate a .class file
 * 
 * The program starts in main()
 * 
 * The return type void means there is no returned value.
 * Every statement must end in semicolon.
 */

package com.minte9.basics.classes;

public class Classes {
    public static void main( String[] args ) {

        System.out.println("Hello World!"); 
            // Hello World!
    }
}
... 10 lines
 

Blueprint

p35 A class is a blueprint for an object.
 
/**
 * A class is a blueprint for an object.
 * 
 * Instance variables (fields) is what an object knows.
 * Methods is what an object does.
 */

package com.minte9.basics.classes;

public class Blueprint {
    public static void main(String[] args) {
        
        MyClass obj = new MyClass();
        obj.setName("John");

        System.out.println("Hello " + obj.name); 
            // Hello John
    }
}

class MyClass {
    public String name;

    public void setName(String name) {
        this.name = name;
    }
}
... 15 lines
 

Questions     github Basics
Objects

        A B C D E F
🔔
1/4