DEV Community

KIRUBAGARAN .K
KIRUBAGARAN .K

Posted on

Today a written test was conducted at Payilagam

1) What is compiler and interpreter

Compiler:
A compiler is a software application that follows the grammar rules of programming languages to translate source code into machine code.

Interpreter (JVM):
An interpreter is computer software that converts programs statements into machine code. Scripts already compiled code and source code all include program statements.
Checks line by line.


2) Features of Java

Simple

Object oriented

Platform independent

Secure

Robust

Portable

Multithreaded

High performance

Distributed

Dynamic & extensible

Architecture neutral

Interpreted & compiled


3) What is class and objects.

Class:

A class is a blueprint / template for creating objects.

It defines properties (variables) and behaviors (methods).

Example: Think of a class as a car design.

Object:

An object is an instance of a class.

It is created from a class and represents a real-world entity.

Example: A real BMW car or Audi car made from the design.

Example:
Student = Class

class Student {
String name;
int age;

void display() {
    System.out.println("Name: " + name);
    System.out.println("Age: " + age);
}
Enter fullscreen mode Exit fullscreen mode

}

Main class

public class Main {
public static void main(String[] args) {

    Student s1 = new Student();
    s1.name = "Kiruba";
    s1.age = 20;

    Student s2 = new Student();
    s2.name = "Manoj";
    s2.age = 22;

    s1.display();
    s2.display();
}
Enter fullscreen mode Exit fullscreen mode

}
Student=class

S1,s2=object


(4) What is Identifiers

All Java variables must be identified with unique names.

These unique names are called identifiers.

Identifiers can be short names (like x and y)

Or more descriptive names (age, sum, totalVolume).

Good:

int minutesPerHour = 60;

Ok, but not so easy to understand:

int m = 60;


(5) What is Declaration and Initialization

Declaration:

Telling the compiler that a variable exists and its type.

You are reserving memory for it, but not giving it a value yet.

Example:

int num; // declaration (num is an integer variable)

Initialization:

Assigning the first value to a declared variable.

Without initialization, the variable has no defined value.

Example:

num = 10; // initialization (assigning value 10 to num)


  1. What is ASCII and UNICODE?

ASCII

(American Standard Code for Information Interchange)

Old character encoding system

Uses 7 bits (0–127) → 128 characters

Covers only English letters, digits, symbols

Eg.:

A = 65

a = 97

0 = 48

UNICODE

Modern encoding system, developed to represent all world languages

Uses 16 bits or more → can represent 65,536+ characters

Supports English + all languages + emojis + symbols

Eg.:

A = U+0041

a = U+0061

☺ = U+1F600

7.Program (Hierarchical Inheritance)

Super class → Employee

Sub classes → Manager and Developer

1 method → calculateSalary() that returns salary

class Employee {
String name;
int id;

double calculateSalary() 
{
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

}

class Manager extends Employee {
double calculateSalary() {
return 40000; // fixed salary
}
}

class Developer extends Employee {
double calculateSalary() {
return 35000; // fixed salary
}
}

public class Company {
public static void main(String[] args) {
Manager m = new Manager();
m.name = "karan";
m.id = 101;

    Developer d = new Developer();
     d.name = "manoj";
     d.id = 103;

    System.out.println("manager "+ m.name + " (ID: " + m.id + ") Salary: " + m.calculateSalary());
    System.out.println("Employee "+ d.name + " (ID: " + d.id + ") Salary: " + d.calculateSalary());
}
Enter fullscreen mode Exit fullscreen mode

}

Top comments (0)