File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes getting ; expected error for the below program.. 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 "getting ; expected error for the below program.." Watch "getting ; expected error for the below program.." New topic
Author

getting ; expected error for the below program..

Janardhan Mudduluru
Greenhorn

Joined: Jul 09, 2009
Posts: 4
Hi Mates,

I am a beginner...getting ; expected error for the below program..

solution will be much appreciated..

Thanks
Janardhan M
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18538
    
  40


You can't just declare a method anywhere. In this case, you are trying to declare the hi() method inside the main() method. This is not legal.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 917

let me modify your example so that it works...



There you go...

what you should learn:
1. methods are not functions, so you cant have:

you are permitted:


2. methods are not functions , so you cant have



you are permitted:



My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Av Vinay
Greenhorn

Joined: Oct 27, 2009
Posts: 6
Hi.,

public class Example {

public Example() {
}
public static void main(String[] args){
String c = hi();
System.out.print(c);
}
public static String hi()
{
return "Hi";
}
}

As explained in the last reply., You just can't write the metod definintion anywhere you want. The other solution for your problem is to write a static function which can be directly called by the static function main() as shown above.

Regards.,

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38033
    
  22
Your code is hard to read if you don't use the Code button.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting ; expected error for the below program..
 
Similar Threads
Doubt in static import
Getting error please see and help it...
Reference Type Casting
Interface Code:problem:need to resolve it
Java noob needs help