Why is using a wild card with a Java import statement bad?

Why is using a wild card with a Java import statement bad?

It is much more convenient and cleaner to use a single statement likeimport java.awt.*;than to import a bunch of individual classesimport java.awt.Panel;import java.awt.Graphics;import java.awt.Canvas;...What is wrong with using a wildcard

calling non-static method in static method in Java [duplicate]

calling non-static method in static method in Java [duplicate]

This question already has an answer here: Cannot make a static reference to the non-static method 8 answers I'm getting an error when I try to call a n

java.lang.IllegalStateException: Cannot (forward | sendRedirect | create session) after response has

java.lang.IllegalStateException: Cannot (forward | sendRedirect | create session) after response has

This method throws java.lang.IllegalStateException: Cannot forward after response has been committedand I am unable to spot the problem. Any help? int noOfRows = Integer.parseInt(request.getParameter("noOfRows")); String chkboxVal =

Access-Control-Allow-Origin Multiple Origin Domains?

Access-Control-Allow-Origin Multiple Origin Domains?

Is there a way to allow multiple cross-domains using the Access-Control-Allow-Origin header?I'm aware of the *, but it is too open. I really want to allow just a couple domains.As an example, something like this:Access-Control-Allow-Origin:

getResourceAsStream() vs FileInputStream

getResourceAsStream() vs FileInputStream

I was trying to load a file in a webapp, and I was getting a FileNotFound exception when I used FileInputStream. However, using the same path, I was able to load the file when I did getResourceAsStream(). What is the difference between the

StringBuilder vs String concatenation in toString() in Java

StringBuilder vs String concatenation in toString() in Java

Given the 2 toString() implementations below, which one is preferred:public String toString(){ return "{a:"+ a + ", b:" + b + ", c: " + c +"}";}orpublic String toString(){ StringBuilder sb = new StringBuilder(100); return sb.append

How to append text to an existing file in Java

How to append text to an existing file in Java

I need to append text repeatedly to an existing file in Java. How do I do that? 1:Are you doing this for logging purposes? If so there are several libraries for this. Two of the most popular are Log4j and Logback.Java 7+If you just need

Unfortunately MyApp has stopped. How can I solve this?

Unfortunately MyApp has stopped. How can I solve this?

I am developing an application, and everytime I run it, I get the message: Unfortunately, MyApp has stopped.What can I do to solve this?About this question - obviously inspired by What is a stack trace, and how can I use it to debug my app

Reading a remote file using Java

Reading a remote file using Java

I am looking for an easy way to get files that are situated on a remote server. For this I created a local ftp server on my Windows XP, and now I am trying to give my test applet the following address:try{ uri = new URI("ftp://localhost/

How to fix NoSuchMethodError?

How to fix NoSuchMethodError?

I use Scala 2.10.0RC1 and sbt 0.12.1.What causes and how can I fix this runtime error (runs fine on 2.9.2)?The exact error message is: java.lang.NoSuchMethodError: scala.Predef$ArrowAssoc$.extension$$minus$greater(Ljava/lang/Object;Ljava/l

Is there any available API to represent various units of item like KG, Litre, Metre, KM, etc

Is there any available API to represent various units of item like KG, Litre, Metre, KM, etc

In my project, somewhere I have to work with a unitOfIssue of Items. Now, various items of course can have different units of representation. So, I was searching for some API or some way, to elegantly handle this situation.Is there any avai

Can I avoid running junit tests twice in eclipse when using a TestSuite?

Can I avoid running junit tests twice in eclipse when using a TestSuite?

I need to do some per-suite initialisation (starting a web-server). It is working fine except that when I run all tests in my project in eclipse my tests run twice. My test suite looks a bit like this:@RunWith(Suite.class)@Suite.SuiteClasse

convert vector to jobject in C++/JNI?

convert vector to jobject in C++/JNI?

I am using Java native function - public native ArrayList parseXML();In C++ my native function - vector resultList;JNIEXPORT jobject JNICALL Java_Sample1_parseXML(JNIEnv *env, jobject obj){ // logic return resultList; // here getting

Android ViewPager with images: memory leak/app crashes

Android ViewPager with images: memory leak/app crashes

I am writing an app that displays a panorama picture that eventually has several markers on it to display information about certain points.As the large image crashed the app (I have also another activity in the app that is displaying a larg

Making GSON & Realm play nice

Making GSON & Realm play nice

I'm trying to use Realm + GSON.If they would work together well, it would be a match made in heaven.However, when I extend my model objects with "extends RealmObject" I get this:10-08 17:00:19.578 12492-12492/appwise.be.gsontestproject E/A

/WEB-INF/classes vs /WEB-INF/lib

/WEB-INF/classes vs /WEB-INF/lib

I'd like to package my Java EE6 web classes (beans, filters, servlets) into jar and place it into /WEB-INF/lib/ directory along with other utility jars and abandon /WEB-INF/classes/ directory totally.Are there any substantial differences be

Clojure: sequence back to vector

Clojure: sequence back to vector

How can I cast a sequence back to vector after a sequence producing operation (like sort)? Does using (vec..) on a sequence that was a vector is costly? One (bad?) possibility is creating a new vector out of sequence:(vec (sort [1 2 3 4 5 6

onConfigurationChanged() not firing for keyboardHidden

onConfigurationChanged() not firing for keyboardHidden

I've followed the various questions and answers here to setup my Android activity to override the onConfigurationChanged() in order to execute logic when the soft keyboard opens and closes. Here's the relevant excerpts from my code. I've

Java 8: Class JavaLaunchHelper is implemented in both

Java 8: Class JavaLaunchHelper is implemented in both

I'm trying to launch Cassandra and I'm running into an issue with JavaLaunchHelper being located in two places. I'm running Java 8. Here's the exact error:objc[413]: Class JavaLaunchHelper is implemented in both/Library/Java/JavaVirtualMach

Sleep and check until condition is true

Sleep and check until condition is true

Is there a library in Java that does the following? A thread should repeatedly sleep for x milliseconds until a condition becomes true or the max time is reached. This situation mostly occurs when a test waits for some condition to become t

Scala - obtaining a class object from a generic type

Scala - obtaining a class object from a generic type

Is it possible to create a Class object purely from a generic parameter? For example:class myclass[T] { def something(): Class[_ Since the type will have been erased at runtime, it seems like this a job for manifests, but I haven't found

How do i find out the JDK version Eclipse is using?

How do i find out the JDK version Eclipse is using?

I see JRE all over the place, but i can not be sure which JDK is compiling my code. How do i find out? 1:Actually Eclipse has its own compiler. You can develop java apps using only the JRE and Eclipse 2:You can still check/set which J

How to extend Java annotation?

How to extend Java annotation?

In my project I use pre-defined annotation @With:@With(Secure.class)public class Test { //....The source code of @With:@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.TYPE)public @interface With { Class[] value() default {};}I wa

How to Java String.format with a variable precision?

How to Java String.format with a variable precision?

I'd like to vary the precision of a double representation in a string I'm formatting based on user input. Right now I'm trying something like:String foo = String.format("%.*f\n", precision, my_double);however I receive a java.util.UnknownFo

What is the simplest way to write a text file in java

What is the simplest way to write a text file in java

Hello, I am wondering what is the easiest (and simplest) way to write a text file in java. Please be simple, because I am a beginner :DI searched the web and found this code, but I understand 50% of it.import java.io.BufferedWriter;import j