Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Environment Variable!!

 
Brian Smith
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi folks,
i found this about System Properties and Environment Variable. System properites is a feature that replaces the concept of
environment variables which is platform-specific
. could you please explain me why environment is a platform specific?
thanks.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi sathi
here r things which will be platform (that is OS) specific,
1. file path separator
- '\' on windows
- '/' on unix based system
- ':' on Mac OS
2. PATH separator
- ';' on windows (see ur autoexec.bat if to see how u specify multiple values for a variable).
e.g.
SET CLASSPATH=c:\java\lib\tools.jar;c:\java\lib\dt.jar
- ':' on unix based systems
e.g.
CLASSPATH=/usr/java/lib/tools.jar:/usr/java/lib/dt.jar
- i am not sure about Mac OS...u can always google..
3. line separator
- \r\n on windows
- \n on unix
- i'm not sure about Mac OS

hth
maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay..
i forgot to mention how System Properties replaces these environment specific values..
1. file path separator
System.getProperty("file.separator")
2. PATH separator
System.getProperty("path.separator");
3. new line character
System.getProperty("line.separator");
write the following code and run on different OS to see the results,
class testSP {
public static void main(String[] s) {
System.out.println(System.getProperty("file.separator"));
System.out.println(System.getProperty("path.separator"));
System.out.println(System.getProperty("line.separator").length());
}
}
regards
maulin
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic