Starting With Java

Steps in getting started

  1. Download Java
  2. Download Java SDK
  3. Get an Integrated Development Environment (IDE)
  4. Start a project within the IDE
  5. Code up "Hello World" and run the code

Java Entry Point

It is categorized by its (string[]arg) as a parameter to the function

        
public class MyMainFunction {
  /* Java main function example */
  public static void main(String[] args) {
    System.out.println("Hello World");
  }
}
        
      

In this example, we are printing out "Hello world" to the console when we run the program.

Printing to the console

Printing to the console

Declaring Function

Functions are actually called methods in Java. Here is an example of how to declare a Java method.

java-method
        
public static void myFunction(String name, int age) {
  // function code
}
        
      
Object Oriented Programming

Java is known as an object oriented programming language.

This means that it is easy to represent entities as objects by using classes and encapsulation.

An example of this might be a student class to represent a student.

        
public class Student {
  /* Student properties */
  private String name;
  private int age;

  /* Constructor */
  public Student(String name, int age) {
    this.name = name;
    this.age = age;
  }

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

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