Questions tagged [java-5]
Java SE version 5 was released in September 2004 and is no longer supported by Sun as of November 2009. Use only if your question is specifically related to features of this version.
java-5
349
questions
1067
votes
33
answers
1.5m
views
How do I join two lists in Java?
Is there a simpler way than:
List<String> newList = new ArrayList<String>();
newList.addAll(listOne);
newList.addAll(listTwo);
Conditions:
Do not modify the original lists.
JDK only.
No ...
186
votes
21
answers
88k
views
Why do people still use primitive types in Java?
Since Java 5, we've had boxing/unboxing of primitive types so that int is wrapped to be java.lang.Integer, and so and and so forth.
I see a lot of new Java projects lately (that definitely require a ...
157
votes
8
answers
280k
views
How to set a JVM TimeZone Properly
I am trying to run a Java program, but it is taking a default GMT timezone instead of an OS defined timezone. My JDK version is 1.5 and the OS is Windows Server Enterprise (2007)
Windows has a ...
78
votes
13
answers
389k
views
Java reading a file into an ArrayList?
How do you read the contents of a file into an ArrayList<String> in Java?
Here are the file contents:
cat
house
dog
.
.
.
73
votes
4
answers
133k
views
How to redirect verbose garbage collection output to a file?
How do I redirect verbose garbage collection output to a file? Sun’s website shows an example for Unix but it doesn't work for Windows.
73
votes
6
answers
66k
views
Java Generics: Generic type defined as return type only
I'm looking at some GXT code for GWT and I ran across this use of Generics that I can't find another example of in the Java tutorials. The class name is com.extjs.gxt.ui.client.data.BaseModelData if ...
36
votes
11
answers
7k
views
Reasons and advantages for upgrading to Java 6 for a non-technical decider (at the client)
I'd like to upgrade from Java 5 to Java 6.
We all know about the technical advantages and benefits, but:
I have the problem that a major client refuses to upgrade from java 5 to java 6 because of "...
36
votes
2
answers
31k
views
What is the easiest way to iterate over all the key/value pairs of a java.util.Map in Java 5 and higher?
What is the easiest way to iterate over all the key/value pairs of a java.util.Map in Java 5 and higher?
33
votes
4
answers
21k
views
Mockito isA(Class<T> clazz) How to resolve type safety?
in my test I have the following line:
when(client.runTask(anyString(), anyString(), isA(Iterable.class)).thenReturn(...)
isA(Iterable.class) produces warning that it needs unchecked conversion to ...
33
votes
1
answer
6k
views
What are the 37 Java API packages possibly encumbered by the May 2014 Oracle v Google decision?
What are the 37 Java API packages possibly encumbered by the May 2014 Oracle v Google decision?
What are the 3 packages that the Appellate Court decided were essential to the language?
How can I ...
27
votes
7
answers
52k
views
How to disable TestNG test based on a condition
Is there currently a way to disable TestNG test based on a condition
I know you can currently disable test as so in TestNG:
@Test(enabled=false, group={"blah"})
public void testCurrency(){
...
}
I ...
25
votes
5
answers
32k
views
What is the use of <T> in public static <T> T addAndReturn(T element, Collection<T> collection){
I get confused when I come across a generic method of this sort.
public static <T> T addAndReturn(T element, Collection<T> collection){
collection.add(element);
return element;
}
...
23
votes
4
answers
62k
views
JAXB unmarshalling ignoring namespace turns element attributes into null
I'm trying to use JAXB to unmarshal an xml file into objects but have come across a few difficulties. The actual project has a few thousand lines in the xml file so i've reproduced the error on a ...
23
votes
4
answers
6k
views
Why wasn't java.io.Serializable deprecated in Java 5?
In pre Java 5, there were no annotations. As a result you could not add metadata to a class.
To mark a class as serializable, you had to implement the Serializable interface (which is just that, a ...
20
votes
5
answers
11k
views
java.lang.InternalError: name is too long to represent
I get this error:
java.lang.InternalError: name is too long to represent
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)...
19
votes
3
answers
10k
views
TimeZone.setDefault changes in JDK6
I just noticed that JDK 6 has a different approach to setting a default TimeZone than JDK5.
Previously the new default would be stored in a thread-local variable. With JDK6 (I just reviewed 1.6.0.18)...
19
votes
3
answers
28k
views
Did we always have to register to download the Java 5 JDK, or is this new Oracle fun?
I could swear that just a couple of months ago I downloaded a copy of the Java 1.5 SE JDK and I did not have to give them information on my first born. Today, I had to go through the register-and-we-...
16
votes
9
answers
79k
views
SEVERE: A message body writer for Java class java.util.ArrayList and MIME media type application/json was not found
I am testing RESTful services and when I execute I am getting exceptions although I have the following jars in my class path(WEB-INF/lib), I am not using Maven and my JDK version is 1.5. Other ...
16
votes
2
answers
120k
views
Invalid maximum heap size
I have copied a jdk directory from another location. Since then, I get the following error message.
Your environment has been set.
java version "1.5.0_22"
Java(TM) 2 Runtime Environment, Standard ...
15
votes
9
answers
3k
views
Do you use Java annotations? [duplicate]
Possible Duplicates:
How and where are Annotations used in Java?
Java beans, annotations: What do they do? How do they help me?
Over and over, I read about Java 5's annotations being an '...
14
votes
7
answers
21k
views
Java method works in 1.5 but not 1.6
I have an application which has been running happily under Java 1.5 for around a year. We've just had the boxes updated and had Java 1.6 installed.
After deploying the app to the new server we've ...
14
votes
5
answers
8k
views
When should I use the java 5 method cast of Class?
Looking through some code I came across the following code
trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto));
and I'd like to know if casting this way has any advantages over
...
13
votes
4
answers
11k
views
Will compiling for Java 1.5 on Java 1.7 still work?
I've recently moved to Java 7 in one of my projects. I claim that it can run on Java 1.5 simply because there's nothing I depend on that is in Java 6 or 7. However when compiling today I noticed this:
...
12
votes
5
answers
19k
views
Maven - Use JDK 7 to Compile for JVM 5
I've been trying to get this to work for a while now but no luck yet.
I want to run with JAVA_HOME pointing to JDK7 but I want to compile a project for JVM 5. I've read through documentation, I've ...
12
votes
2
answers
775
views
Cant understand the working of File object.delete()
I am trying to delete a jar file using java 5 (So the Paths API introduced in Java 7 is not an option).
My code:
String sep = File.separator;
File test = new File("."+ sep + "server" + sep + "lib" +...
11
votes
8
answers
12k
views
Cross-platform way to open a file using Java 1.5
I'm using Java 1.5 and I'd like to launch the associated application to open the file. I know that Java 1.6 introduced the Desktop API, but I need a solution for Java 1.5.
So far I found a way to do ...
11
votes
2
answers
11k
views
Illegal access exception when trying to access attibrute from parent class by introspection
I am currently playing with introspection and annotations in Java 1.5.
The have a parent abstract class AbstractClass.
The inherited classes can have attributes (of type ChildClass) annotated with a ...
11
votes
4
answers
31k
views
Java Quickly check for network connection
My issue is fairly straightforward. My program requires immediate notification if a network connection is lost. I'm using Java 5, so I'm unable to use the very handy features of NetworkInterface.
...
11
votes
4
answers
2k
views
Why the output is different between JDK 1.4 and 1.5?
I'm running this code with JDK 1.4 and 1.5 and get different results. Why is it the case?
String str = "";
int test = 3;
str = String.valueOf(test);
System.out.println("str[" + str + "]\nequals ...
11
votes
3
answers
5k
views
When should we use console class?
I was reading about Console class, and in the very first line, it was written
New to Java 6 and when we are running Java SE 6 from command line, then we are typically using console class object
...
10
votes
4
answers
73k
views
How Can I create a generic HashMap to insert collections and objects?
How Can I instantiate a HashMap to put collections and objects?.
//it's wrong
Map<String,?>params=new HashMap<String,? >
List<Person> lstperson=getPerson();
params.put("person",...
10
votes
2
answers
23k
views
How Can I Tell Eclipse to Compile and Build a Project with a Different JRE Version than it Normally Does?
I'm not sure if this question has been answered in full or if my title is descriptive enough given my situation, but I've been asked to convert a project from being built with Ant to Maven. That part ...
10
votes
3
answers
6k
views
Extracting information from a a java core dump with jmap(1.5)
Long story short, some coworkers are running a pretty old setup(oc4j jdk1.5.6 in x86_64) with an application which happens to be mission critical. They recently have tried to deploy a new version of ...
9
votes
4
answers
5k
views
How to create custom JUnit4 assertions that don't show in the Failure Trace
I'd like to add some custom assertions to our code base that properly hide from the failure trace. I know how to write a public static method that someone can statically import. I know how to reuse ...
9
votes
3
answers
5k
views
Can I ignore BeanCreationException and inject null instead?
We have a situation where our Spring wires up some beans that include ActiveMQ classes built with Java 6. Our application runs on customer's servers, so we can't guarantee that they have Java 6 or ...
8
votes
2
answers
25k
views
IMAP access to mail office 365 with javamail
I'm trying to read the emails in a folder of an email account Office365 using JavaMail 1.4 api.
My code is:
public static void main(String argv[]) throws Exception {
// Get a Properties ...
8
votes
2
answers
4k
views
Using JAX-WS 2.2.5 client with JDK/JRE 1.5
Java 6 shipped with JAX-WS 2.0. Java 5 didn't ship with JAX-WS as far as I know.
I was able to use JAX-WS 2.2.5 with Java 1.6 for creating Webservice client stubs by using the Java Endorsed Override ...
8
votes
3
answers
872
views
Java: easiest way to package both Java 1.5 and 1.6 code
I want to package a piece of code that absolutely must run on Java 1.5. There's one part of the code where the program can be "enhanced" if the VM is an 1.6 VM.
Basically it's this method:
private ...
7
votes
3
answers
44k
views
Pop-up window in Java Swing
Can someone suggest me how to implement a pop-up window in Java Swing. I want the pop-up window to be a modal window (user cannot return to the main window when the pop-up is open).
I tried doing it ...
7
votes
1
answer
4k
views
which ephemeral port has java InetSocketAddress binded to?
What I'd like to achieve
bind a server to an ephemeral port for unit testing purposes.
My issue :
Using the 1.5.0_22 JDK I try to bind an InetSocketAddress on an ephemeral port using port 0 as per ...
7
votes
3
answers
5k
views
Where can I find the JDK 1.5 source code? [closed]
Where can I find the entire source code for JDK 1.5 to download? I am unable to find the exact link on the oracle site; the link provided only goes in circles.
7
votes
1
answer
833
views
Alternative for Collections.newSetFromMap to be used in JDK 1.5?
I want to use such "Collections.newSetFromMap()" method in JDK 1.5 which doesnt support it.
Also ConcurrentHashSet Class is not supported in java 5.
Have to compile following line in JDK 1.5.How do i ...
6
votes
4
answers
24k
views
Is is possible to build java code using JDK 1.6 to run on JRE 1.5?
Is there an option to build java code to run on JRE 1.5 when compiled using JDK 1.6?
PS: I am new to Java.
6
votes
4
answers
2k
views
Does increase in the number of comments increases the execution time?
Consider the following cases:
Case 1: (Less comments in for loop)
import java.io.IOException;
public class Stopwatch {
private static long start;
public static void main(String args[]) ...
6
votes
3
answers
11k
views
How do I add javax.annotation.Generated to Java SE 5?
I'm working on a project that has to run on Java SE 5 and Java SE 6. I recently started using a tool that adds @Generated annotations to generated code, and I want to keep those annotations. It looks ...
6
votes
5
answers
870
views
Best ways to write a method that updates two objects in a multithreaded java environment?
Suppose we have a class called AccountService that manages the state of accounts.
AccountService is defined as
interface AccountService{
public void debit(account);
public void credit(account);
...
6
votes
3
answers
706
views
Java version migration deprecated date methods
I'm migrating from Java 1.1. to Java 5.
I notice that some methods have been deprecated e.g. java.util.Date has a getYear() method which is deprecated.
My question is if the getYear() method is left ...
6
votes
3
answers
6k
views
How to migrate Java code to a more recent jdk (e.g. 1.8)
What is the best way to migrate Java code of an older jdk (1.5) to a more recent Java version (1.8) to provide from its new features and improvements.
We have a large Java jdk 5 code base and want to ...
6
votes
1
answer
3k
views
How to find out the drag source component in the drop target TransferHandler?
Question is regarding Java 5 and Drag n Drop.
Is there a way to determine the drag source component in the drop target TransferHandler?
I need to know this in my canImport(..) or importData(..) ...
6
votes
2
answers
549
views
Sun JDK 1.5 cannot dereference error with generics
We have a class hierarchy similar to this one:
public class TestDereference {
private static MainInterface mi = new MainInterfaceImpl();
public static void main(String[] args) {
System.out....