java

Synchronization on "reference" or on instance

Consider the following code: public class Foo { private static final Object LOCK = new Object(); private Object _lockRef1 = LOCK; private Object _lockRef2 = LOCK; private int _indx = 0; public void dec() { synchronized(_lockRef1) { _indx--; } } public void inc() { synchronized(_lockRef2) { _indx++...

How to read non-english texts in java? They are represented in wrong encoding.

I use apache HttpClient. And when I'm trying to "read site", all non-english content is represented wrongly. Actually, it's represented in windows-1252 but it should be in UTF-8. How can I fix this? I tried to use InputStreamReader (inputStream, Charset.forName ("UTF-8")), but it didn't help (wrong symbols transformed into ????????). ...

Question from SCJP test

Hi! Question from SCJP test: class A{ A aob; public static void main(String args[]){ A a=new A(); A b=new A(); A c=new A(); a.aob=b; b.aob=a; c.aob=a.aob; A d=new A().aob=new A(); c=b; c.aob=null; System.gc(); ...

How can I programmatically fill out the web form with JAVA?

I just need filling out web form programmatically with java. I use Apache HttpClient 4.0.1. Form looks like this: http://i046.radikal.ru/0912/fd/bcc149cf3b50.png HTML code of it looks like this:(any tags can not be shown ) DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" S...

Can one initialise a java String with a single repeated character to a specific length.

I'd like to create a function that has the following signature: public String createString(int length, char ch) It should return a string of repeating characters of the specified length. For example if length is 5 and ch is 'p' the return value should be ppppp Is there a way to do this without looping until it is the required ...

Error getting SVN repo of Liferay in Eclipse

Hello, Im using Eclipse Galileo and have installed Subclipse. I looked at the svn repo url at http://www.liferay.com/web/brian.chan/blog/-/blogs/changes-to-anonymous-access-to-liferay-s-svn and then tried to get Liferay from their SVN repository in Eclipse, using svn://svn.liferay.com/repos/public --username guest,but i get the followin...

How can I catch moment when someone kill java.exe process?

console java application. Someone kill java.exe process by Task Manager. How can I write to logs some information at this moment before application is terminated? Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { ..... } }); OR Runti...

How to convert Excel to XML using java?

Hi, i want to convert my input Excel file into the Output XML file. If anybody has any solution in java for how to take input Excel file and how to write to XML as output,please give any code or any URL or any other solution. Thanks, Mishal Shah ...

Can JavaSE doing a web application?

I know that J2EE can using JSP + Servlet, can I use JSP & Servlet using J2SE? ...

RichFaces problem with ajax commandButton

Hi i have a problem with <a4j:commandButton> after i press it for some reason all buttons on this page are changing their style any suggestions would be much appretiated i have uploaded a video which shows my problem @ 0:10 sec http://www.screencast.com/users/Schyzotrop/folders/Jing/media/b54aece2-4a97-45dc-99eb-76a7fbe29002 thanks ...

can anybody post tutorial links for jtidy to convert xhtml to xml

can anybody give sample program for converting xhtml doc to xml using jtidy in java. or otherwise post the tutorial link for using jtidy ...

Calling static functions from a thread in java?

Lets say I have a class like this in Java: public class Function { public static int foo(int n) { return n+1; } } What happens if I call the foo method like this from a thread? x = Function.foo(y); Can I do that with two threads, without them waiting for each other? Let's say that foo takes a while, and that it gets...

How to use "javax.lang.model.element.ElementVisitor"?

I experiment with java annotation processors and try to understand the usage of the classes in "javax.lang.model". For what I have read I think the ElementVisitor is to be intended as the primary way to work with the model. But I don't understand how to use it properly. I knew the visitor pattern. Up to now I've used it to avoid iterati...

Convert java to c# .net

Possible Duplicate: Tool to convert java to c# code I have done a project in java and I want to convert it to C#.Net. I'm using Visual Studio 2008. How can I convert the code from Java to C#? Are there any tools available? ...

Convert boolean[] to String and viceversa in java

Howto convert a boolean array (or BitSet) to a string and vice versa. Example: boolean[] ar = {true,false,false,false,false}; print(BitArrayToString(ar)); Should return one of the following 10000 //binary 16 //decimal 10 //hex, prefered The otherway around should work also ar = StringToBitArray(BitArrayToString(ar)); ...

View Menu with submenu

I'm working on an EclipsePluginProject. I don't have much(nearly nothing) experience with UIs under java. I added a View Option Menu and some actions following this post. IMenuManager dropDownMenu = getViewSite().getActionBars().getMenuManager(); dropDownMenu.add(new Action("Action1") { @Override public void run() { //do...

Do pointers in java actually exist?

I thought I'm pretty experienced in java, but it seems that's not really the case, I just noticed something yesterday, something I used before but never really realised what it did. I googled but didn't find the answer to my question. If I declare an int array, and use Array's static sort function to sort my array, I just need to type ...

Java + bitwise operation

Hi All, I have a long variable in java and am converting it to a binary string, like long var = 24; Long.toBinaryString(val); Now this prints only 7 bits, but I need to display all the 64 bits, i.e. all the leading zeros also, how can I achieve this? The reason is I need to iterate through each bit and perform an operation according ...

concurrency in threads and synchronization

Transaction processor is a part of switch which is used for banking job.(shown in picture below) ![alt text][1] which aspects of this part should be considered in designing? I mean concurrency needs.for example for threads. when a new thread should be created for answering a request and when have to be deleted?how can I reduce overhead ...

Process files in Java EE

I have a system that is supposed to take large files containing documents and process these to split up the individual documents and create document objects to be persisted with JPA (or at least it is assumed in this question). The files are in the range of 1 document to 100 000 in each file. The files come in various types Compressed...