Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: getting system info (cpu, memory, disks etc)

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Location
    Durban
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default getting system info (cpu, memory, disks etc)

    /**Hello Norm thanks for your reply this code goes and gets the system info like cpu, memory and disks etc
    *i am having trouble compiling the following code as the error reads, "Could not find or load main class", i know i am *supposed to have a main class in the code but where in my code can i define this main class i am using netbeans and *command prompt to compile the code but comes up with the error above and yes i also think its mentioning a main method *as well, but the above error is what i am coming up with
    */

    [Code = java]
    import java.io.File;
    import java.io.IOException;
    import java.text.NumberFormat;

    public class GetInfo {

    private Runtime runtime = Runtime.getRuntime();

    public String OSname() {
    String OSname = this.OSname();
    return OSname.toString();
    }

    public String MemInfo () {
    String MemInfo = this.MemInfo();
    return MemInfo.toString();
    }

    public String DiskInfo () {
    String DiskInfo = this.DiskInfo();
    return DiskInfo.toString();
    }

    public String OSversion() {
    return System.getProperty("os.version");
    }

    public String OsArch() {
    return System.getProperty("os.arch");
    }

    public long totalMem() {
    return Runtime.getRuntime().totalMemory();
    }

    public long usedMem() {
    return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
    }

    public void Memo() {
    NumberFormat format = NumberFormat.getInstance();
    long maxMemory = runtime.maxMemory();
    long allocatedMemory = runtime.totalMemory();
    long freeMemory = runtime.freeMemory();

    System.out.println("Free Memory: " + format.format(freeMemory / 1024));
    System.out.println("Allocated memory: " + format.format(allocatedMemory / 1024));
    System.out.println("Max Memory: " + format.format(maxMemory / 1024));
    System.out.println("Total free Memory: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024));

    }

    public void Os() {

    System.out.println("OS name" + this.OSname());
    System.out.println("OS version" + this.OSversion());
    System.out.println("OS arch" + this.OsArch());
    System.out.println("Available processors: " + runtime.availableProcessors());

    }

    public void DiskInf() {
    /* 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 root path: " + 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());

    }

    }
    }
    [/code]
    Last edited by Msyhles; November 19th, 2013 at 08:11 AM. Reason: formatting


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: getting system info (cpu, memory, disks etc)

    error reads, "Could not find or load main class"
    What program is giving that message? How are you executing the program?
    I'm not sure what a "main class" is?

    The java program requires a main() method in the class it is starting execution with.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 0
    Last Post: April 3rd, 2013, 09:17 PM
  2. [SOLVED] Towers of Hanoi Algorithm Error once i get to 3 disks??
    By courtenay in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 11th, 2011, 12:06 AM
  3. How to get a System's total CPU usage percentage using a java program
    By userj2ee in forum Java Theory & Questions
    Replies: 2
    Last Post: January 7th, 2011, 01:28 AM
  4. SIGAR to find CPU info-problem
    By ttsdinesh in forum Exceptions
    Replies: 7
    Last Post: October 4th, 2009, 10:33 AM
  5. recursive search of all local disks
    By ttsdinesh in forum Java Theory & Questions
    Replies: 4
    Last Post: September 27th, 2009, 08:23 AM