java

What does Statement.setFetchSize(nSize) method really do?

hi. i have this really big table with some millions of records every day and in the end of every day i am extracting all the records of the previous day. i am doing this like String SQL = "select col1, col2, coln from mytable where timecol = yesterday"; Statement.executeQuery(SQL); but the problem is that this program takes like...

javax annotations problem

I freaking loosing my mind on this: I have this code: @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "ANetApiResponseType", propOrder = { "resultCode", "messages"}) and I get this error: Type mismatch: cannot convert from XmlAccessType to AccessType I've googled , but all these problems usually occur because some...

Time Complexity O() of isPalindrome()

I have this method isPalindrome() and am trying to find the time complexity of it, and also rewrite the code more efficiently. boolean isPalindrome(String s) { boolean bP = true; for(int i=0; i<s.length(); i++) { if(s.charAt(i) != s.charAt(s.length()-i-1)) { bP = false; } } return bP; } Now I know this code...

Searching through Collections in Java

I have a java properties file containing a key/value pair of country names and codes. I will load the contents of this file into a Collection like List or HashMap. Then, I want users to be able to search for a country, e.g if they type 'Aus' in a textbox and click submit, then I want to search through the collection I have, containing a...

Ruby alternative for Lucene

Hi, I have heard about Lucene a lot, that it's one of the best search engine library in JAVA, is there any similar(as powerful) library for Ruby. ...

JavaFX or Swing?

Hello, i just wanted your input on something with regards to java. Would it be good to use javafx for my user interface, or would sticking to swing be easier or more convenient? I'm still a student by the way, so i'm not really thinking in terms of the enterprise yet. ...

Problem with Java Applet

Hi, I'm new to Java Applets. I have a problem while reloading the applet. When I resize the applet window or open some other application and then come back to the applet, the contents on the screen is redrawn. Basically my paint method is getting called. I want the contents of the paint method to be called only once. How can I accomplis...

Why is each public class in a separate file?

I recently started learning Java and found it very strange that every Java class must be declared in a separate file. I am a C# programmer and C# doesn't enforce any such restriction. Why does Java do this? Were there any design consideration? Edit (based on few answers): Why is Java not removing this restriction now in the age of ID...

VerticalSplitPanel doesn't show widgets in GWT

This is some very simple code that I'm using to try showing a VerticalSplitPanel, but the widgets I add don't show. The divider thing of VerticalSplitPanels does show however the widgets I add don't. Code: public class MyView extends Composite { private VerticalSplitPanel mainPanel=new VerticalSplitPanel(); public CountryFilte...

In a Java regex with Quantifiers how can I obtain the matched groups?

I am processing text using Java Regexes (1.6) which contain quantifiers and I wish to return the number and values of matched groups. A simple example is: A BC DEF 1 23 456 7 XY Z which is matched by: ([A-Z]+){0,9} (\d+){0,9} ([A-Z]+){0,9} How can I find the number of each capture (here 3 4 2) and the values ("A", "BC", "DEF", "1",...

Impressive examples in Java?

I'm going to teach a Java course, and I want to show some interesting and impressive examples of simple Java programs at the first lecture to awaken student interest. Except for the default examples which come with the JDK, what can you advise? What possibilities of Java were you impressed by? One more thing - students admittedly kno...

Right way to use twitter4j in appengine

I am practicing making a web app which tries to read the user's twitter profile, display his/her friends and show his/her picture. The code example at the Twitter4j website goes: public static void main(String args[]) thrwos Exception{ Twitter twitter = new Twitter(); twitter.setOAuthConsumer("[consumer key]", "[consumer secret]"...

PHP vs. Java are there energy consumption differences?

I heard a rumor, that Java consumes less energy than PHP and was wondering if and how this would be true. I'm currently working in a company where we base most of our apps on PHP. Power consumption has never been the problem for us, but we are working on bigger projects where it might matter. We love PHP for web developing and are wonder...

Migration solution for singletons in an OSGI environment

I'm working in a JEE Environment in which each application is in a war file of its own. In the WEB-INF/lib of each application war file there is a common jar that is shared by all applications. This common jar contains several Singletons which are accessed from many points in the code. Because of the war-file boundaries each application ...

How to iterate over a TreeMap?

I want to iterate over a treeMap, and for all 'key's which have a particular value, I want them to be added to a new TreeMap. How can i do this? Code samples would be prefered. ...

Reading Text from Another Application's Frame

I plan on creating a toy application to play games. Is it possible to capture game data from another applications frame? I know this is traditionally done using a low level language and using dll injection but i was wondering if this is possible to do from a high level language? ...

integer value of a string

What function is to be used in java so as to print the integer value of a string. Please explain, maybe with the help of an example. Example String: String str = new String("HELLO"); ...

which .jar file has javax.xml.stream.* ?

Going nuts again with my Mac running Java 1.5.... where do I get a .jar file that has javax.xml.stream.XMLInputFactory ? I want to use StAX but don't know how to get it set up right. :::scream::: I can't seem to get this setup. I've now downloaded jaxp-api.jar, jsr173_1.0_api.jar, sjsxp.jar, stax-api-1.0.1.jar, stax2-api-3.0.1.jar, an...

using Runtime.exec() in Java

What do you have to do in Java to get the Runtime.exec() to run a program that is on the path? I'm trying to run gpsbabel which I have put into the path (/usr/local/bin). public class GpxLib { public static void main(String[] args) { try { Runtime r = Runtime.getRuntime(); Process p = r.exec("gpsbabel -i garmi...

How to debug JavaFX

Hi all, I've just started working with javafx, it seems cool and NetBeans seems much more fun than Eclipse but I find it impossible to debug my application. I've added breakpoints, and I pressed the debug button, I see the debugger is registered to some port but it doesn't cause the application to start. When I run the application and ...