Type erasure in the confusion of generics

I was reading concept of type erasure in generics. While executing the below piece of code I got confused. public class CollectionsWild { void Test(Collection<?> t){ System.out.println("Collection"); } void Test(List<Integer> t){ Sys

How to display Toast after a completed task?

I use this code to delete a file File dir = new File(Environment.getExternalStorageDirectory() + "/myapp/" + "/Media/"); if (dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { new File(d

How to use Spring Page without spring data

Hi i'm using below code for find article using spring with plain hibernate. public List<Article> getArticles(int currPosition, int pageSize) { Criteria c = getSession().createCriteria(Article.class); c.addOrder(Order.desc("createdDate"));

Get information about using jvm memory in java code

There are many ways to analyze jvm memory usage offline, like MAT, jmap. However, is there any way to measure the memory usage inside the code during the runtime? Any advice will be much appreciated.Please refer to the official Java documentation, i.

Send an email OAUTH2 SMTP Outlook Java

I am using the scopes: mail.send, mail.readwrite, mail.read, offline_access, openid, email, and profile (although I am fairly confident I do not need all of these -> goal is to read inbox and send emails, while also getting email and name if they exi

expected = JSONException.class does not catch

I made a Test where I send an invalid JSON, and it should catch me a JSONException. When I run the test, it fails and shows me a JSONException, Why doesn't test catch it? @Test (expected = JSONException.class) public void testExtraFieldsJsonException

Get a definition of non-class found error in the error?

I am writing an android app but using JUnit to test it out some of the more java-specific functionality before creating activities and the android-specific functions. As I write out the JUnit tests and execute them bit by bit, I am finding failures a

Send a file with Java Sockets, lose data

I'm trying to send a file from a client to a server with Sockets in Java. It works fine when I am testing on the same machine, but when I test across different machines, I lose large chunks of data, resulting in a corrupted file. If I try to send a v

RGB to Philips Hue (HSB)

I'm making a musicplayer in Processing for an assignment for school. The Philips Hue lights will make some corresponding visual effects. I wanted to make the visuals kinda unique for each song. So I fetched the cover art (using LastFM API) of the pla

Change the JLabel background on the MouseRelease event

I am trying to write a Java program that when you click on a certain element in the JFrame, the background of a JLabel is changed. The function that the event handling method calls to change the background does not work when called from the event, ho

How to make this method return an array?

How can I make the following method return a character array ? public char[] startThread() { // arr declaration Runnable r = new Runnable() { @Override public void run() { arr = getArray(); // arr assignment } }; new Thread(r).start(); return arr; }

Long string used in Java

Let say I have to used a two paragraph string in my java program. What would be the best approach on this? Should the paragraph saved in a file and retrieved when used? Or there are better approach?It depends. If the paragraphs will never change, the

Statement of Regular Expression

I've never been good with regex and I can't seem to get this... I am trying to match statements along these lines (these are two lines in a text file I'm reading) Lname Fname 12.35 1 Jones Bananaman 7.1 3 Currently I am using this for a while stateme

SOAP Asynchronous Web Service

I have an interface that I've exposed as a regular SOAP web service. One method of the interface consists for the client to send a file to the server, then the server processes the file and returns a result file. Processing the file may take some tim

Is it possible to run the maven plugin of the java class?

Need to run maven jaxb2 plugin from my app, at run-time. Is it possible?Maybe i have done something that could help you: /** * @author swoeste * */ public class MavenExecutor { private final File configuration; private final ClassWorld classWorld; /*

The most efficient way to run the method at a defined interval?

I want to run a specific method doThis() (which is not a CPU intensive action, it's just a POST to a web server) every 10 minutes and when that method is finished executing, to notify the user (via Toast or Notification or something of the sort). But

How to convert the Date represented in String in milliseconds?

Possible Duplicate: how to convert java string to Date object In my Java code I have input String like 05.10.2011 which I need to convert to milliseconds. So: String someDate = "05.10.2011"; I have to convert to match milliseconds format. String

How to have a scrollable JTextPane?

I would like to have a JTextPane that have scroll bar, how can I do so ? Thanks.To insert a scroll bar on your new JTextPane, just use a JScrollPane: JTextPane txt = new JTextPane(); JScrollPane jsp = new JScrollPane(txt); JTextPane API: http://downl

Convert java method to cpp

public boolean isDoubleValue(String s) { try { Double.valueOf(s); return true; } catch (Exception e) { return false; } } But i want to convert this method into QT cpp. Can any one help me? Thanks, NagarajuSince you need it in Qt (from your comment),

A simple java SOAP client

I'm new to web services and I've been breaking my head trying to find a simple java SOAP client program on the Internet. All I want to do is send a SOAP message and receive back some response. There is a website which offers free web-services. http:/

JEditorPane is the last line

Using a JEditorPane, is there any way to tell if the caret is currently on the last line? I cannot find anything in the API or more importantly JTextComponent of which JEditorPane is derived. I need to find this out when the user uses the down arrow

problem with Random.nextGaussian ()

Random.nextGaussian() is supposed to give random no.s with mean 0 and std deviation 1. Many no.s it generated are outside range of [-1,+1]. how can i set so that it gives normally distributed random no.s only in the range -1 to 1.A Gaussian distribut