JAVA

  minte9
REMEMBERS




Last update:   09-06-2022

File

p9 In Java, everything goes into a class, into a file with .java extension.
 
/**
 * In Java, everything goes into a class (.java file)
 * JVM compiles the file, resulting a .class file (used to run the app).
 * 
 * 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!
    }
}

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;
    }
}

Questions     github Basics
Objects
        A B C D E F
🔔
1/4