-
New to Java
Hi, I'm new to Java and this forum.
I have some other programming experience in C++ and Visual Basic, but I would like to learn Java.
Anyway, I downloaded the JCreator free compiler, I found some Hello World code
Code:
/**
* The HelloWorldApp class implements an application that
* simply displays "Hello World!" to the standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}
But when I compile to code, a DOS command box comes up and gives me the error:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
Press any key to continue...
What do I need to do to fix this error? Thanks.
-
You need to set the CLASSPATH environment to include the folder(directory) where your class is written so the interpreter will find it.
An easy way to do this is to run a batch file when you get out to the DOS window. Set it up to change to the folder in which you'll be storing your .java files; this will prompt the compiler to look here for the .java source file and include this directory for looking for any included classes; and when you invoke the java interpreter it will look in this folder and any other folder in your ClassPath in its search for the .class files.
JavaSet.bat:
cd C:\JavaWork;
set CLASSPATH=C:\JavaWork;
-
 Originally Posted by Kramer55
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
Press any key to continue...
The compiler tells you that it can't find the .class file of your application. You'll need to compile it first by typing this command in the folder of your .java file:
c:\ ... \your app folder\javac HelloWorldApp.java
after that run your progrma by doing:
c:\ ... \your app folder\java HelloWorldApp
Good luck!
-
 Originally Posted by prometheuzz
You'll need to compile it first by typing this command in the folder of your .java file:
c:\ ... \your app folder\javac HelloWorldApp.java
after that run your progrma by doing:
c:\ ... \your app folder\java HelloWorldApp
Good luck!
Sorry, but what exactly do you mean by "typing" the command in the folder?
Do I need to make it a .bat file? If so how?
-
I think he means:
Open a DOS window / Command Prompt - A black window
cd (change directory) to the folder with your java file
and then type in the commands as show above.
If the java.exe and javac.exe commands are found on PATH you wouldn't need the full path.
On my system (WIn98) when I searched for the command files I got:
Found java.exe in:
C:\Java\j2sdk1.4.1\bin\ 08/29/02 02:10 AM
C:\WINDOWS\ 03/04/05 05:47 PM
Found javac.exe in:
C:\Java\j2sdk1.4.1\bin\ 08/29/02 02:10 AM
The java.exe command has been copied into the WINDOWS folder and is on the path.
I also have an old version of java.exe from SDK version 1.4.1 and a new one from jre 1.4.2_08.
The javac.exe command is in the development folder. So you need to set PATH for that.
In the DOS window, enter: SET to see what the value of PATH and CLASSPATH is along with the other environment variables.
A sample batch file: enter these two lines with NotePad and save as Java.bat
Change the path to be to the location on your system.
@REM Run JDK1.2 JVM
C:\Java\jdk1.2\bin\Java.exe %1 %2 %3 %4 %5
The %x args will be substitued for when you use the batchfile.
For example: java.bat MyClass -argtoPgm ...
Or you could replace the %1 %2 ... with: MyClass -argtoPgm ...
Last edited by Norm; 08-10-2005 at 04:17 PM.
-
 Originally Posted by prometheuzz
c:\ ... \your app folder\javac HelloWorldApp.java
after that run your progrma by doing:
c:\ ... \your app folder\java HelloWorldApp
Whenever I try to type that (C:\Java\Programs\javac HelloWorld.java) in the same folder where my programs are saved, I get the error:
'JAVAC' is not recognized as an internal or external command, operable program or batch file.
Last edited by Kramer55; 08-10-2005 at 08:12 PM.
-
If you don't have the Sun java compiler but rather:
"I downloaded the JCreator free compiler"
If this is a compiler or has a compiler and is not just a IDE then somewhere in its folders there must be a command that does compiles. For the SDK that one downloads from Sun the name of the compiler is: javac.exe.
Have you entered: ... javac.exe or just javac? Try adding the .exe.
I recommend that you go to the Sun site and download the SDK.
Is there any doc with the JCreator package that gives the name of its java compiler?
It would help if you would copy the Command prompt screen and post it here so we can see the command that you are entering and the system's response.
The message you posted earlier:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
shows that you probably have the jave.exe command available.
Last edited by Norm; 08-10-2005 at 08:21 PM.
-
I have the java.exe and the javac.exe commands available; they are in the .bin folder of the J2SE 5.0 that I DLed from Java.
Is that the correct SDK to DL? If not, which is the correct one?
-
That sounds OK. Now run your tests in the command prompt, copy and post the results.
Also type: SET on the comand prompt to see what the environment variables are set to.
Did you try with javac.exe and java.exe vs without the .exe?
-
Stupid question, but how do I take shots of the command prompt?
is it with the Print Screen button? How do I access the shots?
Thanks.
Yes, I did try the javac.exe, I'll post the results when I figure it out.
-
I'm on Win98 so the technique might be different to get a copy of the screen. After openning a DOS/Command prompt, on the left of tool bar there is a dotted box (shows as Mark under the cursor). Click that and a white box wll appear at the upper left of the window. User the cursor to drag the edges of the box to cover/select what you want to copy. Then back on the toolbar there is a button that will Copy what you've selected to the clipboard. Then open Notepad and Paste the clipboard into the doc. Edit, file and post.
-
Here's what I get when I run javac.exe
C:\JAVA\BIN>javac.exe
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are u
sed
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
Here's the same error when I run HelloWorld.java
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
Press any key to continue...
Do I need to use the <classpath> command from javac.exe?
-
More DOS stuff
Some confusion here.
javac.exe is the compiler
java.exe is the interpreter (executes a class file);
Both commands require parameters.
Javac.exe minimally requires the name of the java source file to compile. For example:
javac.exe HelloWorld.java
In your example, you left off the source filename
You didn't post the full screen results for executing the java.exe. Please copy and paste EXACTLY what is entered and the results!
The java.exe command expects the name(path actually) of the class to execute. It makes some assumptions that you'll learn about later when you start using Packages. For now you use just the filename of the class file without the .class extension:
java.exe HelloWorld
The .exe is redundant, but should always work.
Do this and copy the results.
Also while in the folder where your test programs are, Enter the command: dir
This will show you what files are in that folder. You should see at least these two:
HelloWorld.java and HelloWorld.class If not, somethings wrong.
Last edited by Norm; 08-11-2005 at 10:27 AM.
-
Here's everything from the java.exe command
Microsoft(R) Windows DOS
(C)Copyright Microsoft Corp 1990-2001.
C:\DOCUME~1\FAMILY>cd C:\Java
C:\JAVA>DIR
Volume in drive C has no label.
Volume Serial Number is 08C3-7B4C
Directory of C:\JAVA
08/10/2005 08:06 PM <DIR> .
08/10/2005 08:06 PM <DIR> ..
08/10/2005 08:06 PM <DIR> bin
06/03/2005 04:32 AM 2,539 COPYRIGHT
08/10/2005 07:37 PM <DIR> demo
08/10/2005 07:37 PM <DIR> include
08/10/2005 07:39 PM <DIR> jre
08/10/2005 07:39 PM <DIR> lib
06/03/2005 03:35 AM 15,848 LICENSE
08/10/2005 07:37 PM 21,223 LICENSE.rtf
08/10/2005 08:06 PM <DIR> Programs
06/03/2005 03:35 AM 20,955 README.html
08/10/2005 07:37 PM <DIR> sample
06/03/2005 03:35 AM 18,053,285 src.zip
06/03/2005 03:35 AM 69,740 THIRDPARTYLICENSEREADME.txt
6 File(s) 18,183,590 bytes
9 Dir(s) 103,697,891,328 bytes free
C:\JAVA>bin
'BIN' is not recognized as an internal or external command,
operable program or batch file.
C:\JAVA>cd c:\java\bin
C:\JAVA\BIN>DIR
Volume in drive C has no label.
Volume Serial Number is 08C3-7B4C
Directory of C:\JAVA\BIN
08/10/2005 08:06 PM <DIR> .
08/10/2005 08:06 PM <DIR> ..
06/03/2005 03:29 AM 49,274 appletviewer.exe
06/03/2005 03:29 AM 49,263 apt.exe
06/03/2005 04:09 AM 36,975 beanreg.dll
06/03/2005 03:29 AM 49,272 extcheck.exe
06/03/2005 03:53 AM 24,576 HtmlConverter.exe
06/03/2005 03:29 AM 49,274 idlj.exe
06/03/2005 03:29 AM 49,255 jar.exe
06/03/2005 03:29 AM 49,276 jarsigner.exe
06/03/2005 03:29 AM 49,248 java.exe
06/03/2005 03:29 AM 49,269 javac.exe
06/03/2005 03:29 AM 49,275 javadoc.exe
06/03/2005 03:29 AM 49,269 javah.exe
06/03/2005 03:29 AM 49,265 javap.exe
06/03/2005 03:29 AM 49,250 javaw.exe
06/03/2005 03:53 AM 127,078 javaws.exe
06/03/2005 03:29 AM 49,274 jconsole.exe
06/03/2005 03:29 AM 49,278 jdb.exe
06/03/2005 03:29 AM 49,259 jps.exe
06/03/2005 03:29 AM 49,265 jstat.exe
06/03/2005 03:29 AM 49,268 jstatd.exe
06/03/2005 03:29 AM 49,272 keytool.exe
06/03/2005 03:29 AM 49,268 kinit.exe
06/03/2005 03:29 AM 49,268 klist.exe
06/03/2005 03:29 AM 49,266 ktab.exe
06/03/2005 03:29 AM 49,286 native2ascii.exe
06/03/2005 03:29 AM 53,383 orbd.exe
06/03/2005 03:29 AM 49,280 pack200.exe
06/03/2005 03:53 AM 69,745 packager.exe
06/03/2005 03:29 AM 49,278 policytool.exe
06/03/2005 03:29 AM 49,260 rmic.exe
06/03/2005 03:29 AM 49,266 rmid.exe
06/03/2005 03:29 AM 49,278 rmiregistry.exe
06/03/2005 03:29 AM 49,277 serialver.exe
06/03/2005 03:29 AM 49,299 servertool.exe
06/03/2005 03:29 AM 53,392 tnameserv.exe
06/03/2005 03:29 AM 127,101 unpack200.exe
36 File(s) 1,921,082 bytes
2 Dir(s) 103,697,891,328 bytes free
C:\JAVA\BIN>java.exe
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
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
C:\JAVA\BIN>
-
I lost you somewhere. What I am interested in is the contents of YOUR folder, not that of the java stuff. You should have your own folder for your programs. Don't mess around in the java stuff. There are very few files that you can add to the java folders. None at your level.
What you need to do is go to the folder with your programs. Use the CD command.
Compile the program that is in your folder with the javac.exe command:
javac Helloworld.java
If there are no errors, execute it:
java Helloworld
If there are error messages, correct them otherwise copy and post the screen.
How did you do C and Basic. You must have had an IDE that isolated you from all this.
Similar Threads
-
Replies: 2
Last Post: 06-14-2006, 03:16 PM
-
Replies: 1
Last Post: 05-13-2005, 06:46 AM
-
By Rob Abbe in forum Talk to the Editors
Replies: 44
Last Post: 01-13-2003, 02:57 PM
-
By Mike Tsakiris in forum .NET
Replies: 11
Last Post: 10-04-2002, 05:32 PM
-
By JJ in forum Enterprise
Replies: 1
Last Post: 07-06-2000, 04:50 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks