Java Task Solutions – Day 1 (Theory +
Programs)
This document covers Day 1 of the uploaded "Java Task.pdf": Java Introduction,
Class/Method/Object, and Same/Different package. It provides concise theory answers and
complete Java programs with different approaches and expected outputs. Questions are
included verbatim as in the PDF.
Day 1 – Theory Questions and Answers
Q1. What is Java?
Answer: Java is an object-oriented, class-based, strongly typed programming language and
platform. It compiles to bytecode that runs on the Java Virtual Machine (JVM).
Q2. Why we go for Java?
Answer: Portability (write once, run anywhere), strong standard library, OOP features,
automatic memory management (GC), rich tooling & ecosystem, and strong community.
Q3. Tell me the features of Java
Answer: Object-oriented, Platform-independent (via JVM), Robust (exception handling, GC),
Secure (sandboxing, bytecode verifier), Multithreaded, Distributed, High performance (JIT).
Q4. Why Java is platform independent?
Answer: The Java compiler produces bytecode (.class) that runs on any JVM implementation
for any OS/CPU, so the same program works across platforms.
Q5. Explain JDK, JVM, JRE?
Answer: JDK: developer kit (compiler, tools, JRE). JRE: runtime (JVM + core libraries). JVM:
engine that loads, verifies, and executes bytecode.
Q6. Explain standard Notation
Answer: Follow Java naming & package conventions: packages lowercase (org.example),
classes PascalCase (StudentInfo), methods camelCase (stuName), constants
UPPER_SNAKE_CASE.
Q7. Explain OOPS?
Answer: Four pillars: Encapsulation (data hiding via classes), Inheritance (code reuse),
Polymorphism (same interface, many forms), Abstraction (essential features, hide details).
Q8. Explain class, methods, object
Answer: Class: blueprint; Method: behavior/function; Object: runtime instance with state +
behavior created from a class.
Q9. What is the syntax of object creation?
Answer: ClassName ref = new ClassName(); // calls zero-arg constructor
Q10. What is the syntax of import?
Answer: import packageName.ClassName; or import packageName.*;
Day 1 – Program Questions with Solutions
Q1. Project : StudentDetails
Package : org.stu
Class : StudentInfo
Methods : stuId(), stuName(), stuDob(), stuPhoneNumber(), stuEmail(), stuAddress()
Description:
Create an object for StudentInfo class and call above methods also follow all coding
standards.
➤ Method A: Simple printer methods (void)
package org.stu;
public class StudentInfo {
public void stuId() { System.out.println("ID : 1024"); }
public void stuName() { System.out.println("Name : Anitha"); }
public void stuDob() { System.out.println("DOB : 2001-05-21"); }
public void stuPhoneNumber() { System.out.println("Phone:
9876543210"); }
public void stuEmail() { System.out.println("Email:
[email protected]"); }
public void stuAddress() { System.out.println("Addr : 12, Gandhi St,
Chennai"); }
public static void main(String[] args) {
StudentInfo s = new StudentInfo();
s.stuId();
s.stuName();
s.stuDob();
s.stuPhoneNumber();
s.stuEmail();
s.stuAddress();
Expected Output:
ID : 1024
Name : Anitha
DOB : 2001-05-21
Phone: 9876543210
Email: [email protected]
Addr : 12, Gandhi St, Chennai