Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Starting out with Java

Posted on 2001-08-06
5
Medium Priority
?
335 Views
Last Modified: 2013-11-23
I'm having real problems getting started with Java . . .
I've downloaded the JDK 1.4 from Sun, but I can't seem to get my program compiled.
I'm running Windows ME and I've set the path, following the installation notes, but when I go to MSDOS and type the name of my program (a simple 5 line program copied from an introductory book on Java, written on Notepad) - it doesn't work.

I type javac Hello.java, and I get the message

error: cannot read Hello.java

So the compiler can't find the text file of the program I've written in notepad - but how do I get it to find then compile the file (which is stored in C\jdk1.4\bin)?

Do I need to type another line of code so that the compiler can find my program - and if so what code or path instructions do I need?

I'm sure this is a trivial problem, but It's very frustrating because it's stopping me from getting started with Java.

Any suggestions would be very warmly welcomed.

David E.Quinn
0
Comment
Question by:davidedwardquinn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 6355275
Check your classpath settings.
The first item should be "." - i.e. current working directory.

To test this go to a command prompt and type :

    echo %CLASSPATH%

This should show your classpath.
It should start .;

If it doesn't type :

    set CLASSPATH = ".;%CLASSPATH%"

Then try javac Hello.java from the same directoiry that Hello.java is stored in.

If you still have problems try using the full path to Hello.java :

    javac c:\directory\Hello.java
0
 

Expert Comment

by:MarkShark
ID: 6355797
I recommend downloading a program called JCreator from the following site: www.jcreator.com

It's easier to set up and compile your scripts than using DOS.

Good Luck
0
 
LVL 8

Accepted Solution

by:
DennisBorg earned 200 total points
ID: 6355816
David:

>I type javac Hello.java, and I get the message
>
>error: cannot read Hello.java
>
>So the compiler can't find the text file of the program
>I've written in notepad - but how do I get it to find
>then compile the file (which is stored in C\jdk1.4\bin)?

Here are a few things which should help you get started.

1) The name, spelling, and capitalization of the file name, must match exactly as you have named your class. For example, if you have declared your class as follows:

   class David {
   }

Then the name of the file must be "David.java".

DAVID.java and david.java will not work.



2) You can add C:\jdk1.4\bin to your PATH statement, so that DOS can find javac without your explicitly specifying the path. Then, from the directory where your java file is, you can issue a command like the following:

   javac Hello.java

Or, you can give the full path of where javac is located:

   C:\jdk1.4\bin\javac Hello.java



3) While in the C:\jdk1.4\bin directory, you can explicitly specify the location of your Hello.java file:

   javac C:\MyJavaFiles\Hello.java


4) You can always (from whatever directory you're in) explicitly specify the location of both javac and your Hello.java file:

   C:\jdk1.4\bin\javac c:\MyJavaFiles\Hello.java


-Dennis Borg
0
 

Expert Comment

by:rgiacalone
ID: 6355957
Hi, you should create a .bat file with lines:

javac -classpath %CLASSPATH% Hello.java
pause
java  -classpath %CLASSPATH% Hello
pause

and even add any class or .jar you need after %CLASSPATH%,
example:

javac -classpath %CLASSPATH%;classes12.zip Hello.java
pause
java  -classpath %CLASSPATH%;classes12.zip Hello
pause

be sure to have your %CLASSPATH% variable set to at least value:    .;<jdk installation path>\lib\tools.jar

hope this answer will be useful to you.
Romain.
0
 

Expert Comment

by:SpideyMod
ID: 8289604
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question