File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getting ; expected error for the below program.." Watch "getting ; expected error for the below program.." New topic

getting ; expected error for the below program..

Janardhan Mudduluru

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

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

solution will be much appreciated..

Janardhan M
Henry Wong

Joined: Sep 28, 2004
Posts: 20517

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.


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

Joined: Jan 12, 2009
Posts: 1111

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:

I agree. Here's the better link:

Av Vinay

Joined: Oct 27, 2009
Posts: 6

public class Example {

public Example() {
public static void main(String[] args){
String c = hi();
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.


Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
Your code is hard to read if you don't use the Code button.
I agree. Here's the link:
subject: getting ; expected error for the below program..
It's not a secret anymore!