I am a EE student who took some C++ classes and is not trying to learn Java. I like to write my code in Notebook++ and want to know how to run in from the Cmd Promt.

I was using Netbean, but I do not like all the code it puts in for you. Maybe one day but I want to code it all myself to ensure I know all the steps from START to END.

I appended my PATH with
(C:\Program Files\Java\jdk1.6.0\bin;) but i still can not run HelloWorld. It worked in NetBean so I know the code is good.

Thanx in advance
Lanier

I like to write my code in Notebook++.

I think you meant Notepad++ :)

Edit:: What's actually your question ? Do you want to compile a C++ program and run it from console (= command prompt) ?

Yes I ment Notepad++

The question is how do i run a Java program from the Cmd Prompt?
Here is what i get when I try and run "HelloWorld"

C:\Users\HAL>java HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: HelloWorld.  Program will exit.

Do you want to compile a C++ program and run it from console (= command prompt) ?

I meant a Java program ...

Edit:: Can you please post your code ?

Here is my code

class HelloWorld
{  
        public static void main(String args[])
        {
           System.out.println("Hello World!");
        }
}

Here is my code

class HelloWorld
{  
        public static void main(String args[])
        {
           System.out.println("Hello World!");
        }
}

Did you save this file under the filename: HelloWorld.java ?

Edit:: I think I've found the problem take look at this ...

Did you save this file under the filename: HelloWorld.java ?

Edit:: I think I've found the problem take look at this ...

I did save the file as HelloWorld.java.

Adding -classpath did not work here is the output.

Microsoft Windows [Version 6.0.6001]
Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

C:\Users\HAL>java -classpath .HelloWorld
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)

where options include:
    -client       to select the "client" VM
    -server       to select the "server" VM...

I also tried
java -classpath.HelloWorld
java -classpath. HelloWorld
java -classpath . HelloWorld

and the console returned "Could not return Java Virtual Machine"

There is no need to mess around with CLASSPATH since Java 1.4, adding direction to Java installation in PATH parameter is sufficient.
So if you change to PATH you can check your set up in Command Prompt, type echo %PATH% that should beside all other things return C:\Program Files\Java\jdk1.6.0_12\bin; also you may check on java by java -version return can be like

java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)

Let me know how this worked out.

There is no need to mess around with CLASSPATH since Java 1.4, adding direction to Java installation in PATH parameter is sufficient.
So if you change to PATH you can check your set up in Command Prompt, type echo %PATH% that should beside all other things return C:\Program Files\Java\jdk1.6.0_12\bin; also you may check on java by java -version return can be like

java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)

Let me know how this worked out.

Seems to work just fine there

C:\Users\HAL>echo %PATH%
C:\Program Files\Java\jdk1.6.0_13\bin;C:\Windows\system32;C:\Windows;C:\Windows\
System32\Wbem;C:\Program Files\CyberLink\Power2Go\;C:\Program Files\MATLAB\R2009
a\bin;C:\Program Files\MATLAB\R2009a\bin\win32

C:\Users\HAL>java -version
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)

Use javac to compile it, and java -jar to run it

commented: This solved the problem THANX +2

Dear,

Set PATH and CLASSPATH environment variables. To do so, Right click on My Computer + Properties + User Variable section.

PATH=C:\Program Files\Java\jdk1.6.0\bin;
CLASSPATH=.;C:\Program Files\Java\jdk1.6.0;

Dear,

Set PATH and CLASSPATH environment variables. To do so, Right click on My Computer + Properties + User Variable section.

PATH=C:\Program Files\Java\jdk1.6.0\bin;
CLASSPATH=.;C:\Program Files\Java\jdk1.6.0;

To set CLASSPATH is not necessary since Java 1.4, why you are ignoring other people posts???

Use javac to compile it, and java -jar to run it

This solved the problem THANX - LanierWexford

To set CLASSPATH is not necessary since Java 1.4, why you are ignoring other people posts???

This thread is finished.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.