|
1. Write a wrapper for the C code, in C, to create an executable.
2. Add a communications layer to that executable: sockets, stdio or files.
3. Test the above.
4. Write code in jave to run the executable via Runtime.exec() or ProcessBuilder.
5. Implement the communications defined in 2 in java.
Note in the above that steps 1-3 have nothing to do with Java.
The advantage to this method over JNI is that bugs in 1/2 above will not cause your java app to blow up. And it is easier to debug.
|
|
|
|
|
How to access, delete, add element in arrayList??
I have a list of oficials of an Enterprise, I want to print the official member with category equal Developer.
Help me to solve this issue using the code below. Please
*/
package Enterprise;
public class oficial {
private String name;
private String category;
private double salary;
public AuxAdmin(String name, String category, double salary) {
this.name = name;
this.category = category;
this.salary = salary;
}
public String getCategory() {
return category;
}
public String getName() {
return name;
}
public double getSalarY() {
return salary;
}
public void setCategory(String category) {
this.category = category;
}
public void setName(String name) {
this.name = name;
}
public void setSalary(double salary) {
if (salary > 4000) {
this.salary = salary; }
else{
System.out.println("error");
} }
@Override
public String toString() {
return "Oficial Member: " + name + " - " + category+" - " +salary;
}
}
public class Enterprise {
public static void main(String[] args) {
ArrayList<oficial> member = new ArrayList<oficial>();
member.add(new oficial("Bill Gate","Manage", 75 000));
member.add(new oficial("Obama ","Developer", 40 020));
member.add(new oficial("Delfim Pereira","Director", 60 000));
member.add(new oficial("Dannis Rico","Secretary", 20 020));
member.add(new oficial("Diana Math","Developer", 62 000));
member.add(new oficial("Sondela Midell","Developer", 47 020));
for (oficial lis : member)
{
System.out.println(lis);
}
}
|
|
|
|
|
Where is the problem?
for (oficial lis : member) {
System.out.println(lis);
}
You already figured that it would need a loop to access all the objects in your ArrayList.
That's fine! You also have a toString() in there - even better!
And you can add(Object) things to the List - now try to remove(Object) something. Easy.
Sidenotes:
Your Object oficial starts with a small letter - that is no good, it should start with a capital letter.
The "constructor" is not really one as it is called different -> AuxAdmin(args) . It should be the same as the object.
Also are the numbers containing a space.
|
|
|
|
|
Thank u 4 ur answer, it was very important 4 me.
I also solved my issue in single line:
if(lis.getCategory().contains("Developer"))
Thanks
|
|
|
|
|
java
modified 26-Feb-12 12:53pm.
|
|
|
|
|
This is really not a valid question, try searching with Google for such solutions.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I need to compute the timing statistics. Please look at the picture for a full details of what the program should do. If you see any bugs in the program or any improvements i can make please let me know of those too.
modified 27-Feb-12 10:33am.
|
|
|
|
|
smells like homework and does not contain a question!?
|
|
|
|
|
I want compress a string with Java(in Android) and decompress with c#...
I did test many algorithm.. but i cant solved my problem.
What can i do?
|
|
|
|
|
Hossein Khalaj wrote: I did test many algorithm..
If you wrote code to compress/decompress then the way to solve your problem is to correctly implement that code in both languages.
If you are using a library, and not writing your own code, then one of the following is true.
1. You are using different algorithms.
2. You did something wrong in one or both languages is how you used the libraries.
3. There is a very small chance that a library is doing something wrong. If so then it should be possible to demonstrate this using a very small example (one in each language.)
|
|
|
|
|
Hey guys,
I'd like to set the Ringer and Media volume to high automatically when detecting a magnet (I have an Xperia ARC), i could not find such an App that could do that.
Does anyone know how to make this ? is it possible ?
I know about Tasker, but it currently doesn't support the magnetic sensor
Any help is appreciated.
Thank!
|
|
|
|
|
...so there is actually a "magnetic sensor" ?
Just by interest: why would I like to have the phone get loud when "magnetic enlightened"?
|
|
|
|
|
I want code for connect Google earth with JSP code
and JSP code for make web application delivery online
|
|
|
|
|
how much $$ is in your buget? We might need it all.
|
|
|
|
|
|
Hi all,
Near one or two years (version Java at that time is 1.5x), I have a short code to compare 2 Strings in java like bellow:
String a = "abc";
String b ="abc";//this is load from the database.
CODE 1
if(a==b){
System.out.println("equal");
}else {
System.out.println("dif");
}
and I got the result is dif
I remember because after I change the code to
String a = "abc";
String b ="abc";//this is load from the database.
CODE 2
if(a.equals(b)){
System.out.println("equal");
}else {
System.out.println("dif");
}
It give me the result is equal
Is it true or my eyes is wrong?
Now the CODE 1 always gives the result is equal
modified 17-Feb-12 21:33pm.
|
|
|
|
|
This is as expected, in Java there is no operator overloading and == always does a reference equality check. To do a value equality check, you need to use .equals (after doing a null check).
|
|
|
|
|
Code1 compares the objects and if they are equal, also both Objects have the same value they are still different objects.
Code2 checks character wise for the value.
It's a common failure.[^].
|
|
|
|
|
sharkbc wrote: Now the CODE 1 always gives the result is equal
Is it true or my eyes is wrong?
Java, regardless of version, has always operated in that way (equals is required.)
So something is wrong in how you are validating this.
Perhaps because despite what your comment says you are not in fact loading it from the database. (An very odd corner case would involve how you are 'loading' it from the database and would indicate an error in the load process.)
|
|
|
|
|
hi Jschell,
I've just modify my question, it must be
...
Is it true or my eyes is wrong?
Now the CODE 1 always gives the result is equal
Im sure at that time, the database is not change and i do not change any other code in the programe, because after we got the mistake, we debug the code and get it.
We just only change
if(a==b) to
if(a.equals(b))
|
|
|
|
|
|
The real problem is that we do not know what you are actually doing.
Again the following has always been true regardless of java version for the major java vendors...
Equality compares references
The method equals() compares value (content of string.)
As I said there are ways which MIGHT present seemingly different results dependent on the specifics of what is going on. But you haven't presented the specifics.
And based ONLY on the code you posted you are comparing references for what you refer to "CODE 1". And reference equality will be equal.
So what are some possible causes for some other difference for some OTHER code?
1. You were not using a real version of java, it was some odd variant.
2. There was something odd about the way in which your database code worked.
3. There was something odd about your data
4. You misinterpreted what was happening before.
5. The real code would make it explicitly obvious why a difference was occurring.
6. The method intern() was being called somewhere (incorrectly called.)
|
|
|
|
|
Where is a initialised from? It is possible that the two objects are the same and then == will return true.
For future reference, if you want to compare two objects always use the equals() method.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
sir i need to compress a video file dont know how to compress a video file in java. thanks in advace....
|
|
|
|
|
Firstly, remove your duplicate question above.
Secondly, a quick search[^] will get more information then a generic question here.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|