aspose file tools*
The moose likes Beginning Java and the fly likes Interpret line attempt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interpret line attempt" Watch "Interpret line attempt" New topic
Author

Interpret line attempt

Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
I am trying to understand this line that is in a Servlet.
Please tell me if I am correct or wrong on how I interpret the bolded line below.
boolean dataExists = new Baseball().hitBall(String Mays, String McCovey);

The line creates a boolean datatype called dataExists which is a object reference that is assigned to a new Baseball type object where it is calling Baseball no argument constructor AND it is calling a (non static) boolean two parameter method called hitBall? For example the Baseball no arg constructor could have some code with the Database connection statement and the boolean method hitBall would have this as its signature method: public boolean hitball(String Mays, String McCovey)
[ April 10, 2007: Message edited by: Mike Jenkins ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Not servlet-specific, so moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Close, but as written, the line will yield a compiler error. Type names are not included in method call parameters.

Were the line writen as:



I'd amend your description as follows:

The line creates a boolean variable called dataExists which is a boolean value that is assigned from a call to the hitBall() method of a new instance of Baseball created using a no-args constructor.

An important nuance that your description seemed to miss is that a reference to the newly created Baseball instance is not stored anywhere.
[ April 10, 2007: Message edited by: Bear Bibeault ]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Mike Jenkins:
...The line creates a boolean datatype called dataExists which is a object reference that is assigned to a new Baseball type object...

Just to clarify a bit further, boolean with a lowercase 'b' is a primitive type -- not an object. (The boolean wrapper class uses an uppercase 'B'.) So instead of referencing an object, dataExists will only hold a primitive value of true or false.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
Thanks for replies and my apology for originally putting in Servlet Forum.
From both responses:
"An important nuance that your description seemed to miss is that a reference to the newly created Baseball instance is not stored anywhere."
and
"So instead of referencing an object, dataExists will only hold a primitive value"

I assume there is no reference in this: boolean dataExists = .. because the boolean is a primitive data type BUT if it said this: Boolean dataExist = .. then it would be a reference to a Baseball instance (object)?
[ April 10, 2007: Message edited by: Mike Jenkins ]
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
No it would be a reference to a Boolean.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Originally posted by Keith Lynn:
No it would be a reference to a Boolean.


Moreover, it would be whatever was returned from the hitBall() method, which would need to be a Boolean for the line to compile.
Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
Thanks,


Can I get clarification on this:
"An important nuance that your description seemed to miss is that a reference to the newly created Baseball instance is not stored anywhere."

This means there is no reference variable in the statement so there is nothing to store anywhere?
[ April 10, 2007: Message edited by: Mike Jenkins ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interpret line attempt
 
Similar Threads
Please explain the output of this code snippet
Problem Working An Example calling Super()
Polymorphism
Constructor problem
new