Today i have java test and mock interview so, i learn how to face interview what type question they asked and how to face on it,and how to handle it.this mock interview motivate me to learn more than topics,
Interview questions:
-what is class?
-what keyword?
-what is identifier?
-what is ternary operators?
-what is object?
-what is datatype?
java question:
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)feature of java:
-
Platform-Independent
Write Once, Run Anywhere (WORA): Java code is compiled into bytecode, which can be run on any platform that has a Java Virtual Machine (JVM). This makes Java highly portable across different operating systems.
-
Object-Oriented Programming (OOP)
Java is based on the principles of OOP, which include:
Encapsulation: Bundling data and methods that operate on the data within a class. Inheritance: Mechanism where one class inherits the properties and behavior of another. Polymorphism: Ability to perform one action in multiple ways (method overriding and overloading). Abstraction: Hiding complex implementation details and showing only essential features.
-
Simple and Easy to Learn
Java was designed to be easy to learn, with a clean and straightforward syntax that eliminates many of the complex features found in other programming languages like C++ (e.g., explicit pointers, multiple inheritance).
-
Secure
Java provides a secure environment through features like:
Bytecode Verification: Ensures that bytecode is valid and does not compromise security. Security Manager: Defines security policies for the Java program, controlling what system resources a program can access. Automatic Memory Management: The garbage collector prevents memory leaks and ensures proper management of resources.
-
Robust
Java emphasizes early error checking, runtime checking, and garbage collection. It has a strong memory management model that helps in avoiding memory-related issues like null pointer dereferencing and memory leaks.
-
Multithreading
Java has built-in support for multithreading, which allows multiple threads to run concurrently. This makes Java ideal for modern, performance-sensitive applications like web servers, gaming engines, and more.
-
Rich API (Application Programming Interface)
Java has an extensive set of built-in libraries and frameworks for everything from networking and GUI development to security, data processing, and database connectivity.
-
Automatic Garbage Collection
Java automatically handles memory management by collecting and deallocating memory that is no longer in use, helping developers avoid manual memor
ChatGPT can make mistakes. Check important info. See Cookie Preferences.
We use cookies
Some cookies are essential for this site to function and cannot be turned off. We also use cookies and collect and share device identifiers to help us understand how our service performs and is used, and to support our marketing efforts. Learn more in our Cookie Policy. You can update your preferences at any time by clicking ‘Manage Cookies’
*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);
}
}
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();
}
**(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)Declaration and Initializtion
- Declaration
A declaration in Java is the process of defining a variable and specifying its type. The variable is just introduced at this point, and it has no value assigned yet.
Example:
int num; // Declaring a variable of type 'int' named 'num'
String name; // Declaring a variable of type 'String' named 'name'
- Initialization
Initialization refers to assigning a value to a declared variable. This can happen at the time of declaration or separately.
Example:
int num = 10; // Declaring and initializing the variable 'num' with value 10
String name = "John"; // Declaring and initializing the variable 'name' with value "John"
I
6) 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;
}
}
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 = "Hayes";
m.id = 101;
Developer d = new Developer();
d.name = "Arun";
d.id = 204;
System.out.println("manager "+ m.name + " (ID: " + m.id + ") Salary: " + m.calculateSalary());
System.out.println("Employee "+ d.name + " (ID: " + d.id + ") Salary: " + d.calculateSalary());
}
}
Top comments (0)