[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Java: Error calling System.out.println()

Posted on 2009-05-04
3
Medium Priority
?
509 Views
Last Modified: 2013-11-23
Please tell me why the program doesn't compile and how to fix the problem.
I am trying to compile a java program without using an IDE.  I have set the PATH and CLASSPATH environment variables to point respectively to the bin and lib directories of the jdk.  I am operating under Windows and using the command prompt to compile.  The source  is e:\scjp\exercises\chapter1\ListFoods.java and the working directroy is e:\scjp\exercises\chapter1.  The command I use to compile is javac ListFoods.java. When I compile the code I receive the error message "ListFoods.java:14: <identifier> expected System.out.println(s);
class main{
	String s = "Hi mom";
	System.out.println(s);
}

Open in new window

0
Comment
Question by:ssackett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 92

Expert Comment

by:objects
ID: 24301699
your code needs to go in a method, and your class name needs to be same as file name

class ListFoods {
     public static void main(String[] args) {
        String s = "Hi mom";
        System.out.println(s);
     }
}

0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 24301721
you'll also need to make your class public

public class ListFoods {
     public static void main(String[] args) {
        String s = "Hi mom";
        System.out.println(s);
     }
}

0
 

Author Closing Comment

by:ssackett
ID: 31577889
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question