LAB ASSIGNMENT-5
NAME:ADITH KUMAR MENON
REGISTRATION NUMBER:18BCE2311
Q1. Writea program to demonstrate the object serialization and
deserialization when one object holds information about the employee of
an organization
ANS:
import [Link].*;
class Employee implements Serializable {
private static final long serialversionUID =129348938L;
transient int salary;
static int dept_id;
String name;
int age;
// Default constructor
public Employee(String name, int age, int salary, int dept_id)
{
[Link] = name;
[Link] = age;
[Link] = salary;
this.dept_id = dept_id;
}
public class SerialExample {
public static void printdata(Employee object1)
{
[Link]("name of the employee = " + [Link]);
[Link]("age of employee = " + [Link]);
[Link]("salary of employee = " + [Link]);
[Link]("department id of employee = " + object1.dept_id);
}
public static void main(String[] args)
{
Employee object = new Employee("adith", 20, 10000, 10);
String filename = "[Link]";
// Serialization
try {
// Saving of object in a file
FileOutputStream file = new FileOutputStream
(filename);
ObjectOutputStream out = new ObjectOutputStream
(file);
// Method for serialization of object
[Link](object);
[Link]();
[Link]();
[Link]("Object has been serialized\n"
+ "Data before Deserialization.");
printdata(object);
// value of static variable changed
object.dept_id = 2000;
}
catch (IOException ex) {
[Link]("IOException is caught");
}
object = null;
// Deserialization
try {
// Reading the object from a file
FileInputStream file = new FileInputStream
(filename);
ObjectInputStream in = new ObjectInputStream
(file);
// Method for deserialization of object
object = (Employee)[Link]();
[Link]();
[Link]();
[Link]("Object has been deserialized\n"
+ "Data after Deserialization.");
printdata(object);
// [Link]("z = " + object1.z);
}
catch (IOException ex) {
[Link]("IOException is caught");
}
catch (ClassNotFoundException ex) {
[Link]("ClassNotFoundException" +
" is caught");
}
}
}
OUTPUT:
Q2. Createa Treemap and store the name and regd no of your ten number of
friends, finally delete one of your friend data from the map
ANS:
import [Link].*;
class tree_map {
public static void main(String args[])
{
TreeMap tm1 = new TreeMap();
TreeMap tm2 = new TreeMap();
[Link](1, "RAKESH :18BCE2351");
[Link](2, "DEVOPRASAD :18BCE2312");
[Link](3, "BASIL JACOB :18BCE342");
[Link](4, "AADARSH SREEKUMAR :18BCE2316");
[Link](5, "SRIDHAR MUGUNDAN :18BCE2313");
[Link](6, "MANU :18BMA2314");
[Link](7, "ASHWIN :18BMA2315");
[Link](8, "ABEL :18BMA2456");
[Link](9, "NEVIN :18BME2345");
[Link](10, "VISHAL :18BCE4578");
[Link](tm1);
[Link](6);
[Link](tm2);
}
}
OUTPUT:
FOLLOWING JAVAFX PART IS DONE IN ECLIPSE:
3Q. Show one stage using JAVAFX where your name will be displayed
ANS:
package helloworld;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class HelloWorld extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
[Link]("Hello World!");
Button btn = new Button();
[Link]("Say 'Hello World'");
[Link](new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
[Link]("Hello World!");
}
});
StackPane root = new StackPane();
[Link]().add(btn);
[Link](new Scene(root, 300, 250));
[Link]();
}
}
OUTPUT:
4Q. Write a program to design a calculator by using javaFX
ANS:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Calculator extends Application{
private TextField txtNum = new TextField();
private Button one = new Button("1");
private Button two = new Button("2");
private Button three = new Button("3");
private Button four = new Button("4");
private Button five = new Button("5");
private Button six = new Button("6");
private Button seven = new Button("7");
private Button eight = new Button("8");
private Button nine = new Button("9");
private Button zero = new Button("0");
private Button dot = new Button(".");
private Button AC = new Button("AC");
private Button btnSum = new Button("+");
private Button btnSub = new Button("-");
private Button btnMul = new Button("*");
private Button btnDiv = new Button("/");
private Button btnEq = new Button("=");
public static void main(String[] args) {
[Link](args);
}
@Override
public void start(Stage primaryStage) throws Exception {
GridPane myPane = new GridPane();
Scene scene = new Scene(myPane,300,300);
[Link](scene);
[Link]();
[Link](txtNum, 4, 0);
[Link](seven, 1, 3);
[Link](eight, 2, 3);
[Link](nine, 3, 3);
[Link](btnMul, 4, 3);
[Link](four, 1, 4);
[Link](five, 2, 4);
[Link](six, 3, 4);
[Link](btnSub, 4, 4);
[Link](one, 1, 5);
[Link](two, 2, 5);
[Link](three, 3, 5);
[Link](btnSum, 4, 5);
[Link](zero, 1, 6);
[Link](dot, 2, 6);
[Link](btnDiv, 3, 6);
[Link](btnEq, 4, 6);
[Link]([Link]);
OUTPUT:
5Q. Writea program to design your mobile screen where the icons available
on your screen will be present and your image will be displayed in the
middle
ANS:
DISPLAYING AN IMAGE USING VFX:
package application;
import [Link];
import [Link];
import [Link];
import [Link];
public class Controller {
//ImageView is a Node used for painting images loaded with Images
// Image = picture
// ImageView = picture frame
@FXML
ImageView myImageView;
Button myButton;
Image myImage = new Image(getClass().getResourceAsStream("[Link]"));
public void displayImage() {
[Link](myImage);
}
}
OUTPUT: