Java Core – Object and Class concept

Java is an Object Oriented Programming Language. Object and Class are 2 main concepts of Java.
What are Java Object & Java Class?

The tutorial will introduce Java Object & Java Class.

I. Java Object

In the real word, there are many Objects: Cats, Dogs, Computers, Mobile Phones. Each Object has individual states and behavior.

In software and Java technology, Objects are similar characteristics. State of Java Object are stored in fields. And the behavior of Java objects are simulated by methods.

How do Java objects communicate together?
Method is the communication between Object to Object in Java. And in fact, method is also the way for internal communication in Java Object.

II. Java Class

Java Class is the ways to define Java Objects.

What are components of Class?
Because Java class defines Java Objects, Java Class contains:
– Instance Variables for indicating states of Java Objects.
– Methods for simulating the behavior of Java Objects.

“new “ keyword is a way to create a object from class in Java.
And Constructor is a way to initial object state at the creating time.

In the above example code:
– Customer is a Java class.
– cust is a Java Object.
– id, firstName, lastName are instance variables. They defines the status of cust object.
public Customer(long id, String firstName, String lastName) is a constructor.
– the cust object has state at initial time: id = 1, firstName = Peter, lastName = “David”.

III. Practices
1. Enviroment

– Java 1.8
– Eclipse Version: Mars.2 Release (4.5.2)

2. Structure of Project

java object class

3. Run


III. Source Code

java object class

By grokonez | October 4, 2016.

Last updated on June 4, 2017.

Related Posts

Got Something To Say:

Your email address will not be published. Required fields are marked *