• Post Reply Bookmark Topic Watch Topic
  • New Topic

A few of my homework questions  RSS feed

 
D Doemer
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have some homework questions here that I've done and I wonder if you guys would double check them and let me know if I've got them.

Thanks!


1. In Java, a field which may be set at most once:
Answer: Final

2. In Java, these are passed by value:
Answer: Arguments

3. In Java, the name of a method to create objects :
Answer: Constructor

4. In Java, a field or method that doesn't depend on the particular object of the class is called :
Answer: Static

5. A standard Java class used to maintain a bunch of objects for an application should be from the Java ______________ Framework:
Answer: ???

10. The expression 7 / 8 in Java evaluates to:
Answer: 0
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37496
547
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Correct.
2) Close, but there's a more specific answer
3) Correct
4) Correct
5) Obviously, not correct. Can you think of a class name that is an example of this?
10) Correct
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any time you start talking about managing a bunch of objects you must automatically start thinking about data structures such as sets, lists and the like... In Java you will find such tools in the utility package (java.util)

Now all you have to do is figure out (google) the name that the gurus came up with for such a framework
 
D Doemer
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, guys. So after a little more research, I'm thinking #2 would be "parameters", and #5 would be "collections". Thoughts?
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct.

#In my opinion question 3 is misleading because constructors are not methods. But constructor is the correct answer.
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For #3 I'd say <init> just because the question is misleading ;).

JVMS says:
At the level of the Java Virtual Machine, every constructor written in the Java programming language (JLS §8.8) appears as an instance initialization method that has the special name <init>. This name is supplied by a compiler.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About Campbell's and Pawel's last answers:

Conceptually, constructors are not methods, so the question itself is actually wrong. A constructor is a special block of code that is called to initialize a newly created object. It's slightly different from a method: you can't call a constructor directly and a constructor does not have a return value.

Under the hood, constructors are implemented as a special kind of method; the compiler automatically generates a method called <init> for a constructor. But that's an implementation detail, and that shouldn't distract you from the fact that constructors are not really methods.
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper, that's why I wrote that I acknowledge the question is misleading and I even put a smiley face ;).
But if I was told to provide a name of a method that creates objects I'd say <init> because in my opinion this answer is it as close to the truth as possible.
I know that constructors are not methods.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote:I know that constructors are not methods.

Actually, I've always wondered about that. The fact is that they look like methods, and indeed they're implemented as methods, so I think it's confusing to tell beginners that they aren't methods.

The thing is: they have special rules, and they can't be called directly (@D Doemer: you call them with the "new" keyword). That doesn't mean they aren't methods though.

Winston
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:The thing is: they have special rules, and they can't be called directly (@D Doemer: you call them with the "new" keyword).

Or by this or super (calling a constructor from within another constructor).
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote:Or by this or super (calling a constructor from within another constructor).

Or not.
(never liked that "default" behaviour)

Winston
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote:
Winston Gutkowski wrote:The thing is: they have special rules, and they can't be called directly (@D Doemer: you call them with the "new" keyword).

Or by this or super (calling a constructor from within another constructor).

Or by string concatenation ;)
 
Ole Sandum
Ranch Hand
Posts: 76
3
IntelliJ IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't the question misleading in another respect as well? Seeing as a constructor isn't actually creating an object, but called when an object is created.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ole Kristian Sandum wrote:Isn't the question misleading in another respect as well? Seeing as a constructor isn't actually creating an object, but called when an object is created.

You're quite right, but I suspect we're going off at a tangent here (fun though it is; and probably my fault in this case). Let's try and stick to OP's question and let her reply to the posts that were "on point".

Winston
 
D Doemer
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, folks. Yes, misleading questions -- or rather, vague and unincorporated -- are a theme of this course.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D Doemer wrote:Thanks, folks. Yes, misleading questions -- or rather, vague and unincorporated -- are a theme of this course.

I've been meaning to ask: Is this a school/uni course, or one that you're doing on your own time? If the first (particularly if it's uni), I have to admit being quite surprised at the lack of documentation - at least if your FormLetter example is anything to go by.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!