how to know the system configuration using java

Hello Everyone,

I wanna know the system configuration (Hard Disk size,Ram capacity,Processor speed) .Can we know it using Java API? Or else is there any API which makes my life easier?

if we can know the system configuration using the languages like c or c++ ,
can we call that code using java?I am new to java.
Can someone let me know,please?

All ur answers r most welcome.

Thanks

Comments

  • you got a free Windows program, no remember the name, but it works great into Java, exactlly what you want..
    comming soon, when i'l find it

  • : you got a free Windows program, no remember the name, but it works
    : great into Java, exactlly what you want..
    : comming soon, when i'l find it
    :
    :
    Hello,

    Actually,what I need is before installing our application on client's machine
    System configuration(Hard Disk capacity,Ram capacity, Processor speed..etc) needs to be checked using java API.For this I have searched on the web.However,I could not get it.
    Now my query is "Can we know the system configuration using native code(c or c++ code)so that we can call that code from java ?"

    any help would be appreciated.

    Thanks.
  • : : you got a free Windows program, no remember the name, but it works
    : : great into Java, exactlly what you want..
    : : comming soon, when i'l find it
    : :
    : :
    : Hello,
    :
    : Actually,what I need is before installing our application on
    : client's machine
    : System configuration(Hard Disk capacity,Ram capacity, Processor
    : speed..etc) needs to be checked using java API.For this I have
    : searched on the web.However,I could not get it.
    : Now my query is "Can we know the system configuration using native
    : code(c or c++ code)so that we can call that code from java ?"
    :
    : any help would be appreciated.
    :
    : Thanks.
    :

    if you look in the java.lang.Runtime class, there are methods for finding out the memory available to the jvm, but it doesnt show the _whole_ RAM capacity.


    the below code is taken from a program called xchat, its written in c and gets the processor speed for linux, freebsd, apple and windows.
    xchat is released under gpl

    [code]#if defined (USING_LINUX) || defined (USING_FREEBSD) || defined (__APPLE__)

    static void
    get_cpu_info (double *mhz, int *cpus)
    {

    #ifdef USING_LINUX

    char buf[256];
    int fh;

    *mhz = 0;
    *cpus = 0;

    fh = open ("/proc/cpuinfo", O_RDONLY); /* linux 2.2+ only */
    if (fh == -1)
    {
    *cpus = 1;
    return;
    }

    while (1)
    {
    if (waitline (fh, buf, sizeof buf, FALSE) < 0)
    break;
    if (!strncmp (buf, "cycle frequency [Hz] :", 22)) /* alpha */
    {
    *mhz = atoi (buf + 23) / 1000000;
    } else if (!strncmp (buf, "cpu MHz :", 10)) /* i386 */
    {
    *mhz = atof (buf + 11) + 0.5;
    } else if (!strncmp (buf, "clock :", 8)) /* PPC */
    {
    *mhz = atoi (buf + 9);
    } else if (!strncmp (buf, "processor ", 10))
    {
    (*cpus)++;
    }
    }
    close (fh);
    if (!*cpus)
    *cpus = 1;

    #endif
    #ifdef USING_FREEBSD

    int mib[2], ncpu;
    u_long freq;
    size_t len;

    freq = 0;
    *mhz = 0;
    *cpus = 0;

    mib[0] = CTL_HW;
    mib[1] = HW_NCPU;

    len = sizeof(ncpu);
    sysctl(mib, 2, &ncpu, &len, NULL, 0);

    len = sizeof(freq);
    sysctlbyname("machdep.tsc_freq", &freq, &len, NULL, 0);

    *cpus = ncpu;
    *mhz = (freq / 1000000);

    #endif
    #ifdef __APPLE__

    int mib[2], ncpu;
    unsigned long long freq;
    size_t len;

    freq = 0;
    *mhz = 0;
    *cpus = 0;

    mib[0] = CTL_HW;
    mib[1] = HW_NCPU;

    len = sizeof(ncpu);
    sysctl(mib, 2, &ncpu, &len, NULL, 0);

    len = sizeof(freq);
    sysctlbyname("hw.cpufrequency", &freq, &len, NULL, 0);

    *cpus = ncpu;
    *mhz = (freq / 1000000);

    #endif

    }
    #endif

    #ifdef WIN32

    static int
    get_mhz (void)
    {
    HKEY hKey;
    int result, data, dataSize;

    if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Hardware\Description\System\"
    "CentralProcessor\0", 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
    {
    dataSize = sizeof (data);
    result = RegQueryValueEx (hKey, "~MHz", 0, 0, (LPBYTE)&data, &dataSize);
    RegCloseKey (hKey);
    if (result == ERROR_SUCCESS)
    return data;
    }
    return 0; /* fails on Win9x */
    }

    char *
    get_cpu_str (void)
    {
    static char verbuf[64];
    OSVERSIONINFO osvi;
    SYSTEM_INFO si;
    double mhz;

    osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
    GetVersionEx (&osvi);
    GetSystemInfo (&si);

    mhz = get_mhz ();
    if (mhz)
    {
    double cpuspeed = ( mhz > 1000 ) ? mhz / 1000 : mhz;
    const char *cpuspeedstr = ( mhz > 1000 ) ? "GHz" : "MHz";
    sprintf (verbuf, "Windows %ld.%ld [i%d86/%.2f%s]",
    osvi.dwMajorVersion, osvi.dwMinorVersion, si.wProcessorLevel,
    cpuspeed, cpuspeedstr);
    } else
    sprintf (verbuf, "Windows %ld.%ld [i%d86]",
    osvi.dwMajorVersion, osvi.dwMinorVersion, si.wProcessorLevel);

    return verbuf;
    }

    #else

    char *
    get_cpu_str (void)
    {
    #if defined (USING_LINUX) || defined (USING_FREEBSD) || defined (__APPLE__)
    double mhz;
    #endif
    int cpus = 1;
    struct utsname un;
    static char *buf = NULL;

    if (buf)
    return buf;

    buf = malloc (128);

    uname (&un);

    #if defined (USING_LINUX) || defined (USING_FREEBSD) || defined (__APPLE__)
    get_cpu_info (&mhz, &cpus);
    if (mhz)
    {
    double cpuspeed = ( mhz > 1000 ) ? mhz / 1000 : mhz;
    const char *cpuspeedstr = ( mhz > 1000 ) ? "GHz" : "MHz";
    snprintf (buf, 128,
    (cpus == 1) ? "%s %s [%s/%.2f%s]" : "%s %s [%s/%.2f%s/SMP]",
    un.sysname, un.release, un.machine,
    cpuspeed, cpuspeedstr);
    } else
    #endif
    snprintf (buf, 128,
    (cpus == 1) ? "%s %s [%s]" : "%s %s [%s/SMP]",
    un.sysname, un.release, un.machine);

    return buf;
    }

    #endif[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories