*
The moose likes Beginning Java and the fly likes Error displayed at println statement. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error displayed at println statement." Watch "Error displayed at println statement." New topic
Author

Error displayed at println statement.

Joy Vergis
Ranch Hand

Joined: Sep 14, 2009
Posts: 43

i am new to java. I writing a program in eclipse. I get error at the println statement.

Program:

package package1;

public class ClassA {
String str1="a-b";

int a= str1.length(); //error at this line.

System.out.println();
}

Error displayed in eclipse:
Syntax error on token "println", Identifier expected after this token.

Please help
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

you can't have code outside a method. you can declare variables, but you can't call methods or really 'do' stuff.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Pankaj Rathod
Greenhorn

Joined: Feb 02, 2009
Posts: 7
Also you are calling System.out.println() without any argument.
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 557
You could start with the almost-obligatory "HelloWorld.java" program that teaches basic program structure and the elements required. You can find a tutorial using an appropriate Google search that either shows how to create and run the program using a basic text editor at the command line (recommended) or using Eclipse. If you've decided on Eclipse as your IDE, construct and run the HelloWorld program using both the command line and IDE approaches so that you see what Eclipse does for you and have an idea what you'll have to do without Eclipse.


Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Pankaj Rathod wrote:Also you are calling System.out.println() without any argument.
What's wrong with that? Look in the documentation and see whether it is permissible.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Don't use Eclipse or other IDEs at this stage.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error displayed at println statement.
 
Similar Threads
Getting exception with buffered loop...
When to use keyword "const"? Just a reserved word.
No suitable driver problem
problem in System.out.println
Boxing/Unboxing and equality