Report 126
Report 126
i
JAVA/CSE
Certificate
i
Session 2024-25
JAVA/CSE
Acknowledgement
I take this opportunity to express my deep sense of gratitude to my ITS coordinator Mr.
Hemant Mittal Assistant Professor and Ms. Kritika Assistant Professor Department of
Computer Science and Engineering, Global Institute of Technology, Jaipur, for his valuable
guidance and cooperation throughout the Practical Training work. She provided constant
encouragement and unceasing enthusiasm at every stage of the Practical Training work.
I am grateful to our respected Dr. I. C. Sharma, Principal GIT for guiding me during
Industrial Training period
I express my indebtedness to Dr. Pradeep Jha, Head of Department of Computer Science
and Engineering, Global Institute of Technology, Jaipur for providing me ample support
during my Industrial Training period.
Without their support and timely guidance, the completion of our Industrial Training would
have seemed a farfetched dream. In this respect we find ourselves lucky to have mentors of
such a great potential.
Mahi Kansal
23EGJCS126
B.Tech. III Semester, II Year, IT
ii
Session 2024-25
JAVA/CSE
Abstract
The core of the report delves into Java’s fundamental syntax, keywords, and data handling
mechanisms. It explains how Java structures its programs, manages variables, and controls
execution flow through loops and conditionals, offering illustrative examples for clarity.
Additionally, the object-oriented nature of Java is discussed, emphasizing concepts such as
inheritance, polymorphism, abstraction, and encapsulation.
Further chapters focus on practical aspects of Java development, such as exception handling
and file input/output (I/O), with real-world examples to demonstrate how developers
manage errors and interact with external data. The report concludes with two detailed Java
projects: a Guess The Number Game and a Hungama Game. These projects highlight the
application of key concepts in real-world scenarios, reinforcing the importance of
mastering Java’s robust features.
Overall, the report offers a holistic guide to understanding and implementing Java, from
basic syntax to more advanced features, making it an ideal resource for both beginners
iii
Session 2024-25
JAVA/CSE
Table of Contents
Certificate ......................................................................................................................................................ii
Acknowledgement .....................................................................................................................................iii
Abstract ......................................................................................................................................................... iv
iv
Session 2024-25
JAVA/CSE
Chapter 5. …………………………………………………………………………….31
5.1 Conclusion………………………………………………………….………..31
5.2 Reference…………………………………………………………..…....…..32
v
Session 2024-25
JAVA/CSE
List of Figures
vi
Session 2024-25
JAVA/CSE
List of Table
vii
Session 2024-25
JAVA/CSE
Chapter 1
Introduction
1. Origins (1991)
Java was conceived by James Gosling and his team at Sun Microsystems. Originally named
Oak, it was designed for interactive television but was soon recognized for broader
applications.
Oak was renamed Java and officially released as Java 1.0. The slogan “Write Once, Run
Anywhere” (WORA) emphasized its platform independence through the use of the Java
Virtual Machine (JVM).
3. Java 2 (1998)
Introduced significant enhancements, including the Swing GUI toolkit and the Collections
Framework. Java 2 was aimed at enterprise applications and further established Java’s
capabilities.
4. Java 5 (2004)
A major update that added features like generics, metadata annotations, and the enhanced
for loop. This version marked a shift towards more powerful programming constructs.
1
Session 2024 - 25
JAVA/CSE
5. Java SE 6 (2006)
6. Java SE 7 (2011)
Introduced features like the try-with-resources statement, the diamond operator for type
inference, and improved support for file I/O (NIO.2).
7. Java SE 8 (2014)
A landmark release that introduced lambda expressions, the Stream API, and the new Date
and Time API. This version significantly improved functional programming capabilities in
Java.
8. Java SE 9 (2017)
Java adopted a new release cadence with feature releases every six months. Subsequent
versions introduced features like local-variable type inference (var), improvements in
garbage collection, and new APIs.
Java remains one of the most popular programming languages, widely used in web
applications, enterprise software, mobile applications (Android), and more. Its strong
community support and extensive ecosystem of libraries and frameworks continue to drive
its development
2
Session 2024 - 25
JAVA/CSE
It is the primary language for Android development, which has a dominant share in the
mobile OS market.
2. Enterprise Solutions
Java is a go-to language for building enterprise-level applications. Many large companies
rely on Java because of its scalability, reliability, and robust ecosystem of frameworks like
Spring, Hibernate, and Java EE.
The financial services sector, including banks and insurance companies, use Java
extensively for transaction processing systems.
3
Session 2024 - 25
JAVA/CSE
3. Platform Independence
Java’s ability to run on any platform with a JVM (Java Virtual Machine) makes it highly
adaptable in the industry. This feature, "Write Once, Run Anywhere" (WORA), has
contributed to its longevity and adoption in varied environments.
4. Mature Ecosystem
Java has a rich set of APIs, libraries, and frameworks that speed up the development
process, enabling developers to build complex systems efficiently.
The Java ecosystem includes robust tools like Eclipse, IntelliJ IDEA, Maven, and Gradle,
which aid in development, debugging, and deployment.
Java has one of the largest developer communities in the world, ensuring active support,
documentation, and forums for learning and problem-solving.
The language continues to evolve with regular updates, introducing features that keep it
modern and competitive with newer languages.
6. Security
Java's built-in security features—like bytecode verification, secure class loading, and
garbage collection—make it a strong choice for building secure applications, particularly
in industries like banking, healthcare, and e-commerce.
Due to its extensive use in enterprises, Java developers are consistently in high demand.
Knowledge of Java is often a requirement for a variety of software development roles,
especially in backend systems and full-stack development.
4
Session 2024 - 25
JAVA/CSE
2. Platform Independence
Java follows the principle of "Write Once, Run Anywhere" (WORA). Programs written in
Java are compiled into bytecode, which can be run on any device equipped with a Java
Virtual Machine (JVM), regardless of the underlying platform (Windows, Mac, Linux,
etc.).
Java is designed with security features such as bytecode verification, secure class loading,
and runtime exception handling. It has automatic memory management through garbage
collection, which prevents memory leaks and other common issues found in lower-level
languages.
Java’s syntax is similar to C++ but with simpler memory management and fewer complex
features, making it easy for developers, especially those with a C/C++ background, to learn
quickly.
5. Multithreading
Java supports multithreading, which allows multiple threads to execute concurrently. This
feature is essential for building high-performance applications, especially for tasks like
processing large datasets, handling multiple network requests, or performing background
tasks.
5
Session 2024 - 25
JAVA/CSE
6. High Performance
Java's performance is enhanced through Just-In-Time (JIT) compilation. The JIT compiler
converts Java bytecode into machine code at runtime, speeding up execution by allowing
frequently used parts of the code to be optimized for performance.
7. Distributed Computing
Java has built-in support for developing distributed applications. Technologies like Remote
Method Invocation (RMI) and CORBA (Common Object Request Broker Architecture)
make it easier to build applications that can run across multiple machines connected by a
network.
Java is designed to be dynamic, which means it can adapt to evolving environments. New
classes, methods, and libraries can be added without affecting existing applications. The
dynamic class loading mechanism and runtime information gathering further enhance this
flexibility.
9. Rich API
Java uses an automatic garbage collection mechanism, which means developers don’t have
to manually manage memory allocation and deallocation. This reduces the risk of memory
leaks and makes Java applications more reliable.
6
Session 2024 - 25
JAVA/CSE
Chapter 2
2.1Basic Syntax
Structure of a Java Program: Explain the basic structure of a Java program, including the
placement of classes, methods, and the `main()` method.
Example:
System.out.println("Hello, World!");
Explanation:
`public class HelloWorld`: Every Java program must have at least one class.
7
Session 2024 - 25
JAVA/CSE
public static void main(String[] args)`: The `main` method is the entry point of the program.
Curly Braces `{}`: Used to define a block of code. Every method and class must use curly
braces.
Java has a set of reserved words, or keywords, that have predefined meanings in the
language. These cannot be used as identifiers (variable names, method names, etc.).
Common Keywords:
Control Flow Statements: `if`, `else`, `switch`, `case`, `while`, `do`, `for`, `break`,
`continue`
Example:
8
Session 2024 - 25
JAVA/CSE
Java is a statically typed language, meaning all variables must be declared with a data type
before they can be used.
Example:
Reference Data Types: Objects, arrays, and more complex structures are stored as
references to memory locations.
9
Session 2024 - 25
JAVA/CSE
Variable Declaration: Variables in Java must be declared with a type before use, and you
can optionally initialize them.
Example:
int number;
2.4 Operators
10
Session 2024 - 25
JAVA/CSE
Example:
int x = 5;
int y = 10;
Java provides various control flow mechanisms to manage the execution of code.
Conditional Statements:
Example:
if (x > 0) {
System.out.println("x is positive");
} else {
System.out.println("x is non-positive");
Example:
int day = 3;
switch(day) {
case 1:
System.out.println("Sunday");
11
Session 2024 - 25
JAVA/CSE
break;
case 2:
System.out.println("Monday");
break;
default:
System.out.println("Other Day");
Loops:
System.out.println(i);
12
Session 2024 - 25
JAVA/CSE
2.6 Arrays
Arrays in Java are objects that store multiple values of the same type. The size of an array
is fixed once it is created.
System.out.println(num);
2.7 Methods
Methods in Java are blocks of code that perform a specific task. Every Java program must
have at least one method, which is `main()`. Methods can accept parameters and return
values.
Method Declaration:
return a + b;
Method Invocation:
13
Session 2024 - 25
JAVA/CSE
2.8 Comments
Example:
Java uses classes like `Scanner` to take user input and `System.out` for output.
Example of Input:
import java.util.Scanner;
14
Session 2024 - 25
JAVA/CSE
Chapter 3
Class Definition: Explain what a class is and how it serves as a blueprint for creating
objects.
Example
String brand;
int year;
System.out.println("Engine started");
15
Session 2024 - 25
JAVA/CSE
Object Creation: Demonstrate how to create an object from a class and access its members.
Example:
myCar.brand = "Toyota";
3.2 Encapsulation
Definition: Encapsulation is the practice of wrapping the data (variables) and code
(methods) together as a single unit and restricting direct access to some of an object’s
components.
Example:
return name;
this.name = name;
16
Session 2024 - 25
JAVA/CSE
3.3 Inheritance
Definition: Inheritance allows a class to inherit properties and behaviors from another class.
Example:
System.out.println("Animal sound");
System.out.println("Bark");
Super Keyword: Show how the `super` keyword is used to access members of the parent
class.
Example:
17
Session 2024 - 25
JAVA/CSE
System.out.println("Bark");
3.4 Polymorphism
Example (Overloading):
return a + b;
return a + b;
Example (Overriding):
System.out.println("Animal sound");
18
Session 2024 - 25
JAVA/CSE
@Override
System.out.println("Meow");
Example (Upcasting):
3.5 Abstraction
Definition: Abstraction allows us to define the essential qualities of an object while hiding
the implementation details.
Abstract Classes: A class that cannot be instantiated and may contain abstract methods.
Example:
19
Session 2024 - 25
JAVA/CSE
System.out.println("Bark");
Interfaces: Explain how interfaces achieve full abstraction by defining method signatures
that must be implemented by a class.
Example:
interface Animal {
void sound();
System.out.println("Bark");
Abstract classes can have defined methods and instance variables, while interfaces cannot.
2.6 Constructors
String brand;
20
Session 2024 - 25
JAVA/CSE
this.brand = brand;
Constructor Overloading: Show how multiple constructors can be created for flexibility.
Example:
String brand;
int year;
this.brand = brand;
this.brand = brand;
this.year = year;
21
Session 2024 - 25
JAVA/CSE
Definition: The `this` keyword refers to the current object within an instance method or
constructor.
Example:
22
Session 2024 - 25
JAVA/CSE
Chapter 4
Exception Handling and File Input/Output (I/O)
What is an Exception?
Checked Exceptions
Explain why handling exceptions is critical to avoid program crashes and ensure graceful
failure in scenarios like file not found, invalid user input, etc.
Example:
try {
23
Session 2024 - 25
JAVA/CSE
} catch (ArithmeticException e) {
} finally {
Multiple Catch Blocks: Explain how multiple catch blocks can be used to handle different
types of exceptions.
Example:
try {
} catch (ArithmeticException e) {
System.out.println("ArithmeticException caught.");
} catch (ArrayIndexOutOfBoundsException e) {
24
Session 2024 - 25
JAVA/CSE
Throw Keyword: Show how exceptions can be thrown manually using the `throw`
keyword.
Example:
} else {
System.out.println("Age is valid.");
validateAge(16);
Defining a Custom Exception: Explain how to create your own exceptions by extending
the `Exception` or `RuntimeException` class.
Example:
25
Session 2024 - 25
JAVA/CSE
super(message);
try {
} catch (CustomException e) {
Introduction: Explain why File I/O is essential for interacting with external files and data
sources.
File Class: Introduce the `java.io.File` class for working with file paths and checking file
properties.
Example:
import java.io.File;
26
Session 2024 - 25
JAVA/CSE
if (file.exists()) {
} else {
Using `FileReader` and `BufferedReader`: Introduce the classes used to read text from files.
Example:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
try {
String line;
System.out.println(line);
27
Session 2024 - 25
JAVA/CSE
reader.close();
} catch (IOException e) {
Example:
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
try {
writer.close();
catch (IOException e) {
28
Session 2024 - 25
JAVA/CSE
Reading Files with Scanner: `Scanner` can also be used for file input, often with simpler
syntax for basic needs.
Example:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
try {
while (sc.hasNextLine()) {
System.out.println(data);
sc.close();
} catch (FileNotFoundException e) {
29
Session 2024 - 25
JAVA/CSE
Example
try {
} catch (FileNotFoundException e) {
30
Session 2024 - 25
JAVA/CSE
Chapter 5
Conclusion
In conclusion, this report has explored the fundamental aspects of Java programming,
starting with a brief introduction to its importance and versatility. We delved into the basics,
laying a strong foundation in understanding Java syntax, data types, control structures, and
functions. Building on this, the Object-Oriented Programming (OOP) principles were
examined, highlighting the concepts of encapsulation, inheritance, polymorphism, and
abstraction, which are the cornerstones of Java's architecture.
The two projects included in this report served as practical implementations of these
concepts, demonstrating how theoretical knowledge can be applied to solve real-world
problems. Through these projects, we have seen how Java's robust features, including its
platform independence and extensive libraries, make it an excellent choice for developing
scalable and efficient software.
31
Session 2024 - 25
JAVA/CSE
Reference
General Java References:
Java: The Complete Reference" by Herbert Schildt
A comprehensive guide to Java, covering both the basics and advanced topics, including
OOP.
Head First Java" by Kathy Sierra & Bert Bates
This book explains Java concepts in a beginner-friendly manner, ideal for understanding
the fundamentals.
Basics of Java:
Oracle Java Documentation
Oracle provides official documentation for Java, covering everything from setup to
advanced programming.
Link: [https://docs.oracle.com/javase/tutorial/](https://docs.oracle.com/javase/tutorial/)
GeeksforGeeks Java Tutorials
A great online resource with explanations and examples for beginners in Java.
Link: [https://www.geeksforgeeks.org/java/](https://www.geeksforgeeks.org/java/)
bject-Oriented Programming (OOP):
Effective Java" by Joshua Bloch
Focuses on best practices in Java programming, including OOP principles.
Design Patterns: Elements of Reusable Object-Oriented Software" by Erich Gamma et al.
A must-read for understanding how OOP concepts can be applied in Java.
Projects:
Java SE Development Kit (JDK) Documentation
Official documentation on using the JDK to build and run Java projects.
Link: [https://docs.oracle.com/javase/8/docs/](https://docs.oracle.com/javase/8/docs/)
32
Session 2024 - 25