wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Java control statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java control statements" Watch "Java control statements" New topic
Author

Java control statements

Achin Gupta
Greenhorn

Joined: Sep 14, 2011
Posts: 28

Are the control statements like if(),while() etc are methods in java?


OCPJP 6
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
They cannot return a value. They cannot have access modifier. They cannot be static. They cannot be invoked using a Class name or object. They cannot be declared abstract. Really is that your question and welcome to the ranch
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

And beyond that... Java doesn't have functions, so it's meaningless to ask questions about whether something is or isn't a "function" in the context of Java.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

They're not really like functions at all, other than having brackets after them - which is just an accident of syntax. How would you write a function (or method) to do what while does? That is, continually execute the block of code following it until a condition is true.

If you want to see a language where all the control structures are methods, though, have a look at Smalltalk (there are probably others). There, for example, a for loop is a method of the Integer class, which takes a block of code as an argument and executes it n times, where n is the receiver.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java control statements
 
Similar Threads
Explicit conrol transfer statements????
what does # mean in Java source code?
making a method run a certain amount of times
ArrayList: How do you retrieve an item in an ArrayList and use that item for another purpose?
alternate code for if/else needed