PROGRAMMING

  minte9
learningjourney




S R Q

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, a .class file is created
 * 
 * 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    
Last update: 42 days ago
Basics, Objects