• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Javac compiler won't start!! can't compile any code

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys and girls, I'm new to Java I'm learning it from the great book "Head First Java", but I'm having a problem. I can't compile any java code because my "javac" compiler in the /bin subdirectory of the /jdk1.5.0_04 doesn't want to run when I click on it. What's going on with it? Someboy please help me, I can't learn Java if I can't compile it.
[ July 28, 2005: Message edited by: Elwal Vador ]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Elwal

The javac program is a commandline utility. Double clicking it will not work. I haven't read the book you are using but I'm sure it will show examples of how to compile from the command line (I assume you are familair with the commandline?). It should also walk you through setting your PATH and CLASSPATH variables. There are lots of good starter tutorials on how to do this if you careto google for them.

Let me know if you're still having a problem.

Andrew
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Although I do not recommend this approach. If your .java file is in the same directory as the javac.exe program, it is possible to drag the .java file onto the javac.exe icon and your program will compile if it is a simple class.
 
Elwal Vador
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, this book was written by Kathy Sierra and according to the book she is the founder of this very web-site. That's why she reffered me to this web-site, through the book, if I was having problems installing the compiler.

Command line, you mean the MS-DOS Prompt right? The book simply tells me to type this in, 'javac myfirstapp.java' and then in another page it tells me to type this in '%javac myfirstapp.java' but it doesn't tell me where I need to type that in. I tried it in the DOS promt and I get a 'Bad command or file name'.

Also nigel I tried dragging the myfirstapp.java file onto the javac.exe but nothing happend.
[ July 28, 2005: Message edited by: Elwal Vador ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The drag-and-drop thing is just going to make a mess -- don't do it.

The "%" in the one example is a Macintosh (i.e., UNIX) system prompt. Don't type it. Just pretend it says "C:\> javac ..." instead!

Now: if you type "javac Foo.java" and you see an "Unrecognized command or filename" this just means that the JDK isn't on your path. Open your "system" control panel, and add "c:\jdk1.5.0_04\bin" to your PATH environment variable. Note that PATH entries are separated by a ";" (semicolon). Then open a new command window, and type "javac". It should show you usage information. If it doesn't, you didn't do the PATH thing correctly; go back and try again.
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to add the javac command to your PATH variable (assumin you have installed the JDK)

If you are on Windoze right click "My Computer", Click "Advanced" then "Environment Variables"

In here you can edit your system and user variables. Find the one that is called path and append the path to the "bin" directory of your java development kit (It is a top level directory in the location where you installed your JDK).

You append the path by putting a semi-colon at the end of the PATH variable String followed by the path to your JDK (mine would be ;C:\jdk5\bin)

Open a new DOS prompt and type javac and it should work.

Happy compiling
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This page may help you get started. You need to set up your PATH. After you successfully type 'javac myfirstapp.java' at the "MSDOS" command prompt and get a myfirstapp.class file (no errors), you'll want to type 'java myfirstapp' (without the '%') in the same window (after the C:\>\yourSourceDirectory) prompt.
 
Nigel Browne
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you 100% sure nothing happened? Have you looked for the newly created myfirstapp.class file?
It is this file that is run in the JVM.
Command line is synonymous with DOS Prompt. Developers working on unix/linux or mac platforms dont have a dos prompt but a command line prompt.
If you open a dos prompt and type javac followed by pressing the enter button what do you get in response?
 
Elwal Vador
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ernest Friedman-Hill:
The drag-and-drop thing is just going to make a mess -- don't do it.

The "%" in the one example is a Macintosh (i.e., UNIX) system prompt. Don't type it. Just pretend it says "C:\> javac ..." instead!

Now: if you type "javac Foo.java" and you see an "Unrecognized command or filename" this just means that the JDK isn't on your path. Open your "system" control panel, and add "c:\jdk1.5.0_04\bin" to your PATH environment variable. Note that PATH entries are separated by a ";" (semicolon). Then open a new command window, and type "javac". It should show you usage information. If it doesn't, you didn't do the PATH thing correctly; go back and try again.



ok I opened the control panel, I clicked on system but I couldn't find any path tabs or options, Im using windows 98. I did however find a java in my control panel I clicked on that and founf 'java application run time" and under path it had C:\Program Files\Java\jdk1.5.0_04\bin\javaw.exe and also C:\Program Files\Java\jre1.5.0_04\bin\javaw.exe

so then I tried in dos, javaw myfirstapp.java and this came out in title bar 'java virtual machine launcher' Could not find main class. Program will exit.
 
Elwal Vador
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rick Beaver:
You need to add the javac command to your PATH variable (assumin you have installed the JDK)

If you are on Windoze right click "My Computer", Click "Advanced" then "Environment Variables"

In here you can edit your system and user variables. Find the one that is called path and append the path to the "bin" directory of your java development kit (It is a top level directory in the location where you installed your JDK).

You append the path by putting a semi-colon at the end of the PATH variable String followed by the path to your JDK (mine would be ;C:\jdk5\bin)

Open a new DOS prompt and type javac and it should work.

Happy compiling



OK I right cliked on my computer but there is no 'advanced' tab I'm using windows 98.
 
Elwal Vador
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nigel Browne:
Are you 100% sure nothing happened? Have you looked for the newly created myfirstapp.class file?
It is this file that is run in the JVM.
Command line is synonymous with DOS Prompt. Developers working on unix/linux or mac platforms dont have a dos prompt but a command line prompt.
If you open a dos prompt and type javac followed by pressing the enter button what do you get in response?



Yea I checked no new class files.
If I type in javac nothing happens, I get "bad command or file name"
 
Rick Beaver
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Elwal Vador:


OK I right cliked on my computer but there is no 'advanced' tab I'm using windows 98.



OK - not sure how to do it globally in 98

In your DOS window try typing:

set PATH=%PATH%;C:\Your\JDK\bin

Then doing a javac - this will set it locally for your current command window I think - this would be short term fix - google up environment variables in windows 98 and figure out how to change your PATH globally.
 
Elwal Vador
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK I finally got it to attempt to compile the .java file by typing in

javaw myfirstapp.java

but now this error keeps comming up, in the toolbar is says "Java Virtual Machine Launcher" and inside the window it says "Could not find main class. Program will exit." and then it has an "OK" button.

And this is the sorce code I'm trying to compile that I copied right from the book,

public class myfirstapp {

public static void main (String[] args) {
System.out.printLn("I rule");
System.out.printLN("The world");
}
}

I think It's because I have this antiqauted 98 OS, piece of SHHHH. Man I was all exited when my book came I was finally going to start learning Java, now I have to buy a new laptop.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"javac.exe" compiles a *.java file, meaning it creates a *.class file out of it.

"javaw" runs a compiled *.class file, detaching itself from your terminal in the process, thus hiding most error messages.

"java" runs a class file without the detaching part.

Note that the argument to "javac" is the name of a file, while the argument to the others is the name of a class; so

javac myfirstapp.java

but then

java myfirstapp
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you can do is , Since it's Win 98, update the autoexec.bat file
Check whether you have any line like Path=%Path%;C:\windows...
If you find that then append your jdk\bin path to the PATH variable. ( as mentioned in the above posts ).

Before Updating the autoexec.bat better take a back up of it & proceed.
 
Elwal Vador
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srinivasa Raghavan:
What you can do is , Since it's Win 98, update the autoexec.bat file
Check whether you have any line like Path=%Path%;C:\windows...
If you find that then append your jdk\bin path to the PATH variable. ( as mentioned in the above posts ).

Before Updating the autoexec.bat better take a back up of it & proceed.



Ok, I have two autoexec.bat's one is in my C:\, the other is in C:\Dosboot\

This is what the one in C:\ has in it

C:\PROGRA~1\NETWOR~1\MCAFEE~1\SCAN.EXE C:\
@IF ERRORLEVEL 1 PAUSE
@echo off


REM To make a DOS Boot Diskette; See the file C:\DOSBOOT\DOSBOOT.TXT

path C:\WINDOWS;C:\WINDOWS\COMMAND


@REM SetPower.exe will initialize the USB Keyboard.

@c:\windows\system\setpower.exe











rem - By Windows Setup - mscdex.exe /d:IDECD000 /L:M


This is what it says in Dosboot

@echo off
REM To make a DOS Boot Diskette, see the file C:\DosBoot\DosBoot.txt.

set path=c:\windows\command

LH c:\windows\command\mscdex /D:IDECD000 /L:M

SET PROMPT=$p$g
SET TEMP=C:\windows\TEMP
SET TMP=C:\windows\TEMP

call c:\dosboot\drivers.bat

c:\windows\smartdrv /q
c:
cd \windows

REM to enable ZIP support in DOS:
REM 1) cd C:\IOMEGA
REM 2) run IOMEGA.EXE
REM 3) then uncomment the following line
REM C:\IOMEGA\GUEST.EXE

REM for DOS Networking including most networked games,
REM read the file IPX.BAT and then uncomment the following
REM CALL C:\DOSBOOT\IPX.BAT
REM for DOS Networking including most networked games,
REM read the file IPX.BAT and then uncomment the following
REM CALL C:\DOSBOOT\IPX.BAT


Which one should I change and what should I type?
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure which auto exec your are using.
What you need to do is .Update your path as mentioned in the above post.
Like Set Path = %PATH%;C:\your JDK\bin\";

First you try this command in a Console, then compile your java code. if it worked then Update your path Permanently through autoexec. But TAKE A BACKUP of the file before updating it. If you are updating the bat file be careful that you are not messing it, else it 'll cause problem in OS.
[ July 28, 2005: Message edited by: Srinivasa Raghavan ]
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Win 9x: Change your PATH in your C:\autoexec.bat file
Type "javac" (nothing else)
Does it give you a "help" screen? or an error like "command not found"?

You need to get javac to work before you can do anything else.
[ July 28, 2005: Message edited by: Marilyn de Queiroz ]
 
Elwal Vador
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srinivasa Raghavan:
I'm not sure which auto exec your are using.
What you need to do is .Update your path as mentioned in the above post.
Like Set Path = %PATH%;C:\your JDK\bin\";

First you try this command in a Console, then compile your java code. if it worked then Update your path Permanently through autoexec. But TAKE A BACKUP of the file before updating it. If you are updating the bat file be careful that you are not messing it, else it 'll cause problem in OS.

[ July 28, 2005: Message edited by: Srinivasa Raghavan ]



I typed in that Set Path but it didn't work.
 
Elwal Vador
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marilyn de Queiroz:
Win 9x: Change your PATH in your C:\autoexec.bat file
Type "javac" (nothing else)
Does it give you a "help" screen? or an error like "command not found"?

You need to get javac to work before you can do anything else.

[ July 28, 2005: Message edited by: Marilyn de Queiroz ]



OK I changed the path in both autoexec.bat, I backed them up too, but still javac still says bad command.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have the JDK folder ( Sorry Just kidding ) ...

Ok now comming to the issue ..
The changes made in autoexec will be reflected only if the machine reboots, so what you do is run the autoexec manually in command prompt.
Close all command prompts, Open a New command prompt
Now type "Set Path" what does it display ?

Check whether the above output has your correct jdk\bin folder in it.
[ July 28, 2005: Message edited by: Srinivasa Raghavan ]
 
Elwal Vador
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it says "Syntax error"

I'm just going to throw my computer in front of a speeding bus.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Elwal Vador:
it says "Syntax error"



Yay! It sounds like you're running javac now! Don't be discouraged -- you're getting to the good part!

So now you're programming! You've written a program, it's made a language ("syntax") error. You fix it, you try again, until it works. That's how it goes!

Show us your code, cut and paste the error message, and we'll help you fix it, if you want!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic