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 problem in System.out.println Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem in System.out.println" Watch "problem in System.out.println" New topic
Author

problem in System.out.println

vinaykumar singh
Greenhorn

Joined: Jan 14, 2006
Posts: 13
hello all...

i having a problem in System.out.println();
see code and please guide me.(i m using Eclipse 3.0,and also tried this code in diffrent editor)



public class A {

System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}

i have a another main class where i calling class A.

get error in class A
System.out.println();

Multipal markers at this line
-Syntax error on token ""aaaaaa"", delete this token
-Syntax error on Token(s), misplaced construct(s)
-----------------------------------------------------------

if i write only

public class A {

System.out.println();
}

getting
-Syntax error on token "println", Identifier expected after this token

-------------------------------------------------------------------------
and if i decleared main method in class A there is no error
like

public class A {
public static void main(String args[]){
System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}
}

-No Error

-------------------------------------------------------------------------

please guide me why this is happening.

thanks in advance...

vinay kumar singh
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

In the first example, you can't have a statement that's not in a method. you could put the method in a constructor if you want it to print when the object is created, or you have to define a method like


and then call that method on the object.

in the second example, i think it's because there is no version of println that takes no argument - you have to pass it SOMETHING. and, if you change it to pass in a parameter, you'll be back at the first example.

in your third example, you have an enclosing method and a valid call to the println method.
[ January 17, 2006: Message edited by: fred rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by fred rosenberger:
in the second example, i think it's because there is no version of println that takes no argument - you have to pass it SOMETHING.

Nope, the second example has the same problem as the first. You are only allowed to put variable declarations outside of a method. Any code that is to be executed must be inside a method, as Fred says. There is a version of System.out.println() that takes no arguments.

Layne


Java API Documentation
The Java Tutorial
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

i was just taking a stab, since we got a different error than the first one, and i didn't have time to doublecheck the API.

at least i was smart enough to write the "i think..."

in any case, i hope we've answered the original question.
 
Consider Paul's rocket mass heater.
 
subject: problem in System.out.println
 
Similar Threads
Error in using JWIG
Error in using "assert" in java program....
Cannot Figure Out This Syntax Error
What is wrong with my code?
Syntax error on token <variableName>, VariableDeclaratorId expected after this token