A boxed primitive is created just to call its compareTo
method. It's more efficient to use the associated static compare method (for double and float since Java 1.4, for other primitive types since Java 7) which works on primitives directly.
This method or field is or uses a Map
or Set
of URL
s. Since both the equals
and hashCode
method of URL
perform domain name resolution, this can result in a big performance hit.
This method accesses the value of a Map entry, using a key that was retrieved from a keySet
iterator. It is more efficient to use an iterator on the entrySet
of the map, to avoid the Map.get(key)
lookup.
The method calls Connection.prepareStatement
inside the loop passing the constant arguments. If the PreparedStatement
should be executed several times there's no reason to recreate it for each loop iteration.
toString
invoked on a string value is useless JAVA-S0064Calling String.toString
is a redundant operation. Just use the string directly.
Boolean
constructor is inefficient, consider using Boolean.valueOf
instead JAVA-S0066Creating new instances of java.lang.Boolean
wastes memory, since Boolean
objects are immutable and there are only two useful values of this type.
Integer
/Long
constructor is inefficient, use valueOf
instead JAVA-S0067Using Integer
's default constructor is guaranteed to always result in a new object whereas Integer.valueOf
allows the compiler/class library/JVM to cache values, which is known as interning.
Float
/Double
constructor is inefficient, use valueOf
instead JAVA-S0068Using Float
or Double
's default constructor is guaranteed to always result in a new object whereas the valueOf
method of these classes allows the JVM to cache values, which is known as interning.
""
instead of new String()
to create empty strings JAVA-S0063Creating a new java.lang.String
object using the default constructor wastes memory because the object so created will be functionally indistinguishable from the empty string constant ""
.
String
constructor JAVA-S0062Creating a String
using object creation wastes memory because the new String
object so constructed will be functionally indistinguishable from the String
value passed as a parameter. Just use the string directly.
This code explicitly invokes garbage collection via System.gc
or Runtime.gc
. Except for specific use in benchmarking, this is very dubious.
This method or field is or uses a Map
or Set
of URL
s. Since both the equals
and hashCode
method of URL
perform domain name resolution, this can result in a big performance hit.
String
constructor JAVA-P0062Creating a String
using object creation wastes memory because the new String
object so constructed will be functionally indistinguishable from the String
value passed as a parameter. Just use the string directly.
""
instead of new String()
to create empty strings JAVA-P0063Creating a new java.lang.String
object using the default constructor wastes memory because the object so created will be functionally indistinguishable from the empty string constant ""
.
toString
invoked on a string value is useless JAVA-P0064Calling String.toString
is a redundant operation. Just use the string directly.
This code explicitly invokes garbage collection via System.gc()
or Runtime.gc()
. Except for specific use in benchmarking, this is very dubious.
Boolean
constructor is inefficient, consider using Boolean.valueOf
instead JAVA-P0066Creating new instances of java.lang.Boolean
wastes memory, since Boolean
objects are immutable and there are only two useful values of this type.
Integer
/Long
constructor is inefficient, use valueOf
instead JAVA-P0067Using Integer
's default constructor is guaranteed to always result in a new object whereas Integer.valueOf
allows the compiler/class library/JVM to cache values, which is known as interning.
Float
/Double
constructor is inefficient, use valueOf
instead JAVA-P0068Using Float
or Double
's default constructor is guaranteed to always result in a new object whereas the valueOf
method of these classes allows the JVM to cache values, which is known as interning.
Pattern.compile()
should not be called in a loop JAVA-P0331This method calls Pattern.compile()
inside a loop with constant arguments. If this Pattern
will be used several times, there's no reason to compile it on each loop iteration.