• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Getting hardware details,processor type through java

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am writing a code to get the hardware details of my computer like Processor Type, Ram, Hard disk type, etc ..


I am not able to get the hardware details , is there any way to get these details without using some extra tools/softwares.
What class/library i am suppose to use to get these values?

Regards,
Vanlal
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I googled "java access processor type" and found a similar topic on
stackoverflow

This topic mentions this SIGAR ..I realize you indicated you do not want anything external. Not sure if you want to avoid a purchased option or just want something that is core J2SE.
 
vanlalhmangaiha khiangte
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I want something that is core java only.. I don't want to use other tools ..
I need to get details like the MotherBoard type, DVD type etc.. hardware details ..
Is there some library/code that is available to do this..

Regards,
Vanlal
 
Saloon Keeper
Posts: 13063
281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No.
 
Saloon Keeper
Posts: 7026
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Resorting to native code via JNI will let you get at almost anything, at the cost of having to deal with native code on any OS/CPU architecture combination you care to support.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

import org.jutils.jhardware.HardwareInfo;
import org.jutils.jhardware.model.ProcessorInfo;

public class Main {



 public static void main(String[] args) throws Exception{
 com.sun.management.OperatingSystemMXBean os = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
 
   /* Total number of processors or cores available to the JVM */
   System.out.println("Available processors (cores): " +
       Runtime.getRuntime().availableProcessors());

   /* Total amount of free memory available to the JVM */
   System.out.println("Free memory (bytes): " +
       Runtime.getRuntime().freeMemory());

   /* This will return Long.MAX_VALUE if there is no preset limit */
   long maxMemory = Runtime.getRuntime().maxMemory();
   /* Maximum amount of memory the JVM will attempt to use */
   System.out.println("Maximum memory (bytes): " +
       (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));

   /* Total memory currently available to the JVM */
   System.out.println("Total memory available to JVM (bytes): " +
       Runtime.getRuntime().totalMemory());

   /* Get a list of all filesystem roots on this system */
   File[] roots = File.listRoots();

   /* For each filesystem root, print some info */
   for (File root : roots) {
     System.out.println("File system root: " + root.getAbsolutePath());
     System.out.println("Total space (bytes): " + root.getTotalSpace());
     System.out.println("Free space (bytes): " + root.getFreeSpace());
     System.out.println("Usable space (bytes): " + root.getUsableSpace());
   }
   
   
 
   long physicalMemorySize = os.getTotalPhysicalMemorySize();
   long freePhysicalMemory = os.getFreePhysicalMemorySize();
   long freeSwapSize = os.getFreeSwapSpaceSize();
   long commitedVirtualMemorySize = os.getCommittedVirtualMemorySize();
   
   System.out.println("physicalMemorySize: " + physicalMemorySize);
   System.out.println("freePhysicalMemory: " +freePhysicalMemory);
   System.out.println("freeSwapSize: " + freeSwapSize);
   System.out.println("commitedVirtualMemorySize: " + commitedVirtualMemorySize);
 
   System.getenv("PROCESSOR_IDENTIFIER");
   System.getenv("PROCESSOR_ARCHITECTURE");
   System.getenv("PROCESSOR_ARCHITEW6432");
   System.getenv("NUMBER_OF_PROCESSORS");
   
//    OperatingSystemMXBean.getSystemLoadAverage();
//    ThreadMXBean.getCurrentThreadCpuTime();
//    ThreadMXBean.getCurrentThreadUserTime();
   
   ProcessorInfo info = HardwareInfo.getProcessorInfo();
   //Get named info
   System.out.println("Cache size: " + info.getCacheSize());        
   System.out.println("Family: " + info.getFamily());
   System.out.println("Speed (Mhz): " + info.getMhz());
   //[...]

   //Get all info from map
   Set<Entry<String, String>> fullInfos = info.getFullInfo().entrySet();
       
   for (final Entry<String, String> fullInfo : fullInfos) {
       System.out.println(fullInfo.getKey() + ": " + fullInfo.getValue());
   }
   
   
   Runtime runtime = Runtime.getRuntime();

   BufferedReader br = new BufferedReader(
       new InputStreamReader(runtime.exec("cat /proc/loadavg").getInputStream()));

   String avgLine = br.readLine();
   System.out.println(avgLine);
   List<String> avgLineList = Arrays.asList(avgLine.split("\\s+"));
   System.out.println(avgLineList);
   System.out.println("Average load 1 minute : " + avgLineList.get(0));
   System.out.println("Average load 5 minutes : " + avgLineList.get(1));
   System.out.println("Average load 15 minutes : " + avgLineList.get(2));
   
   InetAddress ip = InetAddress.getLocalHost();
   NetworkInterface network = NetworkInterface.getByInetAddress(ip);
   
   byte[] mac = network.getHardwareAddress();

   System.out.print("Current MAC address : ");

   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < mac.length; i++) {
       sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));    
   }
   System.out.println(sb.toString());  
   
   
   
   
   
   
   
 }
 }

//Need following jarsavailab;le    in maven
//jHardware-0.8.6.jar
//jPowerShell-1.9.1.jar
//jSensors-2.2.1.jar
//slf4j-api-1.7.30.jar
//WMI4Java-1.4.2.jar
 
Marshal
Posts: 73244
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Maybe after eight years the answer isn't really urgent.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic