Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

System Guts(power information)

Thread view: 
MidiBot@gmail.com - 20 Mar 2006 01:22 GMT
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.
Roedy Green - 20 Mar 2006 02:32 GMT
>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
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas Weidenfeller - 20 Mar 2006 09:12 GMT
>  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

Signature

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/

Jeffrey Schwab - 20 Mar 2006 16:12 GMT
>>  Hello. I want to write a program in which the main functionality will
>> depend on whether or not my
[quoted text clipped - 4 lines]
> 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?
Thomas Weidenfeller - 20 Mar 2006 18:03 GMT
> Why would someone using a Mac PowerBook be better off with a language
> suited for Windows system programming?

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

/Thomas
Signature

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/

Roedy Green - 20 Mar 2006 20:17 GMT
On Mon, 20 Mar 2006 18:03:08 +0100, Thomas Weidenfeller
<nobody@ericsson.invalid> 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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Stefan Ram - 20 Mar 2006 23:49 GMT
>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/
Thomas Weidenfeller - 21 Mar 2006 09:31 GMT
> 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.

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

/Thomas
Signature

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/

Roedy Green - 21 Mar 2006 14:58 GMT
On Tue, 21 Mar 2006 09:31:47 +0100, Thomas Weidenfeller
<nobody@ericsson.invalid> 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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Gordon Beaton - 21 Mar 2006 15:07 GMT
> 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

Signature

[  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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.