Posts

Showing posts from January, 2022
SERIALIZATION CUSTOMER:  An Object can be directly saved into a file and can be later reloaded. This process is called Serialization and the restoration is called De-serialization. The extension of the file is ".ser". An Object is considered ready for serialization if its class implements a Serializable interface. The serializable interface is called Marker Interface. A Marker Interface is one that has no methods and member variables, but just indicates / marks that the given class is implementing the Interface. Use ObjectOutputStream class for converting an object to a serialized file. Input and Output Format: Enter the Customer name John Enter the Customer number 12 Enter the Customer address Chennai CODE: import java.io.Serializable; public class Customer implements Serializable {     private String name; private Integer number; private String address; public Customer() { super(); // TODO Auto-generated constructor stub } public Customer(String name, In...
Image
  JAVA Streams and Writers: ITEMTYPE DETAILS IN FILE The length and position of attributes are as follows.   Attribute Length Position name 15 1 deposit 7 16 costPerDay 5 22 Input format: Read the details from the input file  " input.txt " Output format: Use " %-15s %-15s %s\n " for displaying ItemType details in tabular form in the console Print one digit after the  decimal  for the  double  datatype. Print the statement for the heading of the details is  present  in the main method. Refer to the sample output for the formatting specifications. Sample Input: Sample Output : Item type       Deposit         Cost per day Electrical      2100.0          500.0 Construction    5000.0          1000.0 CODE: public class ItemType {   ...
JAVA Streams and Writers: FIXED LENGTH FORMAT In Fixed Length Format files, each field has a fixed length. If a variable of the field is shorter than its size, it is filled with space so that all variables of a particular field is of the same size.  Write a program to read event details from the fixed-length format file and display the events organized by specific persons. The sizes of fields in the fixed-length file are, Field Size name 0-19 details 19-39 type 39-51 organizer 51-61 attendeesCount 61-67 projectedExpense 67-74 Sample Input and Output 1: Enter the name of the person whose events to be shown: Jane Name           Detail              Type           Attendees CountProjected Expense Magic Show     Magicwithoutlogic stageshow      1000     ...
  JAVA Streams and Writers: Hall details   Write a program to get the hall details in CSV format in the console and store them as the list of objects. Then write this list into the file " output.txt ". Sample Input: [All text in bold corresponds to input and rest corresponds to output] Enter the number of halls: 3 Party hall,9876543210,4000.0,Jarviz Disco hall,9876543201,5000.0,Starc Dining hall,9873216540,3000.0,Chris CODE: import java.io.FileWriter; import java.io.IOException; import java.util.List; public class Hall {     private String name;     private String contact;     private Double costPerDay;     private String owner; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getContact() { return contact; } public void setContact(String contact) { this.contact = contact; } public Double getCostPerDay() { return costPerDay; } public void se...
  JAVA Streams and Writers: FILE WRITING Sample Input: [All Texts in bold corresponds to the input and rest are output] Enter the number of users: 3 Enter the details of user :1 Jane,1234,jane,jane Enter the details of user :2 John,5678,john,john Enter the details of user :3 Jill,1357,jill,jill CODE: public class User {     String name;     String mobileNumber;     String username;     String password;          public User(String name,String mobileNumber,String username,String password)     {         this.name=name;         this.mobileNumber=mobileNumber;         this.username=username;         this.password=password;     }     public String getName() { return name; } public void setName(String name) { this.name = name; } public String getMobileNumber() { return mobileNumber; } public void...
  JAVA Streams and Writers: FILE HANDLING INTRODUCTION Provided " input.csv " which has User details. Read all the user information stored in CSV format and create a user object by parsing the line. Add all the user objects to the ArrayList. At last,   display the user list. Output format: Use  "%-15s %-20s %-15s %s\n"  to print statements for the heading of the details in the Main method. Sample Output : Name            Email                Username        Password William             will@gmail.com        william             will123 john           john@gmail.com     john  ...
  GENERIC CLASSES: Sample Input and Output: Enter an integer : 15 Enter a string : Hello World Generic class Integer Value :15 String Value :Hello World Generic class CODE: // Generic Class public class Item <T> {      T data; public T getData() { return data; } public void setData(T data) { this.data = data; } } import java.io.IOException; import java.util.Scanner; public class Main {     public static void main(String[] args) throws IOException {     Item <Integer> item1 = new Item<Integer>(); Item <String> item2 = new Item<String>(); Scanner sc = new Scanner(System.in); System.out.println("Enter a integer :"); int num = Integer.parseInt(sc.nextLine()); System.out.println("Enter a string :"); String str = sc.nextLine(); item1.setData(num); item2.setData(str); System.out.println("Integer Value :"+item1.getData()); System.out.println("String Value :"+i...