This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes create a method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "create a method" Watch "create a method" New topic
Author

create a method

Sue Nair
Greenhorn

Joined: Jan 28, 2008
Posts: 6
Hi! I am new to java and am having a little bit of trouble with some code. How do I create a method named isFull() that returns a boolean value? Thanks,
pegleg
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

"pegleg", please check your private messages for an important administrative matter.


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

Joined: Jan 10, 2002
Posts: 60810
    
  65

What's your best attempt so far?
[ January 31, 2008: Message edited by: Bear Bibeault ]
Sue Nair
Greenhorn

Joined: Jan 28, 2008
Posts: 6
Originally posted by Bear Bibeault:
What's your best attempt so far?

[ January 31, 2008: Message edited by: Bear Bibeault ]


I tried to put

isFull=boolean();
but I don't think it is right
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

You're right. It's not right.

What you showed there is a method reference, not a declaration. You do not specify the return type on a method reference.

Before referencing the method, you need to declare it. So what's the proper syntax for declaring a method?

Or, do already have the method declared elsewhere and are having trouble calling (referencing) it?
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Originally posted by pegleg:
Hi! I am new to java and am having a little bit of trouble with some code. How do I create a method named isFull() that returns a boolean value? Thanks,
pegleg


As Bear told, the creation of method has to deal with two aspects. One is having it (declaring as well defining it). Second is using it (referencing) from some other place.

Are you clear with these basics of methods? If not, please have a look at the tutorial on defining methods.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Olivier Legat
Ranch Hand

Joined: Nov 17, 2007
Posts: 176

I don't quite see what your method is meant to do but if it just the boolean return part then I might be able to help.



Based on our program you may choose not to write "public" or "static"


Olly
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Originally posted by Olivier Legat:





Here, the compiler will definitely complain as the local variable 'x' is not initialized

Initializing the local variables before their first usage is NOT optional and its a must!

We were trying to help him to first get the basics and let him come up with his own code instead we give him the full code. Of course, that is the motto of NOT being a codemill.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Oliver Legat is right in what he posted; You may not need to initialise the boolean variable because the next line will readI think it is reasonable for him to drop that sort of hint. The only thing I would disagree with is the bit about static. It will probably be the object which is "full," not the class, so the method almost certainly ought not to be static.
Sue Nair
Greenhorn

Joined: Jan 28, 2008
Posts: 6
Thanks! That worked for me.

Originally posted by Olivier Legat:
I don't quite see what your method is meant to do but if it just the boolean return part then I might be able to help.



Based on our program you may choose not to write "public" or "static"
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Originally posted by S Nair:
Thanks! That worked for me. . . .

Well done. Please post what you wrote, so other "greenhorns" can learn from it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: create a method
 
Similar Threads
Calculate the average of an ArrayList
Constructor overloading
Building a class which initializes abject like String class?
toString() method...
Re: How to create a arrows with different angle in java applet