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.

 * Customer Class
 * @author
public class Customer {
	long id;
	String firstName;
	String lastName;
	 * Constructor of Customer class 
	 * @param id
	 * @param firstName
	 * @param lastName
	public Customer(long id, String firstName, String lastName){ = id;
		this.firstName = firstName;
		this.lastName = lastName;

	 * display method
	public String display() {
		String info = String.format("[Customer: id=%d, firstName=%s, lastName=%s]"
									, id, firstName, lastName);
		return info;

	 * Entry Point of Java Programming
	 * @param args
	public static void main(String[] args) {
		Customer cust = new Customer(1, "Peter", "David");

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


[Customer: id=1, firstName=Peter, lastName=David]
III. Source Code

java object class

0 0 votes
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments