Categories
discuss

is it possible to overload a final method

In java we cannot override a final method but is it possible to overload ?

Answer

Yes, overloading a final method is perfectly legitimate.

For example:

public final void doStuff(int x) { ... }
public final void doStuff(double x) { ... }
Categories
discuss

How do I debug a remote application in my eclipse

I am running my server from outside of my eclipse and now i want to debug it. so is it possible ? If yes how can i do that.

Answer

1) Specify this option on remote JVM.

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

Note that now the debug server is running at this remote host and port 5005.

2) In Eclipse, create and run remote debug config under Run > Debug> Debug Configurations… > Remote Java Application.

Categories
discuss

Can I batch some Swing component updates so that repaints are all done at once?

I have a bunch of buttons in my JToolBar, and I set some of them to be disabled or enabled depending on the state of my application. I find when I am updating a number of buttons at once that they are not all repainted at the same time. I want to ensure that when I set a number of buttons to be disabled/enabled, that they all change state at the same time.

Below is a small test that demonstrates the problem. (It needs a file a.png in the current directory to use as a button icon.) When you run it, a toolbar with 10 buttons is shown. Pressing Enter at the terminal will toggle the disabled state of all of the buttons. On my machine at least, each time I do this the buttons are repainted in a seemingly random order, and not all at once.

It seems like double buffering might solve the problem, although the first thing I tried (setting double buffering on the JToolBar) didn’t seem to affect anything.

Thanks,

Cameron

import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;

public class Test {
    public static void main(String[] args) throws IOException {
        final JButton[] bs = new JButton[10];
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame f = new JFrame("test");
                JToolBar t = new JToolBar();
                f.getContentPane().add(t);
                for (int i = 0; i < bs.length; i++) {
                    bs[i] = new JButton(new ImageIcon("a.png"));
                    t.add(bs[i]);
                }
                f.pack();
                f.setVisible(true);
            }
        });
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        for (;;) {
            r.readLine();
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    for (JButton b : bs) {
                        b.setEnabled(!b.isEnabled());
                    }
                }
            });
        }
    }
}

Answer

As long as the enable state changes happen in one event thread run, they happen so that nothing can’t go there between in invalid state. So I guess this is just a painting problem? It just looks bad?

One possible way to change the behavior is to add a repaint call for the container (the toolbar for example) so that bigger area is repainted at once instead of repainting each button separately.

Categories
discuss

Difference between tomcat and resin?

I like to know what are the differences between Tomcat container and Resin container

Answer

Tomcat is a stand alone web server supporting the J2EE web technologies (eg. Servlets, JSP) and Resin is a full blown J2EE Application server which includes a web server plus the rest of the J2EE family of technologies (eg. EJB). Tomcat is always free to use for any purpose. Resin is free only for open source or hobby use. Commercial use of Resin is not free. One interesting feature of Resin is the ability to run PHP applications under the JVM through Quercus.

Categories
discuss

How to query the MMS Log in Android

In my app I need to query both the SMS and the MMS log to get the history of all incoming and outgoing messages. This code has worked wonderfully for SMS:

Cursor c = cr.query(Uri.parse("content://sms"), null, null, null, null);

But when I try the following I get completely different results:

Cursor c = cr.query(Uri.parse("content://mms"), null, null, null, null);

The SMS query returns data that includes the message address (phone number), contact name, message subject, message body, etc… The same query for MMS returns a bunch of nulls or numeric value fields that I can’t make any sense of. I really need a list of all MMS messages currently on the phone with the phone number or contact ID associated with it, and if the message was an incoming or outgoing message. In the SMS query results I can get the phone number from the address field, and the incoming/outgoing type from the type field but neither of these exist when I query for MMS.

Is there a different content Uri that I need to query for this sort of MMS data? Any help would be greatly appreciated.

Edit: Just to clarify, I’m completely aware that this is an unsupported content provider. However since there is no supported way of doing this I’m fully willing to test and support this on a per phone/per OS version basis. Just to keep the discussion on track lets say this question is specific to Android 1.6 on an HTC Dream (G1) or HTC Magic (MyTouch). How would you accomplish this task on that specific phone and OS version? Or if it’s not possible on those, but it is possible on Android 2.0 on a Motorola Droid, then I would find that information very helpful as well. But regardless, lets stick to the discussion of how to accomplish this task in a supported or unsupported manner and not let it devolve into a discussion of how we should all stay away from things that aren’t supported by the API, which is something I find the Android discussion groups to be riddled with and which I feel provides little to no help whatsoever. If I’m using an unsupported method, that’s fine, show me the supported method of accomplishing that task. If there is no supported method, then why does the API support allowing me to request permission to read SMS via android.permission.READ_SMS?

Answer

These are the content uris I’ve used in the past. You’ll have to fiddle with the values you get back, and it’s a long way from getting the parts of an MMS, but hopefully it’ll help.

// root URI for MMS messages
static final String MMS_CONTENT_URI = "content://mms";

// root URI for MMS and SMS threads
public static final String MMS_SMS_CONTENT_URI = "content://mms-sms";

// URI of MMS inbox
public static final String RECEIVED_MMS_CONTENT_URI = MMS_CONTENT_URI + "/inbox";

// URI where sent MMSes are stored
public static final String SENT_MMS_CONTENT_URI = MMS_CONTENT_URI + "/sent";

// URI where sent MMSes are stored
public static final String MMS_PART_URI = MMS_CONTENT_URI + "/part";

// URI for incoming SMSes (also triggers on MMSes)
public static final String SMS_INBOX_URI = "content://sms/inbox";
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..