Java Class, Object and Variables

Java Classes:
In Java, a class serves as a blueprint or a template for creating objects. It is a fundamental concept in object-oriented programming (OOP) and defines the structure and behavior that objects of that class will possess.

A class is a temp…


This content originally appeared on DEV Community and was authored by Dev Ananth Arul

Java Classes:
In Java, a class serves as a blueprint or a template for creating objects. It is a fundamental concept in object-oriented programming (OOP) and defines the structure and behavior that objects of that class will possess.

A class is a template to create objects having similar properties and behavior, or in other words, we can say that a class is a blueprint for objects.
Properties of Java Classes:

  • Class is not a real-world entity. It is just a template or blueprint, or a prototype from which objects are created.
  • A class itself does not occupy memory for its attributes and methods until an object is instantiated.
  • A Class in Java can contain Data members, methods, a Constructor, Nested classes, and interfaces.

Java Objects:

Objects are the instances of a class that are created to use the attributes and methods of a class. A typical Java program creates many objects, which as you know, interact by invoking methods. An object consists of:

State: It is represented by attributes of an object. It also reflects the properties of an object.
Behavior: It is represented by the methods of an object. It also reflects the response of an object with other objects.
Identity: It gives a unique name to an object and enables one object to interact with other objects. 

Java Variables:

In Java, variables are containers used to store data in memory. Variables define how data is stored, accessed, and manipulated.

A variable in Java has three components,

Data Type: Defines the kind of data stored (e.g., int, String, float).
Variable Name: A unique identifier following Java naming rules.
Value: The actual data assigned to the variable.

Rules to Name Java Variables:

  • Start with a Letter, $, or _ – Variable names must begin with a letter (a–z, A–Z), dollar sign $, or underscore _.
  • No Keywords: Reserved Java keywords (e.g., int, class, if) cannot be used as variable names.
  • Case Sensitive: age and Age are treated as different variables.
  • Use Letters, Digits, $, or _ : After the first character, you can use letters, digits (0–9), $, or _.
  • Meaningful Names: Choose descriptive names that reflect the purpose of the variable (e.g., studentName instead of s).
  • No Spaces: Variable names cannot contain spaces.
  • Follow Naming Conventions: Typically, use camelCase for variable names in Java (e.g., totalMarks).


This content originally appeared on DEV Community and was authored by Dev Ananth Arul


Print Share Comment Cite Upload Translate Updates
APA

Dev Ananth Arul | Sciencx (2025-10-14T17:33:59+00:00) Java Class, Object and Variables. Retrieved from https://www.scien.cx/2025/10/14/java-class-object-and-variables/

MLA
" » Java Class, Object and Variables." Dev Ananth Arul | Sciencx - Tuesday October 14, 2025, https://www.scien.cx/2025/10/14/java-class-object-and-variables/
HARVARD
Dev Ananth Arul | Sciencx Tuesday October 14, 2025 » Java Class, Object and Variables., viewed ,<https://www.scien.cx/2025/10/14/java-class-object-and-variables/>
VANCOUVER
Dev Ananth Arul | Sciencx - » Java Class, Object and Variables. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/10/14/java-class-object-and-variables/
CHICAGO
" » Java Class, Object and Variables." Dev Ananth Arul | Sciencx - Accessed . https://www.scien.cx/2025/10/14/java-class-object-and-variables/
IEEE
" » Java Class, Object and Variables." Dev Ananth Arul | Sciencx [Online]. Available: https://www.scien.cx/2025/10/14/java-class-object-and-variables/. [Accessed: ]
rf:citation
» Java Class, Object and Variables | Dev Ananth Arul | Sciencx | https://www.scien.cx/2025/10/14/java-class-object-and-variables/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.