Java Class Explained for Beginners :Java Tutorial Series

                                     

 

What Will I Learn?

  • You will learn How a java class worksYou will learn about Java objects
  • You will learn how to create a new class
  • You will learn how to instantiate a new objec 

Requirements

  • System Requirements: Java JDK, Eclipse IDE or Netbeans IDE
  • OS Support for Java:Windows, macOS, Linux   
  • Required Knowledge A fair knowlege of java Basics and fundamentals   

Resources for Java and this tutorial:

  • Oracle Website: https://www.oracle.com/index.html
  • Java Docs: http://www.oracle.com/technetwork/java/javase/documentation/api-jsp-136079.html
  • Others : https://stackoverflow.com/questions/3527264/how-to-create-a-pojo DifficultyBeginner 

Description

Outline and Overview 

Classes are very important. Without it then nothing can be done.We will consider a class using POJO (Plian Old Java Object) Basically, a class is like a blueprint that contains what actions of things to be done. Consider the blueprint of a house (that is the architectural design). it contains what should be put in place, how it should be put, the actions to be carried out etc Let me use an Object call House to further buttress on POJO.

  •  Object House here is our class. 
  • Objects in real life have attributes : this attributes are usually referred to as instance variables. 
  • Knowing the attribute of the object, you can take actions on it : let say u can give your house color blue.  
     now lets represent this in code.....    

Lets Begin ....

STEP 1  :  Create a java project having a main method

STEP 2 Create a new java class in the same package with any name of your choice 

STEP 3 The Code itself

 Class House{  

  //this are the attributes : instance variables

String color;

String size;

 /* here we create a constructor where our variable will be initialized. Currently color and size is null (that is empty). So when we want to use our object, we can the tell it what the values are */ 

//the following methods are the actions you carry out on your object 

public  House(String s1, String s2){ 

color = s1;

size = s2;}   

public String getColor(){return color}//this set de color of the object 

public String getSize(){return size}


}


Now our House object is created, we then use it in the main function


 Class myMainClass{

public void main(String[] args) {

//make an instance of your House object

 House myHouse = new House(“Blue”,”Big”); 

//now do whatever you want to on the house

 myHouse.getColor();

myHouse.getSize(); 

System.out.println("House Color is :" + houseClolor);

System.out.println("\nHouse size is :" + houseSize);

}  


(


This is the output of the above code

next tutorial coming soon!!!

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now