• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Setup  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All, first of all apologies if this is covering old ground, i am new to both Java and this forum (registered but 5 minutes ago). I have searched similar topics but i am still not totally clear of how to resolve my issue.

I have just started the "Head First Java" book and i am trying to compile and run the old "MyFirstApp" from the command line. I would like to use the command line rather than my installed IDE (Eclipse) as i've never really had much exposure to the command line and would like to use it as the book suggests for the first few simple programmes i write.

I am using a work laptop and don't therefore have total admin privileges, which doesn't help. My class path is set to "C:\Program Files\Java\jdk1.5.0_13\bin" and my "MyFirstApp.java" file is saved to the following location: "C:\Program Files\Java\Head First Tutorials".

How do i compile the .java file using the command line, which directory do i need to be in and what cmd line instruction do i type? I tried a few things without success and would be blind guessing with anything i might try now, hench this post.

Cheers in advance for any help.


 
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Alexander wrote: I tried a few things without success

what you have tried? perhaps, this help?
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Daniel Alexander wrote:My class path is set to "C:\Program Files\Java\jdk1.5.0_13\bin" and my "MyFirstApp.java" file is saved to the following location: "C:\Program Files\Java\Head First Tutorials".

Your classpath should not be set to the bin directory of your JDK installation. The classpath is used by Java to find compiled *.class files. Those are not in the bin directory of your JDK installation. It's best to not set the CLASSPATH environment variable at all. If it is not set, Java will use the current directory to look for class files.

Also, C:\Program Files\Java is not the right place to save your own Java source files. Save them somewhere where you can save normal documents, for example your C:\Users\YourName\Documents directory. Everything under C:\Program Files should only be used for installed software, not your own files.

Daniel Alexander wrote:How do i compile the .java file using the command line, which directory do i need to be in and what cmd line instruction do i type? I tried a few things without success and would be blind guessing with anything i might try now, hench this post.

I don't have Head First Java, but doesn't the book explain that? Anyway, have a look at Oracle's Java Tutorials. The Hello World tutorial explains step by step how to write, compile and run your first Java program from the command line.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and Welcome to JavaRanch
 
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome,

The java compiler is "javac".
The JRE (Runtime) command is "java"

Type those in at the command line in your project folder and see at least if you can run them.

WP
 
Daniel Alexander
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers for the welcome and for the help.

I have moved the files to a folder outside of the Program Files folder and deleted the classpath variable from the environment variables under the system settings.

It wasn't until i typed the following line in a the command prompt that i could get the javac command to work: "C:\Head First Tutorials> set path=%path%;C:\Program Files\Java\jdk1.5.0_013\bin.

Having run the simple app, I then closed the cmd shell and opened up a new cmd shell to see if this "set property" was persistent, unfortunately not and i had to type it out again before the cmd shell would recognise 'javac' as a valid command. I have tried to add an environment variable named "path" to the system environment variable list to have a persistent setting, unfortunately this doesn't seem to have worked. Any ideas???

Dan.
 
Daniel Alexander
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, resolved it. I had replaced the whole Path rather than appending the ";C:\Program Files\Java\jdk1.5.0_13\bin" to the end.

School boy error :s
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First you save the file & go to command prompt then change the drive if you have the save the file in D drive. go to D drive then compile javac filename.java. For output java filename enter

 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Alexander wrote:Sorry, resolved it. I had replaced the whole Path rather than appending the ";C:\Program Files\Java\jdk1.5.0_13\bin" to the end.
School boy error :s

Lesson 1: computers are stupid.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!