Java File
Java File
(CIE-306P)
VISION
"To attain global excellence through education, innovation, research, and work ethics in
the field of Computer Science and engineering with the commitment to serve humanity."
MISSION
M1: To lead in the advancement of computer science and engineering through
internationally recognized research and education.
M2 To prepare students for full and ethical participation in a diverse society and
encourage lifelong learning.
M3 To foster development of problem solving and communication skills as an integral
component of the profession.
M4 To impart knowledge, skills and cultivate an environment supporting incubation,
product development, technology transfer, capacity building and entrepreneurship in the
field of computer science and engineering.
M5 To encourage faculty, student’s networking with alumni, industry, institutions, and
other stakeholders for collective engagement.
Rubrics for Lab Assessment:
Rubrics 10 Marks POs and PSOs Covered
2M 2M 2M 2M 2M
AIM: Introduction to Eclipse IDE for Enterprise Java Developers and Web Developers.
Eclipse IDE stands out as a popular open-source and free Integrated Development Environment (IDE),
particularly favored by both enterprise Java and web developers. Its extensive features streamline coding,
debugging, and testing processes. The IDE's extensibility, robust community support, and a vast plugin
ecosystem make it a staple in the enterprise domain.
For enterprise Java development, which often involves constructing large-scale applications using
frameworks like Spring, Hibernate, and Java EE (Jakarta EE), Eclipse IDE offers a suite of powerful
tools and seamless integrations:
1. Java Development Tools (JDT): These provide the core functionalities for Java development,
encompassing a code editor, compiler, debugger, and refactoring capabilities. JDT supports Java
SE (Standard Edition), making it suitable for developing standalone applications, libraries, and
command-line tools.
2. Enterprise Java Frameworks: Eclipse exhibits excellent integration with Java EE (Jakarta EE)
frameworks, empowering developers to build enterprise-grade applications such as web
applications, microservices, and backend systems. Furthermore, dedicated plugins for frameworks
like Spring, Hibernate, and JavaFX offer advanced features like intelligent code completion,
real-time validation, and deployment utilities.
5. Database Tools: Eclipse incorporates database management tools that allow developers to
connect to, query, and modify databases without leaving the IDE. This feature proves invaluable
for enterprise applications that rely on persistent data storage.
Beyond enterprise Java development, Eclipse IDE also provides a strong foundation for web
development, assisting developers in creating dynamic and responsive websites, single-page applications
(SPAs), and REST APIs:
1. HTML, CSS, and JavaScript Editing: Eclipse offers comprehensive support for editing core
web technologies like HTML, CSS, and JavaScript, complete with syntax highlighting, code
completion, and error detection. The IDE's capabilities extend to supporting modern front-end
frameworks such as Angular, React, and Vue.js through plugins or additional tooling.
2. Web Framework Support: Eclipse integrates seamlessly with popular Java-based web
frameworks like Spring MVC, JavaServer Faces (JSF), and JavaServer Pages (JSP). Moreover, it
provides integration with contemporary web development tools like Node.js, npm, and Yeoman,
enabling the creation of cutting-edge front-end applications.
Here are the steps to install Eclipse IDE for Enterprise Java and Web Developers:
● After successfully installing the JDK, proceed to download the Eclipse IDE.
● Run the downloaded Eclipse installer file.
Step 3: Choose Installation Package
● In the installer, select the option "Eclipse IDE For Enterprise Java and Web Developers."
● Visit the Apache Tomcat website and download the latest version of Tomcat.
● Extract the downloaded archive to a directory on your computer.
● Ensure that the JDK is installed on your system. If not, download and install it as described in the
installation steps.
● In Eclipse, navigate to Window > Preferences.
● In the Preferences dialog, expand the Java section and select Installed JREs.
● Click the Add button, choose Standard VM, and click Next.
● In the JRE home field, browse to the directory where you installed the JDK. Click Finish.
● Ensure the newly added JDK is selected as the default JRE.
● If you need to modify Tomcat's settings, you can right-click on the Tomcat server in the Servers
view and select Properties.
● When working with dynamic web projects, ensure the "Dynamic Web Project" nature is enabled
for your project. You can create a new one via File > New > Dynamic Web Project and then
deploy it to your configured Tomcat server.
Program-1.2
Aim:- Write a program in java to concatenate two strings using command line.
Code:-
Output:
Program-1.3
Aim:- Create a class Box that uses a parameterized constructor to initialize the dimensions
of a box. The dimensions of the Box are width, height, depth. The class should have a
method that can return the volume of the box. Create an object of the Box class and test
the functionalities.(Inheritance)
Code:-
package week1_1;
class Box {
double width;
double height;
double depth;
Box(double width, double height, double depth) {
this.width = width;
this.height = height;
this.depth = depth;}
double volume() {
return width * height * depth;}}
Output:
Program-1.4
Aim:- Create a base class Fruit which has name ,taste and size as its attributes. A method
called eat() is created which describes the name of the fruit and its taste. Inherit the same
in 2 other class Apple and Orange and override the eat() method to represent each fruit
taste. (Method overriding)
Code:-
package week1_1;
class Fruit {
String name, taste, size;
Fruit(String n, String t, String s) { name = n; taste = t; size = s;
}
void eat() { System.out.println("The " + name + " tastes " + taste +
"."); }
}
Output:
Program – 1.5
Aim:- Write a program to create a class named shape. It should contain 2 methods-
draw() and erase() which should print “Drawing Shape” and “Erasing Shape” respectively.
For this class we have three subclasses- Circle, Triangle and Square and each class
overrides the parent class functions- draw () and erase (). The draw() method should print
“Drawing Circle”, “Drawing Triangle”, “Drawing Square” respectively. The erase()
method should print “Erasing Circle”, “Erasing Triangle”, “Erasing Square” respectively.
Create objects of Circle, Triangle and Square in the following way and observe the
polymorphic nature of the class by calling draw() and erase() method using each object.
Shape c=new Circle(); Shape t=new Triangle(); Shape s=new Square(); (Polymorphism)
Code:-
package week1_1;
class Shape {
void draw() { System.out.println("Drawing Shape"); }
void erase() { System.out.println("Erasing Shape"); }}
class Circle extends Shape {
void draw() { System.out.println("Drawing Circle"); }
void erase() { System.out.println("Erasing Circle"); }}
class Triangle extends Shape {
void draw() { System.out.println("Drawing Triangle"); }
void erase() { System.out.println("Erasing Triangle"); }}
class Square extends Shape {
void draw() { System.out.println("Drawing Square"); }
void erase() { System.out.println("Erasing Square"); }}
public class Main {
public static void main(String[] args) {
Shape[] shapes = { new Circle(), new Triangle(), new Square() };
for (Shape shape : shapes) {
shape.draw();
shape.erase();}}}
Output :
Program – 1.6
Aim:- Write a Program to take care of Number Format Exception if user enters values
other than integer for calculating average marks of 2 students. The name of the students
and marks in 3 subjects are taken from the user while executing the program. In the same
Program write your own Exception classes to take care of Negative values and values out
of range (i.e. other than in the range of 0-100) (Exception Handling)
Code:-
package week1_1;
import java.util.Scanner;
Output:-
Program – 2.1
Code:
package project1;
class MyThread extends Thread {
private final String name;
MyThread(String name) {
this.name = name;}
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println(name + " - iteration: " + i);
try {Thread.sleep(500);}
catch (InterruptedException e) {
System.out.println(name + " interrupted");}}
System.out.println(name + " finished.");}}
public class MultiThreadingExample {
public static void main(String[] args) {
Thread t1 = new MyThread("Thread 1");
Thread t2 = new MyThread("Thread 2");
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedException e) {
System.out.println("Main thread interrupted");
}
System.out.println("All threads completed.");
}}
Output :
Program – 2.2
Code:
package project1;
import java.util.*;
class PC {
LinkedList<Integer> list = new LinkedList<>(); int cap = 2;
public void produce() throws InterruptedException {
int val = 0;
while (true) {
synchronized (this) {
while (list.size() == cap) wait();
System.out.println("Produced-" + val);
list.add(val++); notifyAll(); Thread.sleep(1000);}}}
Code:
package project1;
Code:
Output :
Program – 3.2
Code:
Code:
Person.java
import java.io.Serializable;
public class Person implements Serializable {
private String name;
private int age;
public Person() {}
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public int getAge() { return age; }
public void setAge(int age) { this.age = age; }
public void displayPersonDetails() {
System.out.println("Name: " + getName());
System.out.println("Age: " + getAge());
}
}
JavaBeanTest.java
public class JavaBeanTest {
public static void main(String[] args) {
Person person = new Person();
person.setName("John Doe");
person.setAge(30);
person.displayPersonDetails();
}
}
Output :
Program – 4.2
Code:
Student.java
import java.io.Serializable;
public class Student implements Serializable {
private String name;
private int age;
private String grade;
public Student() {}
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public int getAge() { return age; }
public void setAge(int age) {
if (age > 0) this.age = age;
else System.out.println("Age must be positive!");}
public String getGrade() { return grade; }
public void setGrade(String grade) { this.grade = grade; }
public void displayStudentDetails() {
System.out.println("Student Name: " + getName());
System.out.println("Student Age: " + getAge());
System.out.println("Student Grade: " + getGrade());}}
EncapsulationTest.java
public class EncapsulationTest {
public static void main(String[] args) {
Student student = new Student();
student.setName("Alice");
student.setAge(20);
student.setGrade("A");
student.displayStudentDetails();
student.setAge(-5); // Will print warning}}
Output :