javac

Hi,
I am trying to compile a java file in command window.
For one file temp.java, I can run Javac command and it will generated a new temp.class file. but when try to run with Java temp, it will give me an error that could't find the class?
Any inputs is welcome!

Thanks
chenjhuaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Radek BaranowskiFull-stack Java DeveloperCommented:
You need to specify local classpath by running

java -cp . Temp

Assuming that you are in a directory with Temp.class file
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
While setting the classpath explicitly is possibly the solution, the classpath should default to the current directory in your specific case (ie. "java temp") so that might not be the full solution.

Another likely possibility is that your java class "temp" has been declared to be in a package (look inside your temp.java file near the top for a line starting with "package"). If so, then you need to have that temp.java (and the resulting temp.class) in a directory structure that relates to the package name.

For example, say that your current directory is C:\Java and that your temp.java file looks something like the following...

package my.java.package;

import ...

public class temp ...

Open in new window


Therefore, you need to place temp.java in      C:\Java\my\java\package   (and javac should create temp.class there too) and then from the   C:\Java   directory, you would run     java my.java.package.temp       or        java -cp . my.java.package.temp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.