Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > System Guts(power information)

Reply
Thread Tools

System Guts(power information)

 
 
MidiBot@gmail.com
Guest
Posts: n/a
 
      03-20-2006

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.

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      03-20-2006
On 19 Mar 2006 16:22:41 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) 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.
 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      03-20-2006
(E-Mail Removed) 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/...g/java/gui/faq
http://www.uni-giessen.de/faq/archiv....java.gui.faq/
 
Reply With Quote
 
Jeffrey Schwab
Guest
Posts: n/a
 
      03-20-2006
Thomas Weidenfeller wrote:
> (E-Mail Removed) 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?
 
Reply With Quote
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      03-20-2006
Jeffrey Schwab wrote:
> 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
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
http://www.uni-giessen.de/faq/archiv....java.gui.faq/
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      03-20-2006
On Mon, 20 Mar 2006 18:03:08 +0100, Thomas Weidenfeller
<(E-Mail Removed)> 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.
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      03-20-2006
Roedy Green <(E-Mail Removed) > 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/

 
Reply With Quote
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      03-21-2006
Roedy Green wrote:
> 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
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
http://www.uni-giessen.de/faq/archiv....java.gui.faq/
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      03-21-2006
On Tue, 21 Mar 2006 09:31:47 +0100, Thomas Weidenfeller
<(E-Mail Removed)> 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.
 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      03-21-2006
On 19 Mar 2006 16:22:41 -0800, (E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
System.Security.SecurityException: Error de solicitud de permiso de tipo System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. Luis Esteban Valencia ASP .Net 0 07-14-2005 01:43 PM
Streaming with System.IO and System.Net Charles A. Lackman ASP .Net 4 01-15-2005 08:00 PM
System error 203 The System could not find environment option sfunds sfunds ASP .Net 9 05-06-2004 09:46 AM
The type System.Web.UI.WebControls.TextBox in Assembly System.Web...error Matt ASP .Net 2 07-24-2003 06:17 PM
Method not found: System.Collections.Specialized.NameValueCollection System.Web.HttpRequest.get_QueryString(). Mark Miller ASP .Net 1 07-18-2003 08:48 PM



Advertisments