In C, I’m working on a “class” that manages a byte buffer, allowing arbitrary data to be appended to the end. I’m now looking into automatic resizing as the underlying array fills up using calls to realloc. This should make sense to anyone who’s ever used Java or C# StringBuilder…
Tag: java
Network is unreachable?
I want to run a cyc (opencyc) Java class, but when I run this class I got an error mentioning that the network is unreachable. I am working on NetBeans 7.0 and opencyc 2.0 win 32 version. I am using localhost (127.0.0.1) to test. The error is below. Why is this happening? How can I connect to the cyc? Answer
How to use replaceValues method of Guava Multimap?
I want to add, remove and replace values in a MultiMap provided by Guava. I do this currently to add values.. Removing values is easier with Guava library. But how can I use the replaceValues method? I mean this Say I wanted to replace value 4.3 with a new value 5.99, how should I do that, the method expects …
Rounding with DecimalFormat in Java
Let’s look at the following statements in Java. In the above statements, all other cases are obvious except the following. It should return 3 but it returns 2. How? Answer This is intentional behavior. From the documentation: Rounding DecimalFormat uses half-even rounding (see ROUND_HALF_EVEN) for forma…
Date formatting according to country habbits
We create J2SE application that has to format the date and time according to custom the country from which users come from. I want to ask how to solve this thing in Java? Probably I’ll use SimpleDateFormat, but I wonder if it is possible to get format string in somehow simpler way than to have all forma…
Bizarre yet predictable triple and interleaved call to servlet when using GWT devmode
I am using Google Web Toolkit and Java Google App Engine to write an app. I have found a situation where the following happens very predictably. I have a servlet the app.yaml entry for which looks like this: This servlet checks that the user is logged in (redundant, I know), looks for the user in the database…
How to pass arguments to .jsp file when using javax.servlet.RequestDispatcher.include()?
I’m using the Model/View/Controller style of building web apps by routing an incoming HttpRequest to a Controller Servlet written in Java and then when the Servlet is finished, having it render back a View using a .jsp file. (This is very much the Rails style.) Doing this requires a line like this at th…
Javafx 2.0 How-to Application.getParameters() in a Controller.java file
Considering the following sample. How to access to arguments/parameters of the application in the controller? Thank you. NB: I’ve tried to mix App.java and MyController.java in only one Class file, but didn’t help. App.java (simplified): MyController.java (simplified): MyView.fxml (simplified): An…
How to create a .jar file using the terminal
I’m trying to create a .jar file using the mac terminal but am having bit of trouble. I followed the steps here but was unsuccessful. I got this error message: So how exactly do you go about doing it? My java program is called Main.java and I have compiled it into a .class file. Now what do I do? Thanks
for-loop very slow on Android device
I just ran into an issue while trying to write an bitmap-manipulating algo for an android device. I have a 1680×128 pixel Bitmap and need to apply a filter on it. But this very simple code-piece actually took almost 15-20 seconds to run on my Android device (xperia ray with a 1Ghz processor). So I tried …