• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

a question about Object Url.

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
this is a mock xam question.
import java.io.*;
import java.net.*;
class Class1 implements Serializable {
String name, address;
URL url;
public Class1(String n,String a,int p) {
name = n;
address = a;
url = new URL("http://domain:" + p);
}
additional code here
How can you prevent object "url" from being saved to file when storing a Class1 object using java serialization?
1 declare "url" as transient
2 make Class1 abstract
3 implement Externalizable and create a writeObject() method
4 store "url" in another class and reference it from Class1
5 declare "url" as either static or final
could anybody please tell what the right answer is and how?.
with warm regards,
arun.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
#1 is correct. To keep any variables or object references from saving with a serialized object, declare them as trasient.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic