Help coderanch get a
new server
by contributing to the fundraiser
  • 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

JAVA_HOME or $JAVA_HOME

 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Coleagues, A caption of Exam Watch in chapter 10, page 805 of the K&B says quote: "If you see something like JAVA_HOME or $JAVA_HOME in an exam question it just means 'That part of the absolute classpath up to the directories we're specifying explicitly'." Can anybody explain this further with an example of a possible exam question, or any syntax that can explain it further?, in my last exams two of the questions had options of JAVA_HOME and I simply was NOT 100% sure of what to answer....'Absolute classpath up to directories we're specifying explicitly' ???.
A thorough explanation will be sincerely appreciated. Thanks.
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JAVA_HOME environment variable generally points to the directory where JDK is installed. Now I've never seen any question which uses it so I'm not sure how its used in questions. Basically its an alternative to the complete path of the java installation. So instead of saying

javac -cp C:\Program Files\Java\jdk1.6.0_20\lib\tools.jar

you can say

javac -cp %JAVA_HOME%\lib\tools.jar
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:

Instead of saying

javac -cp C:\Program Files\Java\jdk1.6.0_20\lib\tools.jar

you can say

javac -cp %JAVA_HOME%\lib\tools.jar



Hello Ankit... If I understand what you mean;

Absolute classpath = " C:\Program Files\Java\jdk1.6.0_20 "

Directory specified explicitly = " \lib\tools.jar "

Okay...I hope this is correct, however thanks for your response.

 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:The JAVA_HOME environment variable generally points to the directory where JDK is installed. Now I've never seen any question which uses it so I'm not sure how its used in questions. Basically its an alternative to the complete path of the java installation. So instead of saying

javac -cp C:\Program Files\Java\jdk1.6.0_20\lib\tools.jar

you can say

javac -cp %JAVA_HOME%\lib\tools.jar



I defined a default classpath, using the OS environment variable, through the following steps:

-name JAVA_HOME

-value C:\myProject\classes

In the command prompt, I tried to run the class I have in the directory as follows:

java -cp JAVA_HOME com.threads.Reader

It provoked a NoClassDefFoundError, I dont know where I am going wrong.

Please note that the name of the class is ( Reader ), and it is declared in package ( com.threads ),
derived from super-directory ( C:\myProject\classes ), what have I done wrong??.

I will be greatfull if you can help.


 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ikpefua.

I'm no expert on dos and handling variables in it, but I believe you should just write it variable like Ankit did and it should work. That is:

java -cp %JAVA_HOME% com.threads.Reader

Also note that you need to open up a new dos-prompt after you have set the environment variable JAVA_HOME, or else it will not be updated in your prompt.

Regards,
Andreas.
 
Ranch Hand
Posts: 300
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JAVA_HOME generally points JDK directory in your computer no matter where it installed and referred by scripts classpath etc. you may find my blog post about How Classpath works in Java interesting.

but frankly speaking I have not seen any question using JAVA_HOME in exams if by any chance they use they might suggest where it is pointing or simply for reference purpose.
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Javin Paul wrote:
but frankly speaking I have not seen any question using JAVA_HOME in exams if by any chance they use they might suggest where it is pointing or simply for reference purpose.



Hello Javin, firstly thanks for the information I will check on it. Secondly I dont think it is necessary to debate about what we have seen or what we have NOT seen about a question that may or may NOT be asked in the exams, the MOST important thing here is that I took the real exams and I got FOUR questions on fundamentals and TWO of those FOUR questions had options like this:

A. JAVA_HOME source\com\wickedlysmart\myClass.java

B. JAVA_HOME classes com.wickedlysmart.myClass

C. More stuff

D. More Stuff

E. More Stuff

In my exam retake I want to go there 100% guarranteed that I know exactly what JAVA_HOME represents, I am asking if someone can help explain with syntax, directory with thorough details if possible etc. I will sincerely appreciate that effort. Thanks for your understanding.
 
Andreas Svenkson
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am honestly not sure what you are asking Ikpefua. Like Ankit and Javin have pointed out, JAVA_HOME tends to point to where you have installed your jdk, although on my system it doesn't even exist.
No matter where it points though (assuming it exists), you can always use it to specify a path in a DOS-command prompt, by writing: %JAVA_HOME%, no matter what you are trying to do (compile or run, etc), just like any other path I would reckon.

As stated, if you want to use this variable to execute a class, you could for instance write: java -cp %JAVA_HOME% <package>.<classname>
(Don't forget the '%' at the start and end, I think thats where you went wrong earlier?)

But perhaps this is not even what you are wondering about?

Regards,
Andreas.
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Anreas, @Javin, @Ankit Thank you all very much, your information together with the videos I watched at you tube helped me to resolve my puzzle. JAVA_HOME is used to set a default classpath in the OS environment variables and like I said earlier I saw a complete visual description in youtube, you know when I have difficulties in understanding, I always like seeing 'codes-in-action'. Once again thanks to you all!.
 
Dinner will be steamed monkey heads with a side of tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic