org.apache.commons.lang.NumberUtils is deprecated and I have not found what to use instead of this class in same jar commons-lang-2.6.jar
Updated:
I could not realize the description,
Deprecated. Moved to org.apache.commons.lang.math. Class will be removed in Commons Lang 3.0.
http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/NumberUtils.html
Like the javadoc of NumberUtils says, the class is moved to the math subpackage
It is now :
org.apache.commons.lang.math.NumberUtils
moved to the math sub package.
Related
I am trying to invalidate items in cloud front. I fount that the class http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudfront_2012_03_15/AmazonCloudFrontClient.html is deprecated.
What class should I use?
There is a class with the same name in another package which is not #Deprecated:
Docs for com.amazonaws.services.cloudfront.AmazonCloudFrontClient
The deprecated class is in the namespace com.amazonaws.services.cloudfront_2012_03_15.AmazonCloudFrontClient.
I realized my IDE was importing from the wrong package.
Use this:
import com.amazonaws.services.cloudfront.AmazonCloudFrontClient;
https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudfront/AmazonCloudFrontClient.html#createInvalidation(com.amazonaws.services.cloudfront.model.CreateInvalidationRequest
I would like to reference a class Bag in a JAR file, but Eclipse is telling me that Bag cannot be resolved to a type. I have added the JAR in which Bag is defined to the classpath for the project, but the error is still there. What am I doing wrong?
I think you can't do that, because the Bag class in algs4.jar is inside the default package.
Before J2SE 1.4, we still can import classes from the default package using a syntax like this:
import Unfinished;
But from J2SE 1.5, that's no longer allowed. So if we want to access a default package class from within a packaged class requires moving the default package class into a package of its own. Read here for more detail explanation :
How to access java-classes in the default-package?
Some options you can choose :
Access the class via reflection or some other indirect method. But it is a little bit hard, something like this :
Class fooClass = Class.forName("FooBar");
Method fooMethod = fooClass.getMethod("fooMethod", new Class[] { String.class });
String fooReturned = fooMethod.invoke(fooClass.newInstance(), new String("I did it"));
If you own the source code of that jar library, you need to put it in properly package and wrap it again as a new jar library.
You may need to either fully qualify the Bag class, or import it.
How can I mention the path of a class as in following code?
Class cl=Class.forName("SomeClass");
This works well if the "SomeClass" is located in the same directory of the calling class. But how to check for a class from a different directory, I saw the syntax for that is like xxxx.yyyy.class, but could not make out what those 'x's and'y's stand for. please help.
Thanks in advance.
Use the fully-qualified class name. For instance, to do this with the Java SE String class, which is in the java.lang package:
Class clazz = Class.forName("java.lang.String");
Those xxx and yyy stands for package names. Packages are normally represented by directories on disk with the same name as the package. When you create a class file you can specify which package the class goes by stating package xxx.yyy at the top of the file.
Referring to "SomeClass" without a package name will try to load a class named SomeClass in the default package.
Use Class.forName although make sure you deal with a possible ClassNotFoundException exception. This is a runtime exception so it does not mean you need to catch it. This is how you will know if you path to the class is correct. The problem is that if it cannot find the class funny things can happen with your code.
Class.forName(com.my.package.ClassName)
It gives an error "Could not find the main class: filename.java" How do I set the filename to be independent of the class names?
You can't ... In Java the file name has to match the name of the public class in the file
See Why are filenames in Java the same as the class name? for an explanation
Short Answer: You can't. One class per file is the java way. Accept that or find another language.
Longer Answer: You can but you probably don't want to.
If you have one public class and x number of non-public classes, you can put the all in the same file by nesting the non-public classes inside the public class. For example (in BlowFish.java):
public class BlowFish
{
class Hooty
{
}
class Sushi
{
}
}
you can't. a java class must be in a .java file with the same name.
maybe is into the manifesto file where you are defining this class as your main class
Sure you can. Just put version numbers in your classnames, as well.
Or keep the newest as the classname.java, with older versions getting version numbers.
Or drop the version numbers and use source code control.
In Java, if you import a deprecated class:
import SomeDeprecatedClass;
You get this warning: The type SomeDeprecatedClass is deprecated
Is there a way to suppress this warning?
To avoid the warning:
do not import the class
instead use the fully qualified class name
and use it in as few locations as possible.
Use this annotation on your class or method:
#SuppressWarnings("deprecation")
Since Java 9, you might need to add:
#SuppressWarnings("removal")
If the class was annotated with something like:
#Deprecated(since = "3.14", forRemoval = true)
As a hack you can not do the import and use the fully qualified name inside the code.
You might also try javac -Xlint:-deprecation not sure if that would address it.
I solved this by changing the import to:
import package.*
then annotating the method that used the deprecated classes with#SuppressWarnings("deprecation")
Suppose that you are overriding/implementing an interface with a deprecated method (such as the getUnicodeStream(String columnLabel) in java.sql.ResultSet) then you will not get rid of deprecation warnings just by using the annotation #SuppressWarnings( "deprecation" ), unless you also annotate the same new method with the #Deprecated annotation. This is logical, because otherwise you could undeprecate a method by just overriding its interface description.
you can use:
javac FileName.java -Xlint:-deprecation
But then this will give you warnings and also tell you the part of the code that is causing deprecation or using deprecated API. Now either you can run your code with these warnings or make appropriate changes in the code.
In my case I was using someListItem.addItem("red color") whereas the compiler wanted me to use someListItem.add("red color");.
If #SuppressWarnings("deprecation") is not working for you like for me. You can find exact squid number in sonar lint plugin. And then you can simply suppress warning: #SuppressWarnings("squid:CallToDeprecatedMethod")