|
Punit Jain wrote:java has automatic garbage collecting and prevents individuals from handling/manipulating memory freely
This has nothing to do with the OP's question.
Punit Jain wrote:For performance reasons, it is unrecommended to use Java in place of C/C++ when it comes to doing low-level systematic commands.
Punit Jain wrote:doing system programming in java is difficult
and effects the performance,
therefore it's better to use native support in java.
Punit Jain wrote:
This has nothing to do with the OP's question.
sorry for misinterpret jeff.
but what i was trying to say is, java is limited up to the jvm, so doing system programming in java is difficult and effects the performance, therefore it's better to use native support in java.
what you mean by "system programming"
Punit Jain wrote:
i mean by something like this:
By performance i mean that "calling native methods are faster".
Jeff Verdegan wrote:
Punit Jain wrote:
i mean by something like this:
By performance i mean that "calling native methods are faster".
Ah, I see.
Yes, it's true that in general it will be faster to call a native method to perform some task, rather than invoking an external process to perform the same task. However, this is also true in C/C++. It's not Java specific at all, and I don't see what it has to do with this thread.
Punit Jain wrote:Haven't done this before but i think linux has a command acpi
which gives output like this:
Battery 1: discharging, 44%, 00:18:48 remaining
and i think we can run linux commands as well in java in the same manner.
not sure about windows, but it has powercfg but don't know does it has any parameter to display above output.
Henry Wong wrote:
Punit Jain wrote:Haven't done this before but i think linux has a command acpi
which gives output like this:
Battery 1: discharging, 44%, 00:18:48 remaining
and i think we can run linux commands as well in java in the same manner.
not sure about windows, but it has powercfg but don't know does it has any parameter to display above output.
With Windows, you can use the following command-line command:
c:\Users\xxxxx> typeperf "\Battery Status(*)\Remaining Capacity"
Henry
Do not wait to strike till the iron is hot; but make it hot by striking....
Punit Jain wrote:thank you henry
but it's showing error:
Error: No Valid Counters.
Henry Wong wrote:
Punit Jain wrote:thank you henry
but it's showing error:
Error: No Valid Counters.
That means that the counter is not available -- one possible reason is that you don't have a battery in the machine....
FYI.... you can also use the "-qx" flag to list all the available counters.
Henry
Punit Jain wrote:-qx showing me a huge list of counter and there is not any counter named "\Battery Status(*)\Remaining Capacity"
this is the counter, right??
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Punit Jain wrote:in java "system programming" i mean running dos commands and all, i have only executed dos commands in java, haven't done system programming myself.
Rob Spoor wrote:I've actually done this myself in Windows. All you need is JNI with one system call - GetSystemPowerStatus.
Ashish S Yadav wrote:Can you suggest some sample java code which will invoke the windows commands ? Can i also see if the laptop is connected to AC power or not ?
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:The Java code is the easy part here. For instance:
The actual code is written in C or C++. That's why I quoted that Windows system call. You write C or C++ code to call that after you include <windows.h>.
As for your second question, the SYSTEM_POWER_STATUS struct that is filled by the GetSystemPowerStatus call includes field ACLineStatus, which will be 0 if the adapter is not connected, 1 if it is, or 255 if it can't be determined. On my desktop machine it returns 1. You can use the BatteryFlag to determine if you actually have an adapter - 128 means it isn't. That's what I get.
Ashish S Yadav wrote:I am new to this concept and jni. Is it possible to get some existing C++ program which does the battery checking, then "wrap" java around it and make java get all the info that the C++ code pulls out ?
Pat Farrell wrote:
Ashish S Yadav wrote:I am new to this concept and jni. Is it possible to get some existing C++ program which does the battery checking, then "wrap" java around it and make java get all the info that the C++ code pulls out ?
As folks have answered up thread, yes. You need to do some research on JNI. Here at the ranch, you are expected to show some effort.
On top of spaghetti all covered in cheese, there was this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|