#CoreJava/ObjectOrientedProgramming
Programming Language
- Script - Reserved Keyword
- Grammar - Syntax
Programming Language for machine understanding
Machine Advantages:
- Accuracy
- Speed
Machine Disadvantages:
- Memory - We have use to proper utilize the memory
Procedural vs Object Oriented Programming
- C is a procedural-oriented programming language.
- C++ and Java are object-oriented programming languages.
- In procedural programming, processes are followed step by step.
- Changing or implementing new features in a procedural approach can be difficult because it may require altering the entire process.
- Object-oriented programming is easier to modify compared to the procedural method due to its modular structure.
What is OOPs?
?
- OOPs stands for Object-Oriented Programming.
- It’s a way of organizing code around objects, which represent real-world things.
- Key concepts include classes, objects, inheritance, polymorphism, and encapsulation.
- OOP helps make code reusable, modular, and easier to manage.
- Common OOP languages include Java, C++, and Python.
OOPs Features
?
The key features of OOPs (Object-Oriented Programming) are:
- Encapsulation: Bundling data and methods together, and restricting direct access to some of the object’s components.
- Inheritance: One class can inherit properties and behaviors from another class.
- Polymorphism: Objects can take many forms, allowing methods to be used in different ways.
- Abstraction: Hiding complex details and showing only the essential features.
Object
- Object - Real Time Entity
- Object - Structure (State) and Usage (Behaviour)
- State (Data) + Behaviour (Methods) = Class
- Object is instance of Class
- Object memory create at runtime
- Objects are dynamic memory size
- That object will have its state and access to all of the behavior defined by the class.
- An object without class is not possible.
- A class without object is possible.
Identity - Hashcode (Hashcode is generated using a hashing algorithm)
Instance - எடுத்துக்காட்டு
Instantiation means object creation.
Attributes - State
Both tangible and intangible objects are possible.
An example of a tangible object is the laptop.
An example of an intangible object is the banking system.
Tangible - உறுதியான (உணரமுடியும் )
Intangible - உணரமுடியாத
Creation of Object Syntax
?
class_name object_name = new class_name();
Explanation: we are using the new keyword to create the object of the class class_name, we can also observe, how the constructor of the class is been called using the new keyword.
new - allocates memory for object inside of the class. It is dynamic memory size.
class_name() - இந்த Brackets இல்லாம object create செய்யமுடியாது. இந்த Brackets constructor உடன் தொடர்புடயவை.
new class_name() --> Object
object_name --> Object Reference
Example:
MobileShop samsungMobile = new MobileShop();
What is Object?
?
- Object is Real Time Entity
- It is a combination of State(Variables) and Behaviour(Methods)
- Object is instance of a class
- Object memory create at runtime and dynamic memory size.
- For example, a car object might have properties like color and speed, and behaviors like accelerator or Brake apply.
What are the Characteristics of Object?
?
An object has three characteristics:
- State: The data or values the object holds (e.g., variables).
- Behavior: The actions or functions the object can perform (e.g., methods).
- Identity: A unique reference that distinguishes one object from another.
How many types to create an objects in java?
?
There are several ways of creating an objects in java, they are:
1. new keyword
- newInstance() method of Class class
- newInstance() method of Constructor class
- clone() method
- Deserialization in Java
- Factory Method Pattern
Is it possible to run a Java program without creating an object? How does it work if all methods are static?
?
- Yes, it is possible can run without creating an object if all methods are
static
. - Example
public class Example {
// Static method
static void displayMessage() {
System.out.println("Hello, World!");
}
// Main method (also static)
public static void main(String[] args) {
// Call static method without creating an object
displayMessage();
}
}
What is Class?
?
- A class is a blueprint or template in Object-Oriented Programming that defines the properties (variables) and behaviors (methods) of objects.
- A Class is a collection of similar types of objects.
- It is a user-defined data type and doesn't occupy any memory.
Syntax of Class
?
class ClassName{
//attributes (Objects)
//methods
}
Explanation:
class
is a reserved keyword in java- Class names should be written in PascalCase.
Member Functions
?
The functions are written inside a class are known as member functions.
Instance variables
?
Variables that are declared within the scope of the class.
Give any 5 Classes in java
?
- Concrete Class - (Normal Class)
- Final Class
- Abstract Class
- Wrapper Class
- Static Class
Structure of a Java Project
Follow this order:
-
Project (Drive)
-
Package (Folder)
-
Class (File)
Package Naming Convention:
- Use the reverse of your internet domain. For example:
com.demo.firstproject
- Use only lowercase letters.
Class Name Naming Convention:
- Don't start with a number.
- Don't use spaces.
- Alphanumeric names are allowed. Example:
Project1
- Avoid special characters except for underscores.
- Use PascalCase for class names.
Correct classname examples:
- MyFirstProject
- My_First_Project
- My1Project
- Use the reverse of your internet domain. For example: