• 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

difference b/w absolute path and relative paths

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
I am a bit confused about absolute and relative paths.Can anyone explain me the differences between the two through some implementatins.For example if my class in one package want to access a class in some other package.
What are the subtlities between the two.

Thanks in advance.
Himani
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Relative path depends on where your current directory is. Absolute directory doesn't.

For example:
Let's say you have this directory structure.

If let's say you are now in the user directory and you want to go one level up, for relative path, you just need to do 'cd mydir'. If you want to use absolute path, you need to do 'cd /home/user/mydir'.
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
  • Relative Path : Its relative to the present directory where you are in.
  • Absolute Path: Its a path from the root drive which is the starting point of all the paths in that drive.


  • In terms of Windows OS terminology,

    Let's say you have a directory structure like

    C:/MyPrograms/Java/Basics/Primitives/IntegerTest.java
    C:/MyPrograms/Java/Basics/Primitives/Props/MyProperties.txt



    And assume you are in the "Primitives" directory and in your IntegerTest.java file you need to refer the MyProperties.txt file.

    In case of relative path, it would be "/Props/MyProperties.txt". Note that it just starts from the current location where you are in. (or your program resides at the moment).

    In case of absolute path, it SHOULD be the full path from the root drive ("C:") as "C:/MyPrograms/Java/Basics/Primitives/Props/MyProperties.txt".

    Hope this helps.
    [ August 09, 2007: Message edited by: Raghavan Muthu ]
     
    Himani Gulati
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hello,
    Thanks for your reply.Actually I am uable understand questions of the following type.Can you please tell me the reason behind the correct answer of the question and more importantly why others are not correct.

    Given the default classpath:
    /foo

    And this directory structure:

    foo
    |
    test
    |
    xcom
    |--A.class
    |--B.java


    And these two files:
    package xcom;
    public class A { }

    package xcom;
    public class B extends A { }


    Which allows B.java to compile? (Choose all that apply.)
    A. Set the current directory to xcom then invoke
    javac B.java
    B. Set the current directory to xcom then invoke
    javac -classpath . B.java
    C. Set the current directory to test then invoke
    javac -classpath . xcom/B.java
    D. Set the current directory to test then invoke
    javac -classpath xcom B.java
    E. Set the current directory to test then invoke
    javac -classpath xcom:. B.java



    Answer: C
     
    Himani Gulati
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I am unable to understand why ...option D and E are not correct answers in the above question.


    Looking forward for your reply.
    Thanks
     
    Raghavan Muthu
    Ranch Hand
    Posts: 3389
    Mac MySQL Database Tomcat Server
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Himani Gulati:
    I am unable to understand why ...option D and E are not correct answers in the above question.


    Looking forward for your reply.
    Thanks



    Why do you think they should be correct?
     
    Ranch Hand
    Posts: 377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Raghavan Muthu:
    In case of relative path, it would be "/Props/MyProperties.txt".

    Small correction. It should be "Props/MyProperties.txt" (without the first slash).
     
    Freddy Wong
    Ranch Hand
    Posts: 959
    Eclipse IDE Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    C. Set the current directory to test then invoke
    javac -classpath . xcom/B.java


    C is correct because now you are in test and B.java is in xcom, that's why you need xcom/B.java. And because B requires class A, you need to specify the classpath to the current directory in order for B to be able to find A.


    D. Set the current directory to test then invoke
    javac -classpath xcom B.java


    D is wrong because now you are in test and the B.java is in xcom directory.


    E. Set the current directory to test then invoke
    javac -classpath xcom:. B.java


    E is wrong for the same reason as D.
     
    Raghavan Muthu
    Ranch Hand
    Posts: 3389
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Manfred Klug:
    Small correction. It should be "Props/MyProperties.txt" (without the first slash).




    It was a typo! Thanks Manfred
     
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,
    Is getAbsolutepath and path related stuffs are included in scjp 1.5 exam
    Could anyone tell me

    Thanks,
    Sumi
     
    Raghavan Muthu
    Ranch Hand
    Posts: 3389
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I am not too sure sumi selva though it does not look like having much significance on the exam.

    Probably the ranchers who had taken the 1.5 exam could help!!
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic