DEV Community

KIRAN RAJ
KIRAN RAJ

Posted on

Empowering Careers: My Experience with Payilagam Training Institute

Today, in our training institute, my trainer conducts tests for everyone. After the test, Muthu Sir, they interviewed a few people from my batch to ask questions about the past two weeks that were trainer-taught, because they are eligible or not to continue in my institute by interviewing to filter out the non-eligible students and remaining the student Tomorrow, they have an interviews and end of the session, my trainer, Prithvi Sir, said write a today conducted test question a in all the students notes the answers are in below questions

1)What is Java compiler and interpreter definition?

A Java compiler, such as javac, is a program that translates Java source code (written in .java files) into an intermediate format called bytecode (in .class files). This bytecode is a set of instructions designed to be executed by the Java Virtual Machine (JVM). The compilation process involves scanning the entire source code, checking for syntax errors, and then generating the platform-independent bytecode.
A Java interpreter, which is part of the Java Runtime Environment (JRE), is responsible for executing the bytecode generated by the compiler. Specifically, the Java Virtual Machine (JVM) acts as an interpreter, reading and executing the bytecode instructions line by line on the specific operating system and hardware where the Java program is run. While traditional interpreters execute source code directly, in Java's case, the interpreter (JVM) executes the pre-compiled bytecode. Modern JVMs often incorporate Just-In-Time (JIT) compilers that can dynamically compile frequently executed bytecode segments into native machine code for improved performance during runtime.

2)Features of Java

Simple:
*Java is easy to learn, especially if you already know C or C++.
*It removes complex features like pointers, operator overloading,

multiple inheritance (handled by interfaces).

Object-Oriented:
*Everything in Java is treated as an object.
*Concepts like inheritance, polymorphism, encapsulation, and abstraction make programs modular and reusable.

Platform Independent (Write Once, Run Anywhere - WORA):
*Java code is compiled into bytecode which runs on the Java Virtual Machine (JVM).
*The same program can run on Windows, Linux, Mac, etc. without modification.

Secure:
*Java prevents memory corruption with no explicit pointers.
*It has a security manager and supports features like bytecode verification, sandboxing, and automatic garbage collection.

Robust:
*Strong memory management, exception handling, and type checking.
*Automatic Garbage Collection prevents memory leaks.
*Programs are less likely to crash.

Portable:
*Java programs are not dependent on hardware or operating system.
*Bytecode and the JVM ensure portability.

Distributed:
*Java has APIs for networking (TCP/IP, HTTP, sockets).
*Used for distributed applications like web services, RMI (Remote Method Invocation), etc.

Multithreaded:
*Java allows you to execute multiple tasks simultaneously (concurrency).
*Useful for applications like games, multimedia, web servers.

High Performance (Compared to other interpreted languages):
*Java uses JIT (Just-In-Time) Compiler to convert bytecode into machine code at runtime.
*Faster than pure interpreted languages like Python, but slower than C/C++.

Dynamic:
*Java can load classes at runtime (Dynamic class loading).
*Supports reflection and runtime polymorphism.
*It adapts to evolving code easily.

Architecture Neutral:
*Compiled code (bytecode) is independent of processor architecture.
*Works on different systems without recompilation.

Compiled and Interpreted:
*Java source code → compiled into bytecode (by javac).
*Bytecode → interpreted/executed by JVM.
*This two-step approach ensures efficiency + portability.

3) What is class and object with example java program?
🔹Class:
*A class is a blueprint or template.
*It defines the properties (variables/fields) and behaviors (methods) of objects.
*Example: If "Car" is a class → It defines attributes like color, brand, speed and actions like drive(), stop().

🔹Object:
*An object is a real-world entity created from a class.
*It is an instance of a class.
*Example: A specific car like "Red Honda City" is an object of the class "Car".

Example Java Program:
// Example of Class and Object in Java
class Car {
// Properties (fields/variables)
String brand;
String color;
int speed;

// Method (behavior)
void drive() {
    System.out.println(color + " " + brand + " is driving at " + speed + " km/h");
}
Enter fullscreen mode Exit fullscreen mode

}
public class Main {
public static void main(String[] args) {
// Creating objects from Car class
Car car1 = new Car();
car1.brand = "Honda City";
car1.color = "Red";
car1.speed = 120;

    Car car2 = new Car();
    car2.brand = "Maruti Swift";
    car2.color = "Blue";
    car2.speed = 90;

    // Calling methods using objects
    car1.drive();
    car2.drive();
}
Enter fullscreen mode Exit fullscreen mode

}

Output:
Red Honda City is driving at 120 km/h
Blue Maruti Swift is driving at 90 km/h

4) What are identifiers and rules of identifiers?
*An identifier is the name given to a variable, method, class, object, or any user-defined element in Java.
*Basically, it’s the name you give to something in your program.
Example:
class Student { // "Student" is an identifier
int age; // "age" is an identifier
String name; // "name" is an identifier

void study() {   // "study" is an identifier
    System.out.println(name + " is studying.");
}
Enter fullscreen mode Exit fullscreen mode

}

🔹 Rules for Identifiers in Java:
*Only letters, digits, underscore (_), and dollar sign ($) are allowed.
*Example: myVariable, student_1, $salary

*Identifiers must not start with a digit.
❌ Wrong: 123name
✅ Correct: name123

*No spaces are allowed.
❌ Wrong: first name
✅ Correct: firstName

*Java keywords (reserved words) cannot be used as identifiers.
❌ Wrong: class, int, static
✅ Correct: myClass, number, isStatic

*Identifiers are case-sensitive.
Student and student are different.

*Should start with a letter, $, or _.
✅ Valid: _value, $amount, total
🚫 Not recommended: Using $ and _ (used by system-generated code).

*No limit on length, but keep them meaningful.
✅ Good: studentName
❌ Bad: x1y2z3abc
Example (Valid & Invalid Identifiers):
// Valid Identifiers
int age;
String studentName;
double $salary;
int _marks123;
// Invalid Identifiers
int 123age; // ❌ starts with a digit
String first name; // ❌ space not allowed
double class; // ❌ keyword not allowed

5) Difference between initialization and declaration?
🔹 Declaration
*Declaration means reserving memory by specifying the variable name and its data type, but not assigning a value yet.
*It just tells the compiler what type of variable it is.
👉 Example:
int age; // variable declared (no value yet)
String name; // declared a String variable

🔹Initialization:
*Initialization means assigning an initial value to the variable after declaration.
*You give the variable its first value.
👉 Example:
int age = 20; // declared + initialized
String name = "Kiran"; // declared + initialized

6)Difference between ASCII code and Unicode:
🔹 ASCII (American Standard Code for Information Interchange)
*Developed in the 1960s.
*Uses 7 bits (128 characters: 0–127).
*Extended ASCII uses 8 bits (256 characters: 0–255).
*Represents English letters, digits, punctuation, control characters.
*Example:
'A' → ASCII code 65
'a' → ASCII code 97
👉 Limitation: Only supports English and a few symbols.

🔹 Unicode
*Developed to support all languages in the world.
*Uses 16 bits in Java (UTF-16) → can represent 65,536 characters directly.
*With UTF-8/UTF-32, it can represent over 1.1 million characters.
*Supports English + Chinese + Tamil + Hindi + Emojis + Special symbols.
*Example:
'A' → Unicode U+0041
'அ' (Tamil letter) → Unicode U+0B85
'😊' (emoji) → Unicode U+1F60A
👉 Advantage: One standard for all writing systems & symbols.

7)1. Write a program:

=> Base class Employee should contain fields name, employee Id, and a method calculate salary() which returns the salary of the employee.

=> The sub class manager should Inherit from Employee

=> The sub class developer should Inherit from Employee

=> main() creat object of manager and developer and display their salaries?

// Base class
class Employee {
String name;
int employeeId;

// method to calculate salary (default)
double calculateSalary() {
    return 0.0; // base employee has no fixed salary
}
Enter fullscreen mode Exit fullscreen mode

}

// Subclass 1
class Manager extends Employee {
double salary;

// method overriding
double calculateSalary() {
    salary = 80000; // fixed salary for manager
    return salary;
}
Enter fullscreen mode Exit fullscreen mode

}

// Subclass 2
class Developer extends Employee {
double salary;

// method overriding
double calculateSalary() {
    salary = 60000; // fixed salary for developer
    return salary;
}
Enter fullscreen mode Exit fullscreen mode

}

// Main class
public class Main {
public static void main(String[] args) {
Manager m = new Manager();
m.name = "Kiran";
m.employeeId = 101;
System.out.println("Manager " + m.name + " (ID: " + m.employeeId + ") Salary: " + m.calculateSalary());

    Developer d = new Developer();
    d.name = "Manoj";
    d.employeeId = 102;
    System.out.println("Developer " + d.name + " (ID: " + d.employeeId + ") Salary: " + d.calculateSalary());
}
Enter fullscreen mode Exit fullscreen mode

}

Top comments (0)