1

i have a variable in unix, i want to pass the value of that variable to java code, so that i can use in java. One way is using properties file. Is there any other way around..??

L A Hari
  • 31
  • 1

3 Answers3

1

You System#getenv to either get the entire environment or a single environment variable

Aviram Segal
  • 10,962
  • 3
  • 39
  • 52
  • 1
    While correct, it would be nice if you could link to a more up-to-date reference, Java 1.5 is a little old now ;) – MadProgrammer Nov 29 '12 at 06:28
  • Depends on how backward compatible are you, Changed it to 6 :) – Aviram Segal Nov 29 '12 at 06:29
  • Well, technically, Java 7 is (backwards compatible), but it also allows developers to see if methods have become deprecated or if it is suggest that a better method is now available. It's a nit pick I know, but I've seen down-votes for less :P – MadProgrammer Nov 29 '12 at 06:31
  • ok that's a good reason (the deprecation), although still, when you write code others might run in another JVM, 7 is not a good idea yet. – Aviram Segal Nov 29 '12 at 06:36
1

public static String getenv(String name)

used to The preferred way to extract system-dependent information is the system properties of the java.lang.System.getProperty methods and the corresponding getTypeName methods of the Boolean, Integer, and Long primitive types. For example:

String classPath = System.getProperty("java.class.path",".");

LEARN HERE

A similar Question is asked here , also a good discussion here.

Community
  • 1
  • 1
Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
0

The variables have different Endianness. http://en.wikipedia.org/wiki/Endianness

As far as I can remember the endianness of data in the JVM was represented in Big-Endian and in Unix it was in Little-Endian.

You should convert it using Bytebuffer or just do it manually :P