Solved

Java: Error calling System.out.println()

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

696 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