System Guts(power information)

Discussion in 'Java' started by MidiBot@gmail.com, Mar 20, 2006.

  1. Guest

    Hello. I want to write a program in which the main functionality will
    depend on whether or not my
    computer is connected to a power adapter(this is for laptops). I looked
    in the online-documentation for this and had no luck. I imagine it is
    quite easy and may even be as simple as a boolean variable...?

    All I want to be able to tell is whether or not my computer is being
    externally powered. More specifically
    I want to be able to have my program running, and be alerted if I
    un-plug my power adapter.

    I am using a Mac(powerbook) with java 1.4.2 if that makes any
    difference.

    Thank you very much.
     
    , Mar 20, 2006
    #1
    1. Advertising

  2. Roedy Green Guest

    On 19 Mar 2006 16:22:41 -0800, wrote, quoted or
    indirectly quoted someone who said :

    >All I want to be able to tell is whether or not my computer is being
    >externally powered. More specifically
    >I want to be able to have my program running, and be alerted if I
    >un-plug my power adapter.


    I don't know of any built in methods in Java to find that out. You
    will have to either:

    1. spawn something with exec that will find out for you.

    2. write something in C to find out and write some JNI glue to it.

    see http://mindprod.com/jgloss/jni.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Mar 20, 2006
    #2
    1. Advertising

  3. wrote:
    > Hello. I want to write a program in which the main functionality will
    > depend on whether or not my
    > computer is connected to a power adapter(this is for laptops). I looked
    > in the online-documentation for this and had no luck. I imagine it is
    > quite easy and may even be as simple as a boolean variable...?


    Use another language. One that is suited for Windows system programming.
    Java is not.

    /Thomas


    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
     
    Thomas Weidenfeller, Mar 20, 2006
    #3
  4. Thomas Weidenfeller wrote:
    > wrote:
    >> Hello. I want to write a program in which the main functionality will
    >> depend on whether or not my
    >> computer is connected to a power adapter(this is for laptops). I looked
    >> in the online-documentation for this and had no luck. I imagine it is
    >> quite easy and may even be as simple as a boolean variable...?

    >
    > Use another language. One that is suited for Windows system programming.
    > Java is not.


    Why would someone using a Mac PowerBook be better off with a language
    suited for Windows system programming?
     
    Jeffrey Schwab, Mar 20, 2006
    #4
  5. Thomas Weidenfeller, Mar 20, 2006
    #5
  6. Roedy Green Guest

    On Mon, 20 Mar 2006 18:03:08 +0100, Thomas Weidenfeller
    <> wrote, quoted or indirectly quoted someone
    who said :

    >Did the OP say Mac? Anyhow, the gist of my answer is still valid. Java
    >is not a good language for system programming.


    Given that "System" programming is often 1% tricky platform-dependent
    stuff and 99% busywork, it is not necessarily a nutty idea to do
    system code in Java. It guides you to keep the bulk of your code
    platform-independent. Had you set out to develop in languages that let
    you do system dependent stuff to easily, you would end up with several
    quite different and incompatible programs, all that had to be
    maintained totally independently.

    The Java approach forces you to keep the system dependent parts in
    clearly defined small boxes.

    The main problem with the Java approach of system stuff is the
    overhead of the Java-native barrier. You don't want to be crossing in
    millions of times a second.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Mar 20, 2006
    #6
  7. Stefan Ram Guest

    Roedy Green <> writes:
    >Given that "System" programming is often 1% tricky platform-dependent
    >stuff and 99% busywork, it is not necessarily a nutty idea to do
    >system code in Java.


    There is an operating system written in Java.

    http://www.jnode.org/
     
    Stefan Ram, Mar 20, 2006
    #7
  8. Thomas Weidenfeller, Mar 21, 2006
    #8
  9. Roedy Green Guest

    On Tue, 21 Mar 2006 09:31:47 +0100, Thomas Weidenfeller
    <> wrote, quoted or indirectly quoted someone
    who said :

    >But if you end up spending 100% of your time kicking your language to do
    >the 1% tricky part it is not fun.


    In Java that part you do in C with some JNI glue. Java is well
    designed to make most platform dependent things impossible.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Mar 21, 2006
    #9
  10. On 19 Mar 2006 16:22:41 -0800, wrote:
    > All I want to be able to tell is whether or not my computer is being
    > externally powered. More specifically I want to be able to have my
    > program running, and be alerted if I un-plug my power adapter.


    If MacOSX provides a process file system (or similar) with information
    about ACPI, APM, PMU or whatever it's called on that platform, then
    you may be able to read the information from your Java application
    using a FileReader.

    If it doesn't, there may be an OS-utility that you can run using
    Runtime.exec() to gather the information you need.

    Failing that, you likely need to use JNI, as others have already
    pointed out.

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Mar 21, 2006
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. z. f.
    Replies:
    0
    Views:
    705
    z. f.
    Feb 3, 2005
  2. Aryeh M. Friedman

    changing the guts of an enum value

    Aryeh M. Friedman, May 2, 2005, in forum: Java
    Replies:
    1
    Views:
    341
    Alan Moore
    May 2, 2005
  3. Replies:
    8
    Views:
    380
    Mark Dickinson
    Apr 17, 2008
  4. kj
    Replies:
    2
    Views:
    108
  5. J.D. Baldwin

    Gisle Aas's Illustrated Perl Guts?

    J.D. Baldwin, Apr 11, 2008, in forum: Perl Misc
    Replies:
    5
    Views:
    162
    J.D. Baldwin
    Apr 14, 2008
Loading...

Share This Page