java

Unreachable return statement in Java

I was recently quickly writing this little function 5 minutes ago when i got the compiler error unreachable statement private static boolean isTransientField(String name, Class beanClass) { try { Field field = beanClass.getDeclaredField(name); return (field.getModifiers() & Modifier.TRANSIENT) == Modifier...

Java How to find a value in a linked list iteratively and recursively

Hi I have a method that has a reference to a linked list and a int value. So, this method would count and return how often the value happens in the linked list. So, I decided to make a class, public class ListNode{ public ListNode (int v, ListNode n) {value = v; next = n;) public int value; public ListNode next; } Then, the metho...

Java multithreading reading a single large file

What is an efficient way for a Java multithreaded application where many threads have to read the exact same file (> 1GB in size) and expose it as an input stream? I've noticed that if there are many threads (> 32), the system starts to contend over I/O and has a lot of I/O waits. I've considered loading the file into a byte array that...

dealing with duplicates in a bst

My bst has to be able to cope with duplicate entries. Does anyone have any strategies for how to go about this that doesn't require excessive amounts of code? I thought of consistently adding duplicates to the right but then that will mess up the bst order. for example what happens when the duplicate has two children who in turn have two...

Using extended Swing component, threading doubt

I have built my own component extending JPanel. I've added a few methods like calculateWhatever()... Should I call those methods with invokeLater() as well? Substance L&F is not complaining about it but I'm having rare random painting problems and I'm wondering If they're happening because of those calculations inside the extended swing...

can any one please explain how to build rpm for fedora10 linux

I have created an application in java. I have tried to create rpm file for that application. But I did not found what is the error. When I am creating rpm file i received an error No file or directory found. http://javaworkshop.wordpress.com/ can any one please explain how to build rpm for fedora10 linux My application (which is a sim...

Java Scanner Delimiter Usage

I'd like to specify a delimiter for a scanner that splits on some pattern, but doesn't remove that pattern from the tokens. I can't seem to make this work, as anything that is identified by the regex also gets eaten as part of the delimiter. Any suggestions? My specific problem, I have file that looks like: text/numbers mix numbers n...

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

I'm following Scott Davis' tutorials on developing grails apps, but whenever i try to run my app (or indeed his source code) i get "Firefox has detected that the server is redirecting the request for this address in a way that will never complete." Safari gives a similar error message as does Opera. As i've tested the original authors...

Handle callback for ENTER key in GWT-Ext's NumberField

I use GWT-Ext library for building GUI for a webapp. I'd like to process an ENTER key press inside of the NumberField. It should be like this: final NumberField requiredHeight = new NumberField(); requiredHeight.setValue(125); requiredHeight.setAllowBlank(false); requiredHeight.setAllowNegative(false); requiredHeigh...

How to catch a java unchecked/runtime exception (specifically SecurityException)

Hi all, I have java class with a method which gets an image from a website: private Image image; private int height; private int width; private String imageUri; public Image getImage() { if (image == null) { log.info("Fetching image: " + imageUri); try { URL iURL = new URL(imageUri); ImageIcon ii = new ImageIcon(iURL); i...

Execute "MEMBER OF" query against 'ElementCollection' Map fields in JP-QL (JPA 2.0)

Is it possible to run a "MEMBER OF" query against associative arrays? If so, what does the syntax look like? The obvious workaround is a native query but that gets pretty messy what with all the joins and such. I'd like to test for existence of an object within the map's key set, value collection or entry set. Maybe something like th...

Unicode problem in NetBeans 6.7.1

When I type any text on Georgian language. NetBeans shows it like question marks. I'm using Windows7(georgian keyboard). I've also tried in Eclipse, but there is no such problem (everything works fine). Then I've tried to open my Eclipse project folder in NetBeans with some html files and the question marks appeared again. (The html fi...

is there a equivalent of Java's labelled break in C# or a workaround

I am converting some Java code to C# and have found a few labelled "break" statements (e.g.) label1: while (somethingA) { ... while (somethingB) { if (condition) { break label1; } } } Is there an equivalent in C# (current reading suggests not) and if not is there ...

Unchecked Exceptions thrown in a GUI Application

We know that unchecked exceptions are to use in case of violation of the contract of a method. If the application is running in a console, the exception will appear in the console window, along with its stack trace. This is true even for GUI application (say written in Swing) invoked from a console and console is running in the backgroun...

Java servlets and database connection pooling.

Just looking at examples of connection pooling on the web, they all implement connection pooling on a per servlet basis. So each servlet has its own pool of database connections. My question is, why is that preferable to something like a global pool of db connections? Since a global pool is seems more efficient than a per servlet poo...

differences between StringBuilder in Java and C#

I am converting Java code to C#. The StringBuilder class in Java seems to have many more methods than the C# one. I am interested in (say) the Java functionality sb.indexOf(s); sb.charAt(i); sb.deleteCharAt(i); which seems to be missing in C#. I suppose the first two could be modelled by sb.ToString().IndexOf(s); sb.ToString().CharA...

How do I make my Java application identify itself to Oracle on connection?

When my application connects to an Oracle database I want to be able to see by looking at the active sessions in the database that it is connected. Currently it identifies itself as "JDBC Thin Client" because that's the driver that I'm using, but other Java based applications that I have are somehow able to set this value to something mo...

JUnit: @Before only for some test methods?

I have some common set up code that I've factored out to a method marked with @Before. However, it is not necessary for all this code to run for every single test. Is there a way to mark it so the @Before method only runs before certain tests? ...

Java: Global Exception Handler

Hello, Is there a way to make a global exception-handler in Java. I want to use like this: "When an exception is thrown somewhere in the WHOLE program, exit." The handler may not catch exceptions thrown in a try-catch body. Martijn ...

RSSI for Bluetooth

Can any one help me to write code for RSSI in Bluetooth. any tool and techniques used for this to find it easily ...