0

I have created a simple program to display some texts, but when I tried to compaile it on jGRASP the it showing the following errors.

Exception in thread "main" java.lang.NoClassDefFoundError: program1 (wrong name: Program1)
at Java.lang.ClassLoder.defineClass1(Native Method)

and

at java.security.AccessController.doPriviledged(Native Method)

Here is the Program1

/**WRITE COMMENT HERE*/

class Program1
{
    public static void main(String [] args)
        {
             System.out.println("Name:\n\tSalwan Yousif\n");
             System.out.println("Major:\n\tHomeland Security\n");
             System.out.println("Reason for taking course:\n\tIt's required for my major\n");
             System.out.println("Pase of course:\n\tJust a bit too fast\n");
             System.out.println("General feedback:\n\tI'll do my best to pass this class\n");
        }
}
5
  • 1
    change this line class Program1 to public class Program1 and save the file as Program1.java . it should work fine. The problem was that your class is inside a java file , but it is not visible to java , hence I just changed the visibility by adding public keyword Commented Sep 6, 2014 at 0:21
  • When programming you should change things one by one, if something breaks you know its the last thing you changed. The stack trace (the error) will also try and help you. Did it break when you renamed the class? I'm not sure you can have numbers in class names. Commented Sep 6, 2014 at 0:21
  • @LeeAllan It is possible to have numbers in class names as long as a digit is not the first character in the class name. For example, Program1 is valid but 1Program is not. Commented Sep 6, 2014 at 0:24
  • @Satya It is showing the same error Commented Sep 6, 2014 at 7:07
  • @LeeAllan Yes it still breaks after changing the numbers Commented Sep 6, 2014 at 7:07

1 Answer 1

1
public class Program1
{
    public static void main(String [] args)
        {
             System.out.println("Name:\n\tSalwan Yousif\n");
             System.out.println("Major:\n\tHomeland Security\n");
             System.out.println("Reason for taking course:\n\tIt's required for my major\n");
             System.out.println("Pase of course:\n\tJust a bit too fast\n");
             System.out.println("General feedback:\n\tI'll do my best to pass this class\n");
        }
}

Save it as a Program1.java You don't need any external applications to run this. Open you terminal/cmd and go to location when you stored that Program1.java and type

javac Program1.java and press ENTER

java Program1 and press ENTER

You will see output of your program in terminal/cmd.

If that commands not workings it means that you don't hav set javac path in your windows. I found the simplest manual as I could which is available HERE or HERE instruction on youtube

Just make sure you are adding correct path to YOUR system environement. To find out that open windows explorer(WIN + E), go to program files, find java jdk, find your bin folder. You will see on the top full path to that folder. Copy this and follow tutorial I gave you

Sign up to request clarification or add additional context in comments.

4 Comments

When I write the first command then it is showing, "'Javac' is not recognized as an internal or external command, operable program or batch file. " And when for second command it is showing "Error: Could not find or load main class Program1".
that means you do not have jdk installed. Please check your installation and see to it that jdk installation dir ins added in path and jdk/lib dir is added in classpath
@DavidR. I edited my answer with solution how to solve that problem too
@DavidR. it has to work. I checked that by myself. You are doing something wrong. Have you watched that youtube link and followed each step ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.