This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes newbie questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "newbie questions" Watch "newbie questions" New topic

newbie questions

Andrew Parker
Ranch Hand

Joined: Nov 12, 2001
Posts: 178
I have several questions:
1) What does "instanceof operator tests the class of an object at runtime" mean? Anyone could give me a simple example?
2) int x=1;
String [] names = {"Fred", "Jim", "Tony"};
names[-x] += ".";
for (int i=0; i<names.length; i++) {>
Ans: The output includes Fred. with a trailing period.
What is "trailing period"?
3) transient modifier - the value of variable will not be written out during serialization. What is serialization and when will it be used?
Thanks a lot.
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
1) They meant that you could have a general class object, let's use good ol' Shape class with a variable called myShape, and Shape might hold a Square object, a Circle object, whatever. When you do myShape instanceof Square, even through myShape is of type Shape, the JVM knows it's really holding a reference to an object of Square, Circle, whatever. In this case, if it is a Square object, instanceof would return true. If it holds Circle, it returns false.
2) The trailing period is the period at the end... go figure. Not a Java term, just saying "Look, there's a period at the end now"
3) Serialization is used to write objects to a file. If an object is not serialized, it means you can't write it. If your object holds references to other objects, all those objects also have to implement serializable, and any objects those objects might hold, and so on and so on. A data member marked transient means you don't want that data written, either.
Look throught the API, and search for other posts on these topics, for more detailed explainations and examples.
[This message has been edited by jason adam (edited December 08, 2001).]
Don't get me started about those stupid light bulbs.
subject: newbie questions
It's not a secret anymore!