// Define Static Method within a Class
public class HelloStatic {
    // Java standard runtime entry point
    public static void main(String[] args) {    
        System.out.println("Hello World!");
    }
}
// A method call allows us to execute code that is wrapped in Class
HelloStatic.main(null);   // Class prefix allows reference of Static Method
Hello World!
// Define Class with Constructor returning Object
public class HelloObject {
    private String hello;   // instance attribute or variable
    public HelloObject() {  // constructor
        hello = "Hello, World!";
    }
    public String getHello() {  // getter, returns value from inside the object
        return this.hello;  // return String from object
    }
    public static void main(String[] args) {    
        HelloObject ho = new HelloObject(); // Instance of Class (ho) is an Object via "new HelloObject()"
        System.out.println(ho.getHello()); // Object allows reference to public methods and data
    }
}
// IJava activation
HelloObject.main(null);

Hello, World!


// Define Class
public class HelloDynamic { // name the first letter of class as capitalized, note camel case
    // instance variable have access modifier (private is most common), data type, and name
    private String hello;
    // constructor signature 1, public and zero arguments, constructors do not have return type
    public HelloDynamic() {  // 0 argument constructor
        this.setHello("Hello, World!");  // using setter with static string
    }
    // constructor signature, public and one argument
    public HelloDynamic(String hello) { // 1 argument constructor
        this.setHello(hello);   // using setter with local variable passed into constructor
    }
    // setter/mutator, setter have void return type and a parameter
    public void setHello(String hello) { // setter
        this.hello = hello;     // instance variable on the left, local variable on the right
    }
    // getter/accessor, getter used to return private instance variable (encapsulated), return type is String
    public String getHello() {  // getter
        return this.hello;
    }
    // public static void main(String[] args) is signature for main/drivers/tester method
    // a driver/tester method is singular or called a class method, it is never part of an object
    public static void main(String[] args) {  
        HelloDynamic hd1 = new HelloDynamic(); // no argument constructor
        HelloDynamic hd2 = new HelloDynamic("Hello, Nighthawk Coding Society!"); // one argument constructor
        System.out.println(hd1.getHello()); // accessing getter
        System.out.println(hd2.getHello()); 
    }
}
// IJava activation
HelloDynamic.main(null);

Hello, World!
Hello, Nighthawk Coding Society!
public class Person {
    private String name;

    // Setter method for name
    public void setName(String name) {
        this.name = name;
    }

    // Getter method for name
    public String getName() {
        return name;
    }

    public static void main(String[] args) {
        Person person = new Person();
        person.setName("John");
        System.out.println("Name: " + person.getName());
    }
}
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

// Method to calculate the mean
double mean(int[] numbers) {
    double sum = 0;
    for (int num : numbers) {
        sum += num;
    }
    return sum / numbers.length;
}

// Method to calculate the median
double median(int[] numbers) {
    Arrays.sort(numbers);
    int middle = numbers.length / 2;
    if (numbers.length % 2 == 0) {
        return (numbers[middle - 1] + numbers[middle]) / 2.0;
    } else {
        return numbers[middle];
    }
}

// Method to calculate the mode
int mode(int[] numbers) {
    Map<Integer, Integer> countMap = new HashMap<>();
    for (int num : numbers) {
        countMap.put(num, countMap.getOrDefault(num, 0) + 1);
    }

    int maxCount = 0;
    int mode = -1;
    for (Entry<Integer, Integer> entry : countMap.entrySet()) {
        if (entry.getValue() > maxCount) {
            maxCount = entry.getValue();
            mode = entry.getKey();
        }
    }
    return mode;
}

Scanner scanner = new Scanner(System.in);
System.out.println("Enter a comma-separated list of numbers:");
String input = scanner.nextLine();
String[] numberStrings = input.split(",");
int[] numbers = new int[numberStrings.length];
for (int i = 0; i < numberStrings.length; i++) {
    numbers[i] = Integer.parseInt(numberStrings[i].trim());
}

System.out.println("Mean: " + mean(numbers));
System.out.println("Median: " + median(numbers));
System.out.println("Mode: " + mode(numbers));
Enter a comma-separated list of numbers:
Mean: 4.571428571428571
Median: 5.0
Mode: 5