Chinmay Sharma Core Java File
Chinmay Sharma Core Java File
Applications of Java:
Java is used in web apps, mobile apps, desktop software, games, and
enterprise applications.
Java API:
Java API is a library of prewritten packages, classes, and interfaces with
reusable functions.
Byte Code:
Byte code is the intermediate code generated after Java compilation,
executed by the JVM.
Section B: Short Answer Type (Limit: 100 Words)
Q1 - Define the term JDK, JRE and JVM?
Java Features:
Java is platform-independent, object-oriented, simple, secure, robust,
architecture-neutral, portable, high-performance, multithreaded, and
dynamic.
These features make it suitable for a variety of applications across different
platforms.
Each stage ensures the code is efficient, secure, and portable across platforms.
Expressions:
Examples:
Branching Statements:
java
CopyEdit
if (age >= 18) {
System.out.println("Eligible to vote");
}
java
CopyEdit
if (score >= 90) {
System.out.println("Grade A");
} else if (score >= 75) {
System.out.println("Grade B");
} else {
System.out.println("Grade C");
}
java
CopyEdit
switch (day) {
case 1: System.out.println("Monday"); break;
case 2: System.out.println("Tuesday"); break;
default: System.out.println("Invalid Day");
}
Looping Statements:
java
CopyEdit
for (int i = 1; i <= 5; i++) {
System.out.println(i);
}
java
CopyEdit
int i = 1;
while (i <= 5) {
System.out.println(i);
i++;
}
java
CopyEdit
int i = 1;
do {
System.out.println(i);
i++;
} while (i <= 5);
These statements provide decision-making and repetition capabilities, which are essential
for efficient, logical, and real-world program flow.
1. Abstraction:
Abstraction is the concept of hiding internal details and showing only essential features.
Abstract Classes: Classes declared with the abstract keyword may have abstract
methods (no body) and regular methods.
java
CopyEdit
abstract class Animal {
abstract void sound();
}
Interfaces: All methods are abstract by default. They allow multiple classes to
implement the same behavior differently.
java
CopyEdit
interface Shape {
void draw();
}
2. Encapsulation:
Encapsulation is the process of wrapping data and code into a single unit (class) and
restricting access to some components.
By making variables private and providing public getter and setter methods.
java
CopyEdit
class Student {
private String name;
Encapsulation ensures:
Summary:
Together, abstraction and encapsulation form the backbone of robust, secure, and
maintainable Java applications.