Java programs are made of classes. 

To run a program at least one class must have a main.

In file One.java

public class One {
  public static void main(String[] args) {
    System.out.println("Howdy."); 
  }
}

Let's compile and run it (in DrJava). 

import java.util.Arrays;

public class One {
  public static void main(String[] args) {
    System.out.println("Howdy."); 
    System.out.println( Arrays.toString( args ) ); 
    
  }
}

Here's how we ran this in DrJava: 

Welcome to DrJava.  Working directory is C:\Users\soicloan\Desktop
> run One
Howdy.
[]
> run One Paul Leslie Tom Jay
Howdy.
[Paul, Leslie, Tom, Jay]


Here's another example:

In Java we have four primitive types:

  integer                int byte long short 
  numbers with decimals  float double 
  truth values           boolean 
  characters             char

Everything else is a user-defined type, aka

  -- classes
  -- reference types
  -- objects (since they have the type of their class)

import java.util.Scanner;

public class Two {
  public static void main(String[] args) {
    int age; 
    String name;
    System.out.print("What's your name: "); 
    Scanner janis;
    janis = new Scanner( System.in ); 
    name = janis.nextLine(); // "Laura"; 
    System.out.print("How old are you: "); 
    age = janis.nextInt(); // 3;
    System.out.println( name + " you will be " + 
                        (age + 1) + " next year." );
  }
}

This is how the program runs:

Welcome to DrJava.  Working directory is C:\Users\soicloan\Desktop
> run Two
What's your name:  [DrJava Input Box]
How old are you:  [DrJava Input Box]
Tim you will be 6 next year.


Next: team exercise. 

Here are some conventions:

  a class name usually starts with an uppercase 

  examples: System  String  Integer  House 

  a variable name usually starts with lowercase

  examples: one age name spike 

  objects names start with lowercase

  a function (method) usually receives arguments

  so you will see the parentheses at the end

System.out.println("Howdy");

The essence of computation is the function. 

In Java and OOP in general we call that a method. 

Methods can be defined in classes (static) or in objects. 

Integer.parseInt("34"); 

parseInt is a method defined in a class, Integer. 

In System.out.println("Whatever"); we have

(a) a class System that has a (static) 

(b) member out (a PrintStream type of object)

(c) that has an instance method println.

That method in that object in that class can print. 

System.println("Howdy"); 

So the key is for you to build and rehearse a repertoire.

https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-

Welcome to DrJava.  Working directory is C:\Users\soicloan\Desktop
> 1
1
> 1 + 2
3
> 1 > 2
false
> "32"
"32"
> 32
32
> "32" + 0
"320"
> 32 + 0
32
> Integer.parseInt( "34" ) + 2
36
> Integer.parseInt( "102" )
102
> Integer.parseInt( "10a2" )
java.lang.NumberFormatException: For input string: "10a2"
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)


Now let's examine BigDecimal objects:

Welcome to DrJava.  Working directory is C:\Users\soicloan\Desktop
> 1 + 2
3
> 6 % 4
2
> 6 / 4
1
> 3 / 2
1
> 3.0 / 2
1.5
> 4.53 * 100
453.0
> 4.35 * 100
434.99999999999994
> 0.1
0.1
> 0.1 + 0.1
0.2
> 0.1 + 0.1 + 0.1
0.30000000000000004
> 0.1 + 0.1 + 0.1 + 0.1
0.4
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.5
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 
0.6
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.7
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.7999999999999999
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.8999999999999999
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.9999999999999999
> BigDecimal a, b;
Static Error: Undefined class 'BigDecimal'
> import java.math.BigDecimal; // auto-import
BigDecimal a, b;
> a = new BigDecimal("1");
> b = new BigDecimal("2");
> a + b
Static Error: Bad type in addition
> a.add(b)
3
> b.add(a)
3
> a = new BigDecimal("4.35");
> b = new BigDecimal("100");
> a.multiply(b)
435.00
> b.multiply(a)
435.00
> 4.35 * 100
434.99999999999994
>

--