Programming

Constructor

It is a special method used to initialize properties of an object as new objects are created. A constructors can be with or with a parameter.

public class DomesticAnimals {

    private String dogName;
    private String dogBirthDate;
    private String dogSportFavorite;

    public DomesticAnimals (){
        this.dogBirthDate = null;
        this.dogBirthDate = null;
        this.dogSportFavorite = null;
    }
}
DomesticAnimals domesticAnimals = new DomesticAnimals();

Overriding and Overloading

Overriding is letting us to write off the function after inheritance and define what we want to work on inside the function .

Overloading is letting a function to have more than one role by changing the parameter, return type to have more rule.

public class Master {
    private String name;

    public Master(String name){
        this.name = name;
    }

    public Master() {
    }

    public void showName (){
        System.out.println(name);
    }
}





public class Child extends Master {

    private String name;

    public Child(String name){
        this.name = name;
    }
    @Override
    public void showName(){
        System.out.println(name);
    }

    public static void main(String []args){
        Child child = new Child("Dan");
        child.showName();

        Master master = new Master("Man");
        master.showName();
    }
}

Figure 1.3 : -Overriding

public class MultipleRole {

    private String name;
    private Integer age;

    public void setDetails(String name){
        this.name = name;
    }
    public void setDetails(Integer age){
        this.age = age;
    }
    public void setDetails (String name, Integer age){
        this.name = name;
        this.age = age;
    }
    public void showDetails (){
        System.out.println("Name=" + name + "," + "Age=" + age);
    }
}
public static void main (String []args){
        MultipleRole multipleRole = new MultipleRole();
        multipleRole.setDetails("Abebe" ,23);
        multipleRole.showDetails();
    }

Figure 1.4 : -Overloading

Array

It is a data structure which consists a set of value of the same or different type. The access of an array can be made through index. The index starts at 0 and goes to size of array -1.

Loop

Are statements used to iterate ignorer to do reparative works. There are several types of Loops like for, while, do .. while, forEach. The following are the possible example for application of the Loop statements

Conditional Statements

It is a statement that is used to control the execution of the code in a program. There are different types of statements like simple if, if else, if else if else, switch.

Exceptions

Are run time errors that could cause the program to terminal or crash during execution. These types of exceptions should be handled properly. one of the techniques of handling exceptions is try {} catch(ExceptionType e){}. There are various types of exception depending on the type of object that we are working one. Some of the exceptions are the following

  • IndexOutOfBoundExceptions
  • IOExceptions
  • NullPointerExceptions
  • ClassNotFoundExceptions
  • FileNotFoundExceptions
  • E.t.c

Casting

it is a procedure that could change the datatype of a certain value to another datatype. Values do have a built-in data types like string, integer, float, boolean, character, and so and so forth. The procedure to case in different programming language differ as per the implementation of the programming language. The following are the possible casting procedure in Java Programming language

Scroll to Top