How do I run my java program

I created a java program with Eclipse.  I tried running my program from command prompt (e.g.

C:\myjavaprograms> java myprogram

but it gives the below error (running javac does not throw an error)

Exception in thread "main" java.lang.NoClassDefFoundError: myprogram (wrong na
me: ceasarcipherprogram/myprogram)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(
        at Method)
        at java.lang.ClassLoader.loadClass(
        at sun.misc.Launcher$AppClassLoader.loadClass(
        at java.lang.ClassLoader.loadClass(
        at java.lang.ClassLoader.loadClassInternal(
Who is Participating?

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

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.

From what i can tell , you get No definition for a requested class error, which would imply that you havn't matched the class name of your project to name of your source file.

Name the file for instance and then also name the class to mytest.
CipherISAuthor Commented:
Here is an example of my code.

package ceasarcipherprogram;

import java.util.Scanner;

public class myprogram{
	public static void main(String[] args){
             //Code Here

Open in new window

You need to export your project as jar before you can run it with java.exe.

If you run eclipse, simply just CTRL-F11 to run the code.

Add System.out.println("Hello"); in your main function and you'll see it works :)
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

CipherISAuthor Commented:
It runs in eclipse.  I do have more code i just gave a sample.  I was trying to figure out how to run it with command prompt.
The simplest way would be to export you code into a .jar file :)

Else you can follow this guide to achieve what you want:
Sharon SethCommented:
You are not executing the command line fromthe correct path . Eclipse would have created the required class files in bin folder of your project .So, cd to that path and then execute the commandline .
This link should help you:
How to execute java program in CMD in windows?
The main class(that has main method) must be public and the name of the file must be the name of the class.

Best wishes

C:\myjavaprograms> javac -d .

C:\myjavaprograms>java ceasarcipherprogram.myprogram

Open in new window


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
Joe RudSystems AdministratorCommented:
Have you installed the java Development Kit (JDK) on your computer so you can compile and run java programs?  Or are you just worked from Eclipse?

You may want to look around this page if you need the JDK
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

From novice to tech pro — start learning today.