Skip to content

Commit

Permalink
serial and deseaial
Browse files Browse the repository at this point in the history
  • Loading branch information
AkashKobal committed Mar 25, 2024
1 parent 2ca9d95 commit 36f0cd2
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 0 deletions.
Binary file added labsheets/~$xp1_M1.docx
Binary file not shown.
10 changes: 10 additions & 0 deletions serializationAndDeseralization/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-17.0.7.7-hotspot">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions serializationAndDeseralization/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>serializationAndDeseralization</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
Binary file added serializationAndDeseralization/bin/module-info.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions serializationAndDeseralization/src/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
*
*/
/**
*
*/
module serializationAndDeseralization {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package serializationAndDeseralization;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;

public class deserial {
public static void main(String[] args) {
try {
FileInputStream fileInputStream = new FileInputStream("C:\\Users\\Admin\\IdeaProjects\\module1\\src\\module1\\experiment1\\file.txt");
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
student s1 = (student) objectInputStream.readObject();
student s2 = (student) objectInputStream.readObject();
student s3 = (student) objectInputStream.readObject();
student s4 = (student) objectInputStream.readObject();
student s5 = (student) objectInputStream.readObject();

System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
System.out.println(s4);
System.out.println(s5);
objectInputStream.close();

}
catch (Exception e){
System.out.println(e);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package serializationAndDeseralization;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class serial {
public static void main(String[] args) {
try {
student s1 = new student(1,116,"Akash","CSE","PU");
student s2 = new student(2,117,"Rahul","CSE","PU");
student s3 = new student(3,118,"Rohit","CSE","PU");
student s4 = new student(4,119,"Raj","CSE","PU");
student s5 = new student(5,120,"Ravi","CSE","PU");

FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\Admin\\IdeaProjects\\module1\\src\\module1\\experiment1\\file.txt");
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(s1);
objectOutputStream.writeObject(s2);
objectOutputStream.writeObject(s3);
objectOutputStream.writeObject(s4);
objectOutputStream.writeObject(s5);
objectOutputStream.flush();
objectOutputStream.close();
System.out.println("Sucess");

}
catch (Exception e){
System.out.println(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package serializationAndDeseralization;

import java.io.Serializable;

public class student implements Serializable {
int id;
int rollNo;
String name;
String branch;
String college;

public student(int id, int rollNo, String name, String branch, String college) {
super();
this.id = id;
this.rollNo = rollNo;
this.name = name;
this.branch = branch;
this.college = college;
}
public String toString(){
return "Student [id=" + id + ", rollNo=" + rollNo + ", name=" + name + ", branch=" + branch + ", college=" + college + "]";
}

}

0 comments on commit 36f0cd2

Please sign in to comment.