JAVA VIVA COMPLETE DEFINITIONS WITH EXAMPLES
-------------------------------------------
1. CLASS:
A class is a blueprint or template from which objects are created.
Example:
class Student {
String name;
int age;
2. OBJECT:
An object is a real-world entity created from a class.
Example:
Student s = new Student();
3. CONSTRUCTOR:
A constructor is a special method used to initialize objects.
Example:
Student() {
name = "Aryan";
4. METHOD:
A method is a block of code that performs an action.
Example:
void greet() {
[Link]("Hello");
5. VARIABLE:
A variable is a container that stores data.
Example:
int age = 15;
6. DATA TYPES:
Types of data stored in variables.
Example:
int, double, char, boolean
7. TOKENS:
Smallest units in a Java program.
Includes: identifiers, keywords, literals, operators, separators.
8. IDENTIFIERS:
Names given to variables, methods, classes.
Example: totalMarks, Student
9. KEYWORDS:
Reserved words with special meaning.
Example: class, public, static, void
10. LITERALS:
Fixed values.
Example:
10, 3.14, 'A', true
11. OPERATORS:
Used to perform operations.
Example:
+, -, *, /, %
12. SEPARATORS:
Characters that separate program parts.
Example:
(), {}, ;
13. POLYMORPHISM:
One action behaving in many ways.
Real-life example: A person behaves differently with friends vs teachers.
Java Example:
void area(int r)
void area(int l, int b)
14. INHERITANCE:
One class acquiring properties of another.
Real-life: Son inherits traits from father.
Java:
class A {}
class B extends A {}
15. ENCAPSULATION:
Wrapping data + methods together and protecting data using private.
Real-life: Medicine capsule protects powder.
Java:
private int age;
public void setAge(int a){ age = a; }
16. ABSTRACTION:
Showing only essential details.
Real-life: You drive a car but don't see engine working.
Java:
abstract void start();
17. ARRAY:
A group of similar data stored in continuous memory.
Example:
int nums[] = {1,2,3};
18. LOOP (FOR, WHILE, DO WHILE):
FOR LOOP – used when number of iterations is known.
for(int i=1;i<=5;i++)
[Link](i);
WHILE LOOP – used when condition-based repetition needed.
int i=1;
while(i<=5){
i++;
DO WHILE LOOP – runs at least once.
int i=1;
do{
i++;
}while(i<=5);
19. STATIC:
Used when value is common to all objects.
static String schoolName = "DVS School";
When NOT to use static:
When each object should have different data (name, roll).
20. OOPS:
Object Oriented Programming System – includes:
Class, Object, Encapsulation, Inheritance, Polymorphism, Abstraction.