1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
frosja888 [35]
3 years ago
8

Assume that the reference variable r refers to a serializable object. Write code that serializes the object to the file ObjectDa

ta.dat.
Computers and Technology
1 answer:
laiz [17]3 years ago
5 0

Answer:

FileOutputStream out = new FileOutputStream("ObjectData.dat");

ObjectOutputStream ostream = new ObjectOutputStream(out);

ostream.writeObject(r);

Explanation:

For object serialization, we can use the writeObject method of java.io.ObjectOutputStream class.

The complete code fragment is as follows:

import java.io.*;

class Demo{

      public static void main(String args[]){

             try{

                  r = <Reference to Object to be serialized> ;

                 FileOutputStream out = new FileOutputStream("ObjectData.dat");

                 ObjectOutputStream ostream = new ObjectOutputStream(out);

                  ostream.writeObject(r);

                 ostream.close();

            } catch(Exception e){

                   e.printStackTrace();

            }

      }

}

You might be interested in
Different units of CPU ?
deff fn [24]
The two typical components of a CPU include the following:<span>--The arithmetic logic unit (ALU), which performs arithmetic and logical operations. --<span>The control unit (CU), which extracts instructions from memory and decodes and executes them, calling on the ALU when necessary.</span></span>
3 0
3 years ago
What is the name for unwanted software that installs when you click some links?
Rudik [331]
Malware you're welcome 
8 0
4 years ago
Read 2 more answers
Python Coding:
leva [86]

Answer:

# Here we are asking the user for a number two times

userInput1 = input("Enter any #: ")

userInput2 = input("Enter any # again: ")

# We compare if userInput1 is greater than userInput2

if(userInput1 > userInput2):

   # Print userInput1 if userInput1 is greather than userInput2

   print("First Number: " + userInput1)

   # Otherwise, print userInput2

else:

   print("Second Number: " + userInput2)

# Initiate a while-loop

while(True):

   # The lines below are from above

   userInput1 = input("\nEnter any #: ")

   userInput2 = input("Enter any # again: ")    

   if(userInput1 > userInput2):

       print("First Number: " + userInput1)

   else:

       print("Second Number: " + userInput2)

   # We ask the user whether they would like to stop

   stop = input("\nWould you like to stop? (Yes or No)")

   # Compare the String stop with "Yes"

   if(stop == "Yes"):

       # If true then break

       break

Explanation:

The use of \n is unnecesary, but it skips a line and provides more readability.

5 0
3 years ago
"in program arrays12.java a swap method is called. does the swap method exchange parameter values x and y?"
Artist 52 [7]

Answer:

The answer is "True".

Explanation:

In the given question option is missing, that is "true or false", which can be described as follows:

In the given question, it is declared, that an "arrays12.java" program file is declared So, the class name is  "arrays12" because in java class name and the program file name is the same.

  • Inside the class, a swap method is called, that first accepts value.
  • After accepting the value it is defined as another variable, that swap variable values, that's why the answer to this question is true.
7 0
4 years ago
almost every school or university has a or council or organization that works towards provision of providing education training
disa [49]

Answer:

In education, the term stakeholder typically refers to anyone who is invested in the welfare and success of a school and its students, including administrators, teachers, staff members, students, parents, families, community members, local business leaders, and elected officials such as school board members, city ...

Explanation:

6 0
3 years ago
Other questions:
  • How will you be assigned with a mailbox with any OSP
    6·1 answer
  • Which diagrams represent how roles can affect careers and lifestyles
    11·1 answer
  • What is the difference between a learner’s license and an operator’s license?
    13·1 answer
  • Explain how applying different network topologies could have an impact on the security of a network
    11·1 answer
  • Corey set up his presentation for delivery to his team. The information he had to convey was critical to their job performance.
    6·3 answers
  • Which of the following statements is false? People tend to shortcut security procedures because the procedures are inconvenient.
    13·1 answer
  • Which task is performed by the artificial intelligence programmer?
    7·1 answer
  • Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards
    10·1 answer
  • Which statement best compares routers and hubs?
    9·1 answer
  • Today's consoles and games have audio features that rival cinematic audio.<br> True or False?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!