Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Error displayed at println statement.

 
Joy Vergis
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 12800
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can't have code outside a method. you can declare variables, but you can't call methods or really 'do' stuff.
 
Pankaj Rathod
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also you are calling System.out.println() without any argument.
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 68135
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Marshal
Posts: 68135
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use Eclipse or other IDEs at this stage.
 
That is a really big piece of pie for such a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!