Java Standards, Class & Object
Java Standards, Class & Object
Java is a popular programming language widely used for application development. One of the key features of Java is its support for templates, the powerful mechanism for creating objects through its class system. Objects are created from classes, which are like blueprints that define the properties and behavior of objects. Overall, Java's support for standards and its class system make it a powerful and versatile language for building a wide range of applications.
Standards
Class, variable, method can be mentioned as the parts that can be seen mainly in a java code. They have unique characteristics that make them easily recognizable in Java code.
- The first letter to start a class is always uppercase.
- The first letter initializing a variable is always lowercase.
- The first letter starting a method is always lowercase, and parentheses must be used at the end.
According to the simple code shown in Figure 1,
- class - Code, String
- variables - class, java, public, void
- method - test()
Operators with Java Print Statement
Figure 2 : Print Statement |
Figure 3 : Print Example |
Besides class, variable, method, Java print statement (Figure 2) includes dot operator, parameters and semi colon. Also, as shown in Figure 3, assignmental operators and equalization operators, curly braces are also used here.
- ( ) Parameter - Store relevant data.
- ; Semicolon - Indicate the end of the code line.
- { } Curly Brackets/Scope identification - Identify the scope of a class or a method.
- . Dot Operator - Use for calling the next.
- = Assignmental Operator - Enables substitution of a value (not to equal)
- == Equalization Operator - Sets a value to equal.
Class & Object
In Java programming language, there is a class hierarchy which includes,
- Object
- Class
- Method
- Variable
For example, features that are accessible to the object, are not accessible to the variable. But features that are accessible to the variable are always accessible to the object.
Figure 4 : Class Hierarchy |
Object
Anything that has properties (features) and behaviours (functions) is called an "object". Properties are things an object has and are non active. Behaviors are things an object can do and are active.
For example, the computer can be taken as the object. It contains the components like monitor, keyboard, mouse, CPU etc. which are required to make the computer work. Those devices can be described as properties of the object called the computer. Many activities like coding, watching videos, playing games etc. can be done using the devices owned by the computer. Those activities can be described as the behaviours of the object called computer.
Figure 5 : Object Example |
Class
A class is a template created for an object.
An object has properties and behaviors. In programming, class, variables and methods are used to refer to object, properties and behavior. Variables and methods are used in a class just like properties and behaviors are used in an object. A class can contain any number of objects by changing their values.
As shown in the previous example, let's take the computer as the object. Computer can be taken as the class. Each computer has the same attributes and behaviors, but the values associated with them vary from computer to computer. Simply put, things like speed, processor, memory of a computer vary from one computer to another. Therefore, there may be many objects in the computer class that have the same variables and methods but whose values change.
Figure 6 : Class Example |
Comments
Post a Comment