Solved

Java: Error calling System.out.println()

Posted on 2009-05-04
3
495 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
  • 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 125 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now