Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set up JDK to start executing programs

 
Daniel Andres
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone

I just got the book to get the certification for OCA Java SE 8 programmer I

Last year, I followed all of the instructions to download JDK and I hope I did it right. In the image that you can see, some parts read JRE but using the help eclipse I selected the JDK. This program is very complex and the tutorial is long. Nevertheless, I have spent a few hours going over the basics but I am not sure how to fully set it up. If anyone has the same book by Jeanne Boyarsky and Scott Selikoff on page 6, I am trying to execute the first program:

$javac Zoo.java

$ java Zoo

it says to make sure that "you have added it to the PATH". I am frustrated because I want to keep studying the book but I want to do the exercises. Please help me out





I have never run any Java programs but I have knowledge on how Java works. I just need help setting it up to start programming.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel,
Welcome to CodeRanch!

The book gives instructions for writing a command line program. The PATH is an environment variable. On Windows, you set a user environment variable. If you want to use Eclipse, this shows how to set up a JDK. I recommend practice with the command line as you study as you will learn more. It looks like you do have the JDK set up though and are up to using Eclipse to create a new class file named Zoo.

Also note that the book recommends this is your second Java book. It moves fast if you've never done any Java before.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daniel Andres,

First of all, a warm welcome to CodeRanch!

Daniel Andres wrote:I have never run any Java programs but I have knowledge on how Java works. I just need help setting it up to start programming.

When you have none or little experience with Java (and compiling/running Java programs) the best way is to use the command line, not an IDE. At first, it will be a little harder because the IDE does several things automatically for you (like compiling all classes when you make a change). It also gives you code completion, spots compiler errors,... But on the exam you don't have the Java compiler at your disposal and thus you have to spot the compiler errors yourself, you have to know parts of the Java API and so on. That's why I always advice to use your favourite text editor and javac + java to create, compile and run Java programs.

To create, compile and run your first Java program, follow the steps from the "Hello World!" application lesson (of Oracle's Java Tutorials). Choose for the command-line instructions of either Microsoft or Linux (not NetBeans IDE).

If you still have some doubts and/or questions after reading both threads, just hit the reply button and let us know

Hope it helps!
Kind regards,
Roel
 
Daniel Andres
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jeanne Boyarsky and Roel!

Roel De Nijs wrote: To create, compile and run your first Java program, follow the steps from the "Hello World!" application lesson (of Oracle's Java Tutorials). Choose for the command-line instructions of either Microsoft or Linux (not NetBeans IDE).


Roel, I installed and set up NetBeans and I was able to compile and run Hello World. If you use the same program, do you know why after I clicked run / Build Project (HelloWorldApp) it didn't open the output Hello_World_App window as you can see here



However, when I ran the main project it worked



Is this an issue as I advance with more programs?

---------------------------------------------------------------------------------------------------------------------------

If you looked back at the image of the page that I posted on my previous post, could you tell me what this means? What is that dollar symbol? I am currently reading that is an inner

$ javac Zoo.java

$ java Zoo

As I said, I have never programmed in Java so I am not familiar with all of the the symbols yet. I am looking for information online but nothing refers back to this example.

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once more, I would not use an IDE at all. Not NetBeans, not Eclipse, no IDE at all.

Daniel Andres wrote:Roel, I installed and set up NetBeans and I was able to compile and run Hello World. If you use the same program, do you know why after I clicked run / Build Project (HelloWorldApp) it didn't open the output Hello_World_App window as you can see here

I'm not a NetBeans user so no clue at all

Daniel Andres wrote:If you looked back at the image of the page that I posted on my previous post, could you tell me what this means? What is that dollar symbol? I am currently reading that is an inner

$ javac Zoo.java

$ java Zoo

The dollar sign is indeed used internally by the compiler to decorate names of .class files of inner classes. But inner classes is not on the OCAJP exam (it's on the OCPJP one). So no need to worry about it here! In this context it's nothing more than the shell prompt on a Linux/Unix machine. On a Windows machine a > is often used.

Let's assume you have written the Java source code file Zoo.java
Next you'll open a command prompt and then you can compile and run the program using these commandsThe above commands will only work if both javac and java are on the PATH system variable. More info and a step-by-step guide can be found here.

Hope it helps!
Kind regards,
Roel
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used NetBeans. It (annoyingly) insists that the project you want to run be designated as the main project. So yes, that's normal.
 
Daniel Andres
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:Once more, I would not use an IDE at all. Not NetBeans, not Eclipse, no IDE at all.


Got it!

I was finally able to add it to the PATH so that I could work with command prompt

The above commands will only work if both javac and java are on the PATH system variable. More info and a step-by-step guide can be found here.

Thank you so much! It took me a long time to set it up, more than it should have, but I am happy now that I can continue with the book

 
Daniel Andres
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:I have used NetBeans. It (annoyingly) insists that the project you want to run be designated as the main project. So yes, that's normal.


Thank you
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Andres wrote:Thank you so much! It took me a long time to set it up, more than it should have, but I am happy now that I can continue with the book

Glad to hear you sorted everything out and you are now up and running, ready to produce a gazillion of code snippets!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic