java

getResourceAsStream works differently on Mac OSX vs. Windows 7?

Hi all, I have a set of unit test cases that depend on a test.properties file. When I run the tests under Mac OSX or Linux using Maven ('mvn test'), they work fine. But when running under Windows 7, they can't find the file unless I copy it directly to the class folder. The code to return the properties is the following two methods: ...

what is binary save and load???

what is it and when we use it?I have to do it for my homework(creating a Bank System) but I don't know for which part of that? ...

how can I save an object in the file???

e.g I have an Object obj,how can I save all its information such as m.getName();m.getFamily() and the others in the file??? ...

How to pass object from main thread to another thread in java

In my main application class I have an object of JTextArea(say txtArea). I have created two another threads in main_application program. The two threads I have created is for reading and writing in serial port. Now I want to put the serial port read buffer data into an JTextArea object. So I need to pass the JTextArea object created in m...

cancel a read from an InputStream

Currently I am using an ObjecInputStream to read from a Socket, and everything works fine using this simple code: ObjectInputStream input = new ObjectInputStream(socket.getInputStream()); Object response = input.readObject(); Now I want to somehow cancel the read, without closing the stream, so that I can later read from it again. Is ...

How to run java application bundled to .app on Mac OS X in 32 bit mode?

I have written a java application on win vista, it uses Bonjour and works fine. When I run it on Mac OS X 10.5.8 with all updates installed as a .jar file it runs perfectly too. But when I create a bundle using Jar Bundler it fails with "Uncaught exception in main method: java.lang.UnsatisfiedLinkError: /usr/lib/java/libjdns_sd.jnilib: ...

How to run a .jar file from inside another java program?

i have a .jar file, which I can run on the command line: java -jar myFile.jar argument1 I want to save the output of this .jar as a String variable inside another java program. How can I do it? I tried including myFile.jar as a reference in my program, and doing myFile.main(new String{"argument1"}) in my program. But this just print...

What is the preferred method for uploading to a server from Android?

I've been trying to find a way to upload a video from an Android device to an API, but I haven't found a good way to do it. It seems most of the information I've found online is fairly out of date (a lot of it being from last year). Most of them are using a method like this: http://getablogger.blogspot.com/2008/01/android-how-to-post-f...

Generics in Java

I'm new to this community so I just wanted to start off by saying Hi. On to my question: I came across something peculiar today, take a look at this code snippet List <Rectangle> test1 = new LinkedList<Rectangle>(); List <Shape> test2 = test1; //Compiler Error; This is of course assuming that class Rectangle is a subclass of Shape. C...

why it shows NullPointerException?

I have an object which is Student student; which has some fields like name,family,... I want to make a user name for this student and by clicking on the one button ,I want to show the student's user name on the console but it will show these sentences on the console(I have copied and pasted just a part of that)-----> java.lang.NullPoint...

Alternative to resource bundle properties file

Are there any other better mechanism than resource bundle properties file to localize the application? ...

Java parseFloat seems to be acting inconsistently

I am sure this has more to do with my understanding of the behaviour than any inconsistent action on the part of parseFloat, but bear with me... if I have input in the format "IDCODE: (3.5)" where IDCODE may be a few different predefined strings, and there is guaranteed to always be brackets, and there is also guaranteed to be a number ...

java - appending excel values

right now whenever i call this function the value in B3 cell of excel file workbook.xls is updated. i need to change this function such that whenever i call this function , new excel file should not be created but cell values should be appended in the order A1 on first call , A2 on 2nd call, A3 on 3rd call and so on . Can you help me wit...

XML parsing problems

i need to parse this such that i can get the attribute of MMV and all the attributes of all CS tags <MMV val="Configdes000110010101"> <CS protocol="SNMP" CommandString="wmanIfBsDcdInterval" oid="1.3.6.1.2.1.10.184.1.1.2.2.1.1" Get_SecurityString="public" Set_SecurityString="public" type="INTEGER" > </CS> <CS protoc...

How to parse the XML file of the given format??

hi everyone.. I'll be happy if I can have a sample code to parse the XML of the following format using DOM/SAX parser.. <MMV>Sysdecs000110010101</MMV> <Protocol name="SNMP"> <CS CommandString="wmanIf2BsOfdmaTTG" oid="1.3.6.1.2.1.10.184.1.1.6.2.2.1.3.1" Get_SecurityString="public" Set_SecurityString="private" type="integer"></CS> ...

Creating object to get expected Json

Hi. I am working in GWT. Currently my requirement is simple. I want a JSON in following format: {":question" : { ":id":"123", ":question_text":"some text", ":nodes":["123","111"]}} I need to create an object in GWT code such that when I use jquery's json plugin to parse that object; I should get above listed json. This json needs to ...

JAVA: check a string if there is a special character in it

How do you check a string if there is a special character like: [,],{,},{,),*,|,:,>,etc.? ...

java.lang.ClassNotFoundException when running java -jar (still unsolved)

I'm using ant to build my build.xml file, it compiles ok, but then getting a runtime java.lang.NoClassDefFoundError when running the resulting jar via "java -jar my_jar.jar". It seems like this comes up a lot but none of the related questions' solutions worked for me. My classpath for javac contains only "/usr/local/lib/libthrift.jar" a...

Java Generics comparison

How do you go about comparing two generic classes? class Entry<K,V> { protected K key; protected V value; public K getKey() { return key; } public V getValue() { return value; } public static Comparator KeyComparator = new Comparator() { public int compare(Object o1, Object o2) { int key1 = ( (Entry) o1 ).getKey(); int...

How java priority Queue is suppose to work?

Short story, I'm implementing a graph and now I'm working on the Kruskal, I need a priority queue. My definition of a priority queue is that the element with the smallest key would come first? Is this wrong? Because when I insert the weighted edges(or numbers) in the queue they don't end up sorted. PriorityQueue<Integer> tja = new Prio...