Getting Started With Java

Steps in getting started

  1. Download Java
  2. Download Java SDK
  3. Get an Integrated Development Environment
  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 application is the main function

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) {

                        }
                    }
                
            

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

The name of the project is therfore "MyMainFunction"

Printing to the console

In order to pring to the console. We Use System.out.println.

I know it is 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.println("Hello")
                        }
                    }
                
            

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

java-method-img

code for copy

                
                    Public static void myFunction(String name, int age )
                    {
                        //function code 
                    }
                
             
Declaring Functions

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

Object Orientated Programming

Java is known as an object orientated 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;
                    }

                
            

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();