java

Find names of all classes that a Java program loads using reflection

To support a static-analysis tool I want to instrument or monitor a Java program in such a way that I can determine for every reflective call (like Method.invoke(..)): 1.) which class C this method is invoked on, and 2.) which classloader loaded this class C. Ideally I am looking for a solution that does not require me to statically m...

How to create a horizontal scrollbar which will scrolls automatically after some time interval

Hi I want horizontal scrollbar which will scroll from left to right automatically after each 1 second. Thanks Sunil Kumar Sahoo ...

How can you test if a thread is the only remaining thread in Java?

I want a thread in a Java program to loop until all other threads die, and then end the loop. How can I know when my loop thread is the only thread remaining? In my situation, the loop thread will have no reference to any other threads, so I don't think isAlive() helps me. ...

using another object's functionality following a proper OO design - encapsulation

Hello, I am debating the proper, OO-design to use another object's functionality (methods) from a java class, while both objects remain decoupled as much as possible. For example, at some point in my class, to implement my logic, I need to call a method that belongs to another object, say a helper class. This helper class does not need...

Volatile semantic with respect to other fields

Suppose I have following code private volatile Service service; public void setService(Service service) { this.service = service; } public void doWork() { service.doWork(); } Modified field marked as volatile and it's value do not depend on it's previous value. So this is correct multithreaded code (don't bother about Service im...

Unmarshalling XML files into Java objects in Android?

I'm making use of an API on the internet that is marshalling objects to XML files. Given that the XSD files are also available I'd like to be able to unmarshall them back in to Java objects once I've downloaded the files. After looking around it looks like JAXB is the default library for doing this in Java, but as I'm developing a mobil...

Thread-Safe setting of a variable (Java)?

Hello, given the following code: public class FooBar { public static volatile ConcurrentHashMap myConfigData = new ConcurrentHashMap(); } public class UpdaterThread implements Runnable { run { //Query the Data from the DB and Update the FooBar config Data FooBar.myConfigData = ConfigDataDAO.getLatestConfigFromDB(); } } ...

Can I intercept and change the request url of a HTTPServletRequest within a Java Servlet filter?

Hi there. I have a Java web application which manages data for many clubs. I would like the application to show club information depending on the URL that is typed in. Eg. If you enter "localhost:8080/MyApp/Club1" ...then the app should strip out the end of the requst url (Club1), do a lookup in the database for the club, and add this t...

Setting SWT tooltip delays

Is it possible to change the tooltip delay in SWT? In Swing, I would normally use the methods in Tooltip.sharedInstance(). This seems to break in SWT. ...

Netbeans: Creating custom build target to let sources be packaged to JAR...?

Hello! I ask the question more specific: Using Netbeans, is there a possibility to create an additional custom build target, which would: either package all project sources along with the binaries into a singe JAR, or package all project sources without the binaries into an additional JAR? Notes: It's not an option for me to mod...

what is difference between unbounded wildcard type List and raw type List?

can please help in understand difference between unbounded wildcard type List and raw type List List a; List<?>; along with this can anybody help me to understand BOUNDED TYPE PARAMETER LIST List<E extends Number>; ...

How do I make a generic List which can accept two different, unrelated types?

I have to define a List and it has two types of possible values 1)String 2)some user defined Class How can I make a List that is type safe in that it only accepts these two types? I want to avoid the use of raw List. ...

Main class block in '{}' never executes

Consider the following code:- class Name { {System.out.println("hi");} public static void main(String[] args) { System.out.println(waffle()); } static boolean waffle() { try { return true; } finally { return false; } } } This never outputs "hi" . Why is thi...

Can I use inheritance in remote/local interfaces? (EJB3)

An example: @Remote public interface SomeComponentRemote{ public Something processStuff(); } //-- @Local public interface SomeComponentLocal extends SomeComponentRemote{ } Is that allowed? Can i do this regularly? ...

How does the Google Maps for Mobile "My Location" feature work?

I've installed the Google Maps Java 2 ME app on my Nokia N73 which supports the Location API (JSR 179), but does not have an in-built GPS sensor. The "My Location" features works correctly, and is able to pinpoint my position within the city. When I tried to access the CellID, LAC and other related data, I got nulls. So how is Maps abl...

java basics about final keyword

Can final keyword be used for a method? ...

java access modifiers

which access modifiers which when used with the method makes it available to all the class and subclasses within a package?? ...

Does serialization preserve object identity?

I am using the Java Serializable interface and the ObjectOutputStream to serialize objects (until now, this method has been sufficient for my purposes). My API relies on object identity for some operations and I’m wondering if it will be preserved by serialization. That is to say: if, for two arbitrary objects a and b, it holds a == b b...

Adapter Design Patter | adapter that converts an Iterator to an Enumeration |ConcurrentModificationException

As part of an exercise, am implementing an ArrayList which will support Enumerations. Following is the adapter that converts an Iterator to an Enumeration: public class MyEnumeratorAdapter<Object> implements Enumeration<Object> { private Iterator<Object> adaptee; public MyEnumeratorAdapter(Iterator<Object> it) { this.ada...

jtextfield default cursor position

I'm working with JTextField and the code for the text field. I'm trying to make a textfield as big as the notepad but the cursor always appears in the middle. I want to put in the starting of the textfield. tf=new JTextField(50); tf.setCaretPosition(0); f.setLayout(new BorderLayout()); f.add(tf,BorderLayout.CENTER); ...