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 4 of 4

Thread: Interacting with OS

  1. #1
    Member
    Join Date
    May 2013
    Posts
    165
    Thanks
    58
    Thanked 1 Time in 1 Post

    Default Interacting with OS

    I would like to know how can I go about interacting with OS so I can get information. For example if I have my program running in the background and I want to have a popup appear when battery level reaches a certain level or at a certain point in time defined by the laptop e.g. based on switchOn time or laptop time. .


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Interacting with OS

    Quote Originally Posted by keepStriving View Post
    I would like to know how can I go about interacting with OS so I can get information. For example if I have my program running in the background and I want to have a popup appear when battery level reaches a certain level or at a certain point in time defined by the laptop e.g. based on switchOn time or laptop time. .
    The standard Java SE framework doesn't have functionalities to get e.g. battery infos, system processes, networking loads, etc...
    You need a third party library. One I know (by name, never used) is the SIGAR API but at this moment I don't know if it handles battery infos.

    If you are on a single specific O.S. and you need to access one or few "native" functions, it could be quite easy using JNA but you need good knowledge/documentation on the native function(s).


    P.S. utility applications like that you have described, generally are not developed in Java but in languages more close to the system, e.g. C/C++, or (on Windows) Delphi or C#.
    This doesn't mean that in Java is impossible ....
    Andrea, www.andbin.net — SCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginners – My new project Java Examples on Google Code

  3. The Following User Says Thank You to andbin For This Useful Post:

    keepStriving (December 13th, 2013)

  4. #3
    Member
    Join Date
    May 2013
    Posts
    165
    Thanks
    58
    Thanked 1 Time in 1 Post

    Default Re: Interacting with OS

    Interesting, I suppose should I want to go that way in my application I should learn C++.

  5. #4
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Interacting with OS

    Quote Originally Posted by keepStriving View Post
    I should learn C++.
    Ok, but remember that Java is a clean, beautiful, secure programming language, with well defined semantics on many things (primitive data types, operators, memory management, threading, synchronization, etc...).

    In C/C++ you don't have a well known (and portable) data type system, you don't have a "guarded" access to array elements (you can go out-of-bounds, causing from nothing, in the best/lucky case, to application crash, in the worst case) and arrays don't have a "length" property. C/C++ don't have, by itself, a garbage collection, you must be very very careful about when/where you release memory.
    In C/C++ you don't have a clean/portable way to define a new thread and there isn't the beautiful synchronized keyword for mutual exclusion.
    I could go on for many other issues.

    In other words, if you are having, say, N troubles learning/programming in Java ...... in C/C++ you will have at least 40ŚN troubles!
    Andrea, www.andbin.net — SCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginners – My new project Java Examples on Google Code

  6. The Following 3 Users Say Thank You to andbin For This Useful Post:

    GregBrannon (December 14th, 2013), keepStriving (December 14th, 2013), Norm (December 14th, 2013)

Similar Threads

  1. Replies: 1
    Last Post: December 4th, 2013, 11:47 PM
  2. Interacting with NetHack
    By caphect in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: July 13th, 2012, 03:11 AM