All Questions

127
votes
5answers
29243 views

Providing white space in a Swing GUI

A GUI with no white space appears 'crowded'. How can I provide white space without resorting to explicitly setting the position or size of components?­­­­­­­­­­­­­­­­­­­­­­­­...
636
votes
11answers
79538 views

How do I write a correct micro-benchmark in Java?

How do you write (and run) a correct micro-benchmark in Java? I'm looking here for code samples and comments illustrating various things to think about. Example: Should the benchmark measure time/it...
467
votes
14answers
156719 views

What is a raw type and why shouldn't we use it?

Questions: What are raw types in Java, and why do I often hear that they shouldn't be used in new code? What is the alternative if we can't use raw types, and how is it better?
673
votes
29answers
1002271 views

How to parse JSON

I have the following JSON text that I need to parse to get pageName, pagePic, post_id, etc. What is the required code? { "pageInfo": { "pageName": "abc", "pagePic": "http://exam...
575
votes
12answers
427360 views

How to upload files to server using JSP/Servlet?

How can I upload files to server using JSP/Servlet? I tried this: <form action="upload" method="post"> <input type="text" name="description" /> <input type="file" name="file" /...
216
votes
7answers
535188 views

What does a "Cannot find symbol" compilation error mean?

Please explain the following about the "Cannot find symbol" error: What does this error mean? What things can cause this error? How does the programmer go about fixing this error? This question is...
1379
votes
25answers
1510149 views

What's the simplest way to print a Java array?

In Java, arrays don't override toString(), so if you try to print one directly, you get the className + @ + the hex of the hashCode of the array, as defined by Object.toString(): int[] intArray = new...
470
votes
7answers
251229 views

What is a stack trace, and how can I use it to debug my application errors?

Sometimes when I run my application it gives me an error that looks like: Exception in thread "main" java.lang.NullPointerException at com.example.myproject.Book.getTitle(Book.java:16) ...
553
votes
12answers
80825 views

Is List<Dog> a subclass of List<Animal>? Why are Java generics not implicitly polymorphic?

I'm a bit confused about how Java generics handle inheritance / polymorphism. Assume the following hierarchy - Animal (Parent) Dog - Cat (Children) So suppose I have a method doSomething(List<A...
617
votes
11answers
541557 views

What issues should be considered when overriding equals and hashCode in Java?

What issues / pitfalls must be considered when overriding equals and hashCode?

Previous Next