Solved

Java: Error calling System.out.println()

Posted on 2009-05-04
3
501 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GUI builder for Eclipse? 8 35
ForLoop Example 3 49
Android development question 2 37
Chrome and Firefox Java 5 32
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This article will show, step by step, how to integrate R code into a R Sweave document
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

777 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