Home Java Docker
Home     Java

Java Topic

What is Java
History of Java
Freature of Java
Difference Between Java & C++
Java Environment Set Up
Java Hello World Program & its Internal Process
Java Hello World Program
JDK, JRE and JVM
Java Variables
Java Data Types & Unicode System
Java Operators
Java Keywords
Java Control Statements
Java if else
Java switch
Java for loop
Java While loop
Java Do While loop
Java break
Java continue
Java Oops Concept
Java Object & Class
Java Method
Java Constructor
Java Static Keyword
Java this Keyword
Java Inheritance
Java Hybrid Inheritance
Aggregation(HAS-A)
Java Polymorphism
Java method overloading
Java method overriding
Java Runtime polymorphism
Java Dynamic Binding
Super keyword
Final keyword
Difference Between method overloading and method overriding
Java Abstraction
Java Interface
Abstract class vs Interface
Java Encapsulation
Java Package
Java Access Modifiers
covariant return type
Instance initializer block
Java instanceof operator
Object Cloning in Java
Wrapper classes in Java
Java Strictfp Keyword
Recursion in Java
Java Command Line Arguments
Difference between object and class
Java String
Java String Class
Java Immutable String
Java Immutable Class
String Buffer
String Builder
String Buffer vs String
String Builder vs String Buffer
String Tokenizer in Java
Java Array
Java Exceptions Handling
Java Try-Catch block
Java Multiply Catch Block
Java Finally Block
Java Throws Keyword
Java Throw Keyword
Java Exception Propagation
Java Throw vs Throws
Final vs Finally vs Finalize
Exception Handling With Method Overridding
Java Multithreading
Lifecycle and States of a Thread in Java
How to create a thread in Java
Thread Scheduler in Java
Sleeping a thread in Java
Calling run() method
Joining a thread in Java
Naming a thread in Java
Thread Priority
Daemon Thread
Thread Pool
Thread Group
Shutdown hook
Multitasking vs Multithreading
Garbage Collection
RunTime Class
Java Synchronization
Synchronized block in Java
Static Synchronization in Java
Deadlock in Java
Inter Thread Communication in Java
Interrupting Thread in Java
Reentrant Monitor in Java
Java Applet
Animation in Applet
EventHandling in Applet
Display image in Applet
Displaying Graphics in Applet
Parameter in Applet
Java 8 Features
Java Lambda Expressions
Method References
Functional Interfaces
Java 8 Stream
Base64 Encode Decode
Default Method
for Each() Method
Collectors class
String Joiner Class
Optional Class
JavaScript Nashron
Parallel Array Sort
Type Interface
Parameter Reflection
Type and Repeating Annotations
JDBC Improvements

Difference between object and class

    What is an object in Java

  • A Java object is a member (sometimes called an instance) of a Java class. Every object has a state, a behaviour, and an identity.
  • In Java, the word "new" is used to create an object.
  • The items we can see in the actual world and Java objects are extremely similar. An item can be a pet, a lighter, a pen, or an automobile.
Table Of Content

  • What is an object in Java
  • Characteristics of Object in java
  • What is Class in Java
  • Java Class Structure
  • Difference Between Object and Class






Object has 3 characteristics:

  • State:: State represents an object's data (value).
  • Behavior : Behavior shows how a thing behaves (or how it functions or work), such as a object car have behaviors such as accelerating, braking, and turning.
  • Identity :An object's identity is often implemented via a unique ID. The value of the ID cannot be seen by an outside user. The JVM, however, makes use of it internally to individually identify each object.
  • For Example, Car is an object. Its name is Nano; color is red, known as its state. It is used to drive, so drive is its behavior.





What is Class in Java

  • A class serves as an object's design guide. Before creating an object, the class must be declared.
  • The class might be thought of as a rough drawing or prototype for a house. It includes all of the information on the floors, doors, windows, etc. We construct the house in accordance with these descriptions. The item is a house.
  • We may produce several objects from a class since numerous houses can be constructed using the same description.
  • In Java, a class can include:



    • Fields:
    • Methods
    • Constructors
    • Blocks
    • interface
    • Nested class

Class structure

  • Here, fields (variables) represent the state of object and methods represent the behavior of object
  • fields are used to store data
  • Methods are used to perform some operations



  •  // Java  program using class and object   
    class Car {	   
        public int gear = 2; // state 
      
        public void braking()  // behavior 
        {
          System.out.println("Car braks Working");
        }
    }
      
  • In the preceding example, we defined a class called Car. It has a gear field and a braking method (). Car is a prototype in this context. We can now use the prototype to build an unlimited number of Car. Furthermore, all of the Car will use the prototype's fields and methods.


Example of class and object




Java example of class and object
 // Java  program using class and object   
class Student2{  
	String Stu_name ;   
	int Stu_id;
	 void insert(String stu_name, int stu_id) {
		Stu_name = stu_name;
		Stu_id = stu_id;
	}  
	public void Display() {
		System.out.println(Stu_id);
		System.out.println(Stu_name+"\n");
	}
} 
class Student{  
	public static void main(String args[]){  
		  Student2 studentObject1=new Student2();
		  Student2 studentObject2=new Student2();
		  studentObject1.insert("Dr Alok Raja ", 40139522);
		  studentObject1.Display();
		  studentObject2.insert("Mrs Anita Sinha", 40139522);
		  studentObject2.Display();
	 } 
}  



Output:

40139522  
Dr Alok Raja 
  
40139532 
Mrs Anita Sinha 




Comparison Chart

Difference between object and class are mention below


S.N Object Class
1. An Objects are instances of classes. An outline or model for creating new objects is called a class.
2. A real-world item is an object, such as a car,bike,table,fan, etc. A class is a collection of similar object.
3. Physical entity are called objects. A logical entity is a class.
4. Mainly the new keyword is used to create objects, as in Main main=new Main (); The class keyword is used to declare classes, such as class Main{}
5. Depending on the need, an object is created multiple times. Classes are only declared once.
6. Memory is allocated whenever an object is created. There is no memory allotted when a class is created.
7. The new keyword, newInstance() method, clone() method, factory method, and deserialization are just a few of the ways to create an object in Java. In Java, the class keyword is the only way to define a class.




Java Array Next »
« Perv Next »


Post your comment





Read Next Topic
Java Tutorial - Topic
covariant return type
Instance initializer block
Java instanceof operator
Object Cloning in Java
Wrapper classes in Java
Java Strictfp Keyword
Recursion in Java
Java Command Line Arguments
Difference between object and class
Read Other Java Chapter
Java Topic
Java Basic Tutorial
Java Control Statements
Java Classes & Object
Java Inheritance
Java Polymorphism
Java Abstraction
Java Encapsulation
Java OOPs Miscellaneous
Java Array
Java String
Java Exception Handling
Java Multithreading
Java Synchronization
Java Applet
Java 8 Features
Java 9 Features
Java Collection
Java Mcq
Java Interview Question
Tools
  

Useful Links

  • Home
  • Blog
  • About us
  • Contact Us
  • Privacy policy

Contact Us

Police Colony
Patna, Bihar
India

Email:

About DockerTpoint


India's largest site for Programming Tutorial as well as BANK, SSC, RAILWAY exam
and Campus placement preparation.