SOFT
SOFT
Page no:
JAVA INTRODUCTION:
Java is a class-based, object-oriented programming language that is designed to have as few
implementation dependencies as possible. It is intended to let application developers write once, and run
anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the
need for recompilation. Java was first released in 1995 and is widely used for developing applications for
desktop, web, and mobile devices. Java is known for its simplicity, robustness, and security features, making it a
popular choice for enterprise-level applications.
Java was developed by James Gosling at Sun Microsystems Inc in May 1995 and later acquired by Oracle
Corporation. It is a simple programming language. Java makes writing, compiling, and debugging programming
easy. It helps to create reusable code and modular programs. Java is a class-based, object-oriented programming
language and is designed to have as few implementation dependencies as possible. A general-purpose
programming language made for developers to write once run anywhere that is compiled Java code can run on all
platforms that support Java. Java applications are compiled to byte code that can run on any Java Virtual
Machine. The syntax of Java is similar to C/C++.
HISTORY OF JAVA:
Java’s history is as interesting as it is impactful. The journey of this powerful programming
language began in 1991 when James Gosling, Mike Sheridan, and Patrick Naughton, a team of engineers at Sun
Microsystems known as the “Green Team,” set out to create a new language initially called “Oak.” Oak was later
renamed Java, inspired by Java coffee, and was first publicly released in 1996 as Java 1.0. This initial version
provided a no-cost runtime environment across popular platforms, making it accessible to a broad
audience. Arthur Van Hoff rewrote the Java 1.0 compiler to strictly comply with its specifications, ensuring its
reliability and cross-platform capabilities.
Features of Java:
1. Platform Independent
2. Object-Oriented Programming
3. Simplicity
4. Robustness
5. Security
6. Distributed
7. Multithreading
8. Portability
9. High Performance
JDK IN JAVA:
The Java Development Kit (JDK) is a cross-platformed software development environment that offers a
collection of tools and libraries necessary for developing Java-based software applications and applets. It is a
core package used in Java, along with the JVM (Java Virtual Machine) and the JRE (Java Runtime Environment).
Beginners often get confused with JRE and JDK, if you are only interested in running Java programs on your
machine then you can easily do it using Java Runtime Environment. However, if you would like to develop a
Java-based software application then along with JRE you may need some additional necessary tools, which is
called JDK.
JDK=JRE+Development Tools
JAVA DATATYPES:
float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits
double 8 bytes Stores fractional numbers. Sufficient for storing 15 to 16 decimal digits
S.
No. PATH CLASSPATH
An environment variable is used by the operating An environment variable is used by the Java
1.
system to find the executable files. compiler to find the path of classes.
}
Output:
C:\23-518>javac DataType.java
C:\23-518>java DataType
The default values of primitive data types are:
Byte :0
Short :0
Int :0
Long :0
Float :0.0
Double :0.0
Char :
Boolean :false
Result:
Hence, the program to display the default value of all primitive data type
of JAVA executed successfully.
Sample Output:
C:\23-515>javac quardraticformula.java
C:\23-515>java quadraticformula
Given quadratic equation:ax^2 + bx + c
Enter a:2
Enter b:3
Enter c:1
Roots are real and unequal
First root is:-0.5
Second root is:-1.0
Executed Output:
C:\23-515>javac quardraticformula.java
C:\23-515>java quadraticformula
Given quadratic equation: ax^2 + bx + c
Enter a: 1
Enter b: -3
Enter c: 2
Roots are real and unequal
First root is: 2.0
Second root is: 1.0
Result:
Hence, the program to display the roots of a quadratic equation
ax2+bx=0 executed successfully.
scanner.close( );
}
public static int binarySearch(int[] array, int target)
{
int low = 0;
int high = array.length - 1;
Sample Output:
C:\23-515>javac BinarySearch.java
C:\23-515>java BinarySearch
Enter the number of elements in the array: 5
Enter the elements of the array :
1
3
5
7
9
Enter the value to search for: 5
Element found at index: 2
Executed Output:
C:\23-515>javac BinarySearch.java
C:\23-515>java BinarySearch
Enter the number of elements in the array: 6
Enter the elements of the array :
10
20
30
40
50
60
Enter the value to search for: 25
Element not found in the array.
Result:
Hence, the program to search for an element in a given list of elements
using binary search mechanism has been executed successfully.
Output:
C:\23-515>javac BubbleSort.java
C:\23-515>java BubbleSort
Enter the number of elements:
5
Enter 5 elements:
64
34
25
12
22
Sorted Array:
12
22
25
34
64
Result:
Hence, the program to sort for an element in a given list of elements
using bubble sort executed successfully.
Result:
Hence, the program to write a program to StringBuffer to delete, remove
character executed successfully.
Sample Output:
C:\23-515>javac Calculator1.java
C:\23-515>java Calculator1
Enter any Two values :
10
5
Addition of 10 and 5: 15
Subtraction of 10 and 5: 5
Multiplication of 10 and 5: 50
Division of 10 and 5: 2.0
Executed Output:
Enter any Two values :
8
0
Addition of 8 and 0: 8
Subtraction of 8 and 0: 8
Multiplication of 8 and 0: 0
Error: Division by zero is not allowed.
Division of 8 and 0: 0.0
Result:
Hence, the program To implement class mechanism. Create a class,
methods and invoke them inside main method executed successfully.
Output:
C:\23-515>javac MethodOverloading1.java
C:\23-515>java MethodOverloading1
Sum of two integers: 35
Sum of two doubles: 32.0
Sum of three integers: 60
Result:
Hence, the program to implement method overloading executed
successfully.
this.age = age;
System.out.println("Parameterized constructor called");
}
public Person(Person p)
{
this.name = p.name;
this.age = p.age;
System.out.println("Copy Constructor called");
}
public void display( )
{
System.out.println("Name: " + name +" \t" +", Age: " + age);
}
}
Result:
Hence, the program to implement constructor executed successfully.
Output:
C:\23-515>javac ConstructorOverloading.java
C:\23-515>java ConstructorOverloading
Default Constructor called
Name: Praveena , Age: 0, Course: Not Enrolled
Constructor with two parameters called
Name: Charitha , Age: 5, Course: Not Enrolled
Constructor with three parameters called
Name: Bobby , Age: 22, Course: Computer Science
Result:
Hence, the program to implement constructor overloading executed
successfully.
Output:
C:\23-515>javac Multilevel Inheritance.java
C:\23-515>java Multilevel Inheritance
Value of a is 100
Inside ChildChildClass!"
Result:
Hence, the program to implement multi-level inheritance executed
successfully.
{
this.base = base;
this.height = height;
}
@Override
double calculateArea()
{
return 0.5 * base * height;
}
}
public class AbstractClass
{
public static void main(String[] args)
{
// Creating objects of different shapes
Shape circle = new Circle(5);
Shape rectangle = new Rectangle(4, 6);
Shape triangle = new Triangle(3, 8);
System.out.println("Area of Circle: " + circle.calculateArea());
System.out.println("Area of Rectangle: " +
rectangle.calculateArea());
System.out.println("Area of Triangle: " + triangle.calculateArea());
}
}
Output:
C:\23-515>javac AbstractClass.java
C:\23-515>java AbstractClass
Area of Circle: 78.53981633974483
Area of Rectangle: 24.0
Area of Triangle: 12.0
Result:
Hence, the write a program for abstract class to find areas of different
shapes executed successfully.
class SuperDemo
{
public static void main(String[] args)
{
Student s = new Student( );
}
}
Output:
C:\23-515>javac SuperDemo.java
C:\23-515>java SuperDemo
Person class Constructor
Student class Constructor
Result:
Hence, the program to implement “super” keyword executed successfully.
Output:
C:\23-515>javac RuntimePolymorphism.java
C:\23-515>java RuntimePolymorphism
Dog barks
Cat meows
Result:
Hence, the program to implement runtime polymorphism executed
successfully.
Output:
C:\23-515>javac Main.java
C:\23-515>java Main
Enter weight: 15
You are ready to fly!
Enter weight: 45
Weight limit exceeded by 30 kg.
Result:
Hence, the program to implement exception handling mechanism has
been executed successfully.
try {
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
int result = num1 / num2;
System.out.println("Result: " + result);
}
catch (ArithmeticException e) {
System.out.println("Error: Division by zero is not allowed.");
}
catch (java.util.InputMismatchException e) {
System.out.println("Error: Please enter valid integers.");
}
catch (Exception e) {
System.out.println("Error: An unexpected error occurred: " +
e.getMessage());
}
finally {
scanner.close();
}
}
}
Output:
C:\23-515>javac MultipleCatchExample.java
C:\23-515>java MultipleCatchExample
Enter two integers to divide:
10
2
Result: 5
Result:
Hence, the program to illustrate multiple catch clauses has been
executed successfully.
Program code:
package week6;
public class BuiltInExceptionsExample {
public static void main(String[] args) {
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("ArithmeticException: Division by zero is not
allowed.");
}
try {
String str = null;
System.out.println(str.length());
} catch (NullPointerException e) {
System.out.println("NullPointerException: Attempted to access a
method on a null object.");
}
try {
int[] arr = new int[5];
System.out.println(arr[10]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("ArrayIndexOutOfBoundsException: Index is
out of bounds.");
}
try {
Class.forName("com.example.NonExistentClass");
} catch (ClassNotFoundException e) {
System.out.println("ClassNotFoundException: The specified class
was not found.");
}
}
}
Output:
C:\23-515>javac BuiltInExceptionsExample.java
C:\23-515>java BuiltInExceptionsExample
Result:
Hence, the program to create java built-in exceptions has been executed
successfully.
try {
checkAge(200);
} catch (InvalidAgeException e) {
System.out.println("Caught exception: " + e.getMessage());
}
}
}
Output:
C:\23-515>javac UserDefinedExceptionDemo
C:\23-515>java UserDefinedExceptionDemo
Age is valid: 25
the second thread displays “Hello “every 2 seconds and the third
display “Welcome” every 3 seconds, (Repeat the same by
implementing Runnable).
Aim: To write a program to create threads by extending thread class.
Program code:
package week7;
import java.util.Scanner;
class MessageRunnable implements Runnable {
private String message;
private int interval;
private int count;
public MessageRunnable(String message, int interval, int count) {
this.message = message;
this.interval = interval;
this.count = count;
}
public void run() {
for (int i = 0; i < count; i++) {
try {
Thread.sleep(interval);
System.out.println(message);
} catch (InterruptedException e) {
System.out.println(message + " Thread interrupted");
}
}
}
}
thread3.start();
scanner.close();
}
}
Output:
C:\23-515>javac RunnableExample.java
C:\23-515>java RunnableExample
Enter the limit for how many times to print each message: 2
Good Morning
Hello
Good Morning
Welcome
Hello
Welcome
Result:
Hence, the program to create threads by extending thread class has been
executed successfully.
Output:
C:\23-515>javac ThreadDemo.java
C:\23-515>java ThreadDemo
Enter the number of threads to create: 2
Thread-0 is starting.
Thread-1 is starting.
Is Thread-0 alive? true
Is Thread-1 alive? true
Thread-0 has finished.
Thread-1 has finished.
Thread-0 has completed execution.
Thread-1 has completed execution.
All threads have completed execution.
Executed Output:
Enter the number of threads to create: 3
Thread-0 is starting.
Thread-1 is starting.
Thread-2 is starting.
Is Thread-0 alive? true
Is Thread-1 alive? true
Is Thread-2 alive? true
Thread-0 has finished.
Thread-1 has finished.
Thread-2 has finished.
Thread-0 has completed execution.
Thread-1 has completed execution.
Thread-2 has completed execution.
All threads have completed execution.
Result:
Hence, the program to illustrate isAlive and join() has been executed
successfully.
}
System.out.println("Main thread is exiting.");
scanner.close();
}
}
Output:
C:\23-515>javac DaemonThreadExample.java
C:\23-515>java DaemonThreadExample
Enter the number of iterations for the main thread: 5
Main thread is running: 0
Daemon thread is running: 0
Main thread is running: 1
Daemon thread is running: 1
Main thread is running: 2
Daemon thread is running: 2
Main thread is running: 3
Daemon thread is running: 3
Main thread is running: 4
Daemon thread is running: 4
Main thread is exiting.
Result:
Hence, the program to illustrate Daemon threads has been executed
successfully.
this.itemsToProduce = itemsToProduce;
}
@Override
public void run() {
for (int i = 0; i < itemsToProduce; i++) {
try {
buffer.produce(i);
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}
class Consumer extends Thread {
private final Buffer buffer;
private final int itemsToConsume;
public Consumer(Buffer buffer, int itemsToConsume) { this.buffer =
buffer;
this.itemsToConsume = itemsToConsume;
}
@Override
public void run() {
for (int i = 0; i < itemsToConsume; i++) { try {
buffer.consume(); Thread.sleep(150);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}
public class ProducerConsumerDemo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of items to produce: ");
int itemsToProduce = scanner.nextInt();
System.out.print("Enter the number of items to consume: ");
int itemsToConsume = scanner.nextInt();
Buffer buffer = new Buffer(5);
Producer producer = new Producer(buffer, itemsToProduce);
rs.close();
stmt.close();
con.close();
}
catch (Exception e)
{
System.out.println("Error: " + e.getMessage());
}
}
}
Output:
Result:
Hence, the program To implement Java Program for to connect to MYSQL
and display the Table has been executed successfully.
while (rs.next())
{
String ID = rs.getString("ID");
String Name = rs.getString("Name");
System.out.println(ID + "\t" + Name);
}
rs.close();
st.close();
con.close();
} catch (Exception e)
{
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}
}
}
Output:
Result:
Hence, the program to connect MS Access with Insert values in to it with
using IDE has been executed Successfully.
con.close();
}
catch (ClassNotFoundException e)
{
System.out.println("JDBC Driver not found!");
e.printStackTrace();
} catch (SQLException e)
{
System.out.println("Connection failed!");
e.printStackTrace();
}
}
}
Output:
C:\23-518>javac OracleConnect.java
C:\23-518>java OracleConnect
Connection successful!
Successfully deleted 2 record(s).
3 Chary 65000 IT
2 Sunil 70000 CSE
Result:
Hence, the program to connect Oracle with Insert values in to it without
using IDE has been executed Successfully.
PROJECT TITTLE :
A basic console-based To-Do List where users can add, view, and remove
tasks. The tasks are stored in a list, and the user interacts with the app
via a simple text menu.
PROJECT DESCRIPTION :
The To-Do List application is designed for users who need a
straightforward and easy way to track and manage their daily tasks
without a graphical user interface. It runs entirely in the console, making
it lightweight and simple to use. The tasks are stored in a list (usually in
memory or a simple text file), and users can interact with the program by
typing commands into a text-based menu.
Team Members:
K V. NANDA PRIYA(23191A0507)
S. PRAVEENA(23191A0515)
Roles of TeamMembers:
K V. NANDA PRIYA -Project researcher
S. PRAVEENA -Debug the code
Aim:
The aim of a basic console-based To-Do List application is to provide users
with a simple, text-based tool for managing their tasks and improving
their productivity.
Program:
import java.util.ArrayList;
import java.util.Scanner;
public class TodoApp
private static ArrayList<String> todoList = new ArrayList<>();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("\n------ To-Do List App ------");
System.out.println("1. Add a Task");
}
}
private static void removeTask(Scanner scanner) {
if (todoList.isEmpty()) {
System.out.println("No tasks to remove.");
return;
}
System.out.print("Enter the task number to remove: ");
int taskNumber = scanner.nextInt();
scanner.nextLine();
if (taskNumber > 0 && taskNumber <= todoList.size()) {
todoList.remove(taskNumber - 1);
System.out.println("Task removed successfully.");
} else {
System.out.println("Invalid task number!");
}
}
}
OUTPUT:
Result:
FUTURE SCOPE:
The future scope of the basic console-based To-Do List app includes
features like task categorization, due dates, reminders, cloud syncing,
collaboration, mobile apps, and AI-driven task prioritization to enhance
functionality and user experience.
CONCLUSION:
In conclusion, the basic console-based To-Do List app provides a simple
yet effective way for users to manage their tasks, and with the addition of
features like data persistence, categorization, reminders, cloud syncing,
and AI enhancements, it can evolve into a more powerful and versatile
tool for personal productivity and collaboration. Its scalability and
potential for integration with other platforms make it an ideal foundation
for future development.