This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Garbarge Collection exercise Ch 9 Head First Java

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am working on the Be the Garbage Collector exercise in Head First Java Chapter 9 page 266 and don't understand the code in line 3 (actually the second line of code)...



I am specifically looking at the line:


I don't get what this is doing...

Supposedly this is creating an method. However, I don't understand the space between "GC" and doStuff()...

Farther down in the code sample the method is referred to as doStuff(), NOT GC doStuff();

--- I found a similar question was posted and answered here: https://coderanch.com/t/417054/java/java/Garbage-collection-eligibility

Sorry to post a possible duplicate question, but I have been trying to find any reference to creating methods with a class name <space> method and I don't readily see anything like this.

Thank you for your assistance and patience.

V/r,

Jim







 
Greenhorn
Posts: 17
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read this book a while ago, I dont remember this but I can answer part of this question.

A recognizable method signature looks something like this

is the return type of this method, meaning it returns no value.

You can have a return type of primitives, or objects as well. For example


So these three methods have a return type of int, String and GC respectively. Where "GC" is some object somewhere.
To call GC collectStuff you would say
As for what this method does? I have no idea But I hope this answers your question, or part of it anyway.

EDIT: If I would have looked a little closer I could have seen that doStruff() calls a second method doStuff2(GC), which takes a GC object as an argument and creates a new GC object.
 
Jim Brent
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course GC is the return type... (GC Object)...

Thank you... Now I get it...
 
Marshal
Posts: 76845
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sal jefferson wrote:. . . As for what this method does? I have no idea . . . second method doStuff2(GC), which takes a GC object as an argument and creates a new GC object.

Have another look at doStuff2. They probably chose those poor names for people who are practising for certification exams because they sometimes have very poor code style in. Now work out not only what doStuff2 does, but also whether it does anything at all
 
Poop goes in a willow feeder. Wipe with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic