Java optional parameters
2021-6-3 anglehua
How do I use optional parameters in Java? What specification supports optional parameters? varargs could do that (in a way). Other than that, all variables in the declaration of the method must be supplied. If you want a variable to be optional, you can overload the method using a signature which ...Error java.lang.OutOfMemoryError: GC overhead limit exceeded
2021-6-3 anglehua
I get this error message as I execute my JUnit tests: java.lang.OutOfMemoryError: GC overhead limit exceeded I know what an OutOfMemoryError is, but what does GC overhead limit mean? How can I solve this? This message means that for some reason the garbage collector is taking an excessive amount o...How to convert a char to a String?
2021-6-3 anglehua
I have a char and I need a String. How do I convert from one to the other? You can use Character.toString(char). Note that this method simply returns a call to String.valueOf(char), which also works. As others have noted, string concatenation works as a shortcut as well: String s = "" + 's'; But t...Efficiency of Java “Double Brace Initialization”?
2021-6-3 anglehua
In Hidden Features of Java the top answer mentions Double Brace Initialization, with a very enticing syntax: Set<String> flavors = new HashSet<String>() {{ add("vanilla"); add("strawberry"); add("chocolate"); add("butter pecan"); }}; This idiom creates an anonymous inner...How do I join two lists in Java?
2021-6-3 anglehua
Conditions: do not modify the original lists; JDK only, no external libraries. Bonus points for a one-liner or a JDK 1.3 version. Is there a simpler way than: List<String> newList = new ArrayList<String>(); newList.addAll(listOne); newList.addAll(listTwo); In Java 8: List<String>...What is the difference between JSF, Servlet and JSP?
2021-6-3 anglehua
I have some questions. These are : How are JSP and Servlet related to each other? Is JSP some kind of Servlet? How are JSP and JSF related to each other? Is JSF some kind of Pre-Build UI based JSP like ASP.NET-MVC? JSP (JavaServer Pages) JSP is a Java view technology running on the server machi...Linking to an external URL in Javadoc?
2021-6-3 anglehua
Something like: /** * See {@linktourl http://google.com} */ This creates a "See Also" heading containing the link, i.e.: /** * @see <a href="http://google.com">http://google.com</a> */ will render as: See Also: http://google.com whereas this: /** * See <a href="...What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?
2021-6-3 anglehua
What is the difference between CrudRepository and JpaRepository interfaces in Spring Data JPA? When I see the examples on the web, I see them there used kind of interchangeably. What is the difference between them? Why would you want to use one over the other? JpaRepository extends PagingAndSortin...How do I copy an object in Java?
2021-6-3 anglehua
Consider the code below: DummyBean dum = new DummyBean(); dum.setDummy("foo"); System.out.println(dum.getDummy()); // prints 'foo' DummyBean dumtwo = dum; System.out.println(dumtwo.getDummy()); // prints 'foo' dum.setDummy("bar"); System.out.println(dumtwo.getDummy()); // prints 'bar' but it shoul...What is the Java equivalent for LINQ?
2021-6-3 anglehua
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago. ...What is a daemon thread in Java?
2021-6-3 anglehua
Can anybody tell me what daemon threads are in Java? A daemon thread is a thread that does not prevent the JVM from exiting when the program finishes but the thread is still running. An example for a daemon thread is the garbage collection. You can use the setDaemon(boolean) method to change the Th...What's the difference between SoftReference and WeakReference in Java?
2021-6-3 anglehua
What's the difference between java.lang.ref.WeakReference and java.lang.ref.SoftReference ? From Understanding Weak References, by Ethan Nicholas: Weak references A weak reference, simply put, is a reference that isn't strong enough to force an object to remain in memory. Weak references all...How to pass an object from one activity to another on Android
2021-6-3 anglehua
I am trying to work on sending an object of my customer class from one Activity and display it in another Activity. The code for the customer class: public class Customer { private String firstName, lastName, Address; int Age; public Customer(String fname, String lname, int age, String...What is an efficient way to implement a singleton pattern in Java?
2021-6-3 anglehua
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. ...Access restriction on class due to restriction on required library rt.jar?
2021-6-3 anglehua
I'm attempting to compile Java 1.4 code that was created by IBM's WSDL2Java on Java5 without recreating the stubs and saw this error in Eclipse. I'm under the assumption that the stubs generated should just compile as long as the runtime jars are available (they are). Access restriction: The type QN...Unfortunately MyApp has stopped. How can I solve this?
2021-6-3 anglehua
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 application errors?, there are lots of questions stating th...How do I tell Maven to use the latest version of a dependency?
2021-6-3 anglehua
In Maven, dependencies are usually set up like this: <dependency> <groupId>wonderful-inc</groupId> <artifactId>dream-library</artifactId> <version>1.2.3</version> </dependency> Now, if you are working with libraries that have frequent releases, ...File to byte[] in Java
2021-6-3 anglehua
How do I convert a java.io.File to a byte[]? It depends on what best means for you. Productivity wise, don't reinvent the wheel and use Apache Commons. Which is here FileUtils.readFileToByteArray(File input). From JDK 7 you can use Files.readAllBytes(Path). Example: import java.io.File; import jav...How to make a new List in Java
2021-6-3 anglehua
We create a Set as: Set myset = new HashSet() How do we create a List in Java? List myList = new ArrayList(); or with generics (Java 7 or later) List<MyType> myList = new ArrayList<>(); or with generics (Old java versions) List<MyType> myList = new ArrayList<MyType>(); ...How to call a method after a delay in Android
2021-6-3 anglehua
I want to be able to call the following method after a specified delay. In objective c there was something like: [self performSelector:@selector(DoSomething) withObject:nil afterDelay:5]; Is there an equivalent of this method in android with java? For example I need to be able to call a method aft...