Getting Started 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

The entry point to a java appliucation is the main function.

It is categorised by its (String[] arg) as a parameter to the function

            
                public class MyMainFunction {
                    /* Java main function example */
                    public static void main{String [] args} {

                    }
                }
            
        

As you can see the main function is wrapped within a clasds which is part of the object oriented structure of Java Projects.

The name of the project is therefore "MyMainFunction"

Printing to the console

In order to print to the console. We use System.out.print1n.

I know, it is very long and cumbersome, but this is the way it's done.

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

                    }
                }
            
        

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

Declaring Functions

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

java-method-img

Some copiable code:

            
                Public static void myFunction(String namew, 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 */
                    puiblic 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;
                    }
                }
            
        

We use this class by doing the following:

            
                Student student1 = new Student("Jimmy", 19);
                String jimmyName = student1.getName();
                student1.setName("Kevin");
                String kevinName = student1.getName();