Solved

Why does my old .class file keep getting regenerated in java?

Posted on 2009-07-02
3
231 Views
Last Modified: 2012-05-07
Hi,

I am new to JAVA and I'm having some difficulties running my program.
I created a new file called Hello.java and saved it on my desktop.
I then typed the command javac.Hello from the command prompt.
The problem i'm having is that its suppose to compile a Hello.class for me
but instead it comiles a previous file which was HelloApp.class

Does anyone know why this happens?
I've installed the jdk6 and added the path to my bin directory.
Thank You.
0
Comment
Question by:techin4
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 250 total points
ID: 24766627
How are you compiling?

+double check that Hello.java has class in it defined as Hello instead of HelloApp
+copy the file into folder like c:\temp
+at command prompt do the following:

c:> cd \temp
c:\temp> javac -cp . Hello.java
0
 

Author Comment

by:techin4
ID: 24766848
Hi mwvisa1,

Your absolutely right.
I had HelloApp as the name of the class.
After renaming it to Hello, it compiled a Hello.class for me.
Thanks!
But i have one more question.
I saw you that you posted javac -cp
What does that -cp for?
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24766940
It is shorthand for -classpath which tells java where to find user class files during compilation which is good if you had other classes in your application in the same directory denoted by the '.'.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

863 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

27 Experts available now in Live!

Get 1:1 Help Now