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
Related
I have the need of getting the Class from a String.
The string is just the class his name without the package declaration.
While I could use Class.forName(className); this requires me to give the FQN.
Here is just where I have the problem.
I know its base package : be.chillworld.catalog but this package have subpackages.
Example :
be.chillworld.catalog.location
be.chillworld.catalog.operation
Easiest solution is to remove all the subpackages so I can do the Class.forName() but there goes the nice structure then.
Anyone have an idea of how to get mine specific class?
Use Reflections Class.Give base package when initiating class and get your specific classes.
Reflections reflections = new Reflections("com.sss.xxx");
reflection.getSubTypesOf(ddd.class)
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.
I want to add an object to the Global scope, and in order to construct it I need to pass it a path to a file.
I don't want to hard code the file path in the source, and so I want to get that path from the application.conf.
The problem is that I don't know how to access these properties from the java class.
I tried this:
Configuration.root().getString("file.path")
But it ends with a NullPointerException.
Am I wrong in assuming that there's a global Configuration instance that I can use?
Thanks.
Try Play.application().configuration().getString("your.key")
As noted in the comment (nico_ekito), please use play.Play and not play.api.Play. play.api.Play is for scala controllers (see comment by Marcus biesior Biesioroff)
Additionally, play uses https://github.com/typesafehub/config under the hood so it can also provide some insights.
Even if it seems simple, here is the scala way to get properties from configuration file :
Play 2.0 and 2.1 :
import play.api.Play.current
...
Play.application.configuration.getString("your.key")
Play 2.2 and +
import play.api.Play.current
...
current.configuration.getString("your.key")
Using Typesafe config
import com.typesafe.config.ConfigFactory
...
ConfigFactory.load().getString("your.key");
From Play 2.4 and + it is better to use dependency injection to access Configurations:
import play.Configuration;
import javax.inject.Inject;
#Inject
private Configuration configuration;
...
String value = configuration.getString("your.key");
Since Play 2 uses the Typesafe config library, I accessed my vars in application.conf like this :
ConfigFactory.load().getString("my.var");
In the play java is:
import play.Play;
...
Play.application().configuration().getString("key")
Use as following (Tested in Play 1.2.5)
${play.configuration.getProperty('my.var')}
where my.var should be specified in application.conf file
As a reference to access it from the template (for play < 2)
play.configuration['your.key']
As folks have mentioned, Play.application.configuration no longer exists.
In Play Scala 2.3.x, to read a value from conf/application.conf, you can do the following:
import play.api.Play.current
...
current.configuration.getString("key")
In Play 1.2.x
import play.Play;
...
String version = Play.configuration.getProperty("application.version.number", "1.1.1");
where the second parameter is the default value
Import this
import com.typesafe.config.Config;
and write the below lines
private Config config;
this.config = ConfigProvider.config();
String value = this.config.getString("fieldFromConfigFile");
import play.Play;
String myVal = Play.configuration.getProperty("your.key").toString();
i use this in my app and it works
Dont forget to import play.Play. Hope it'll gives you help
Starting from version 2.5 please use play.Application class which should be injected and then
application.config().getString("your.property.here")
For Java Playframework:
In Application.conf, you can put something like that:
email="example#gmail.com.pe"
some class:
import play.Play;
String email = Play.application().configuration().getString("key") // key ->email
I am currently learning Java using the Deitel's book Java How to Program 8th edition (early objects version).
I am on the chapter on creating classes and methods.
However, I got really confused by the example provided there because it consists of two separate .java files and when one of them uses a method from the other one, it did not import the class. It just created an object of that class from the other .java file without importing it first.
How does that work? Why don't I need to import it?
Here is the code from the book (I removed most comments, to save typing space/time...):
.java class:
//GradeBook.java
public class GradeBook
{
public void displayMessage()
{
System.out.printf( "Welcome to the grade book!" );
}
}
The main .java file:
//GradeBookTest.java
public class GradeBookTest
{
public static void main( String[] args)
{
GradeBook myGradeBook = new GradeBook();
myGradeBook.displayMessage();
}
}
I thought I had to write
import GradeBook.java;
or something like that.
How does the compiler know where GradeBook class and its methods are found and how does it know if it exists at all if we dont import that class?
I did lots of Googling but found no answer.
I am new to programming so please tolerate my newbie question.
Thank you in advance.
It is because both are in same package(folder). They are automatically imported no need to write import statement for that.
You don't have to import classes that are in the same package as the current class.
Also, note that GradeBook.java is the name of the file. The (simple) name of the class is GradeBook. Every class should be in a package. If it is in the package com.foo.bar, the class name is com.foo.bar.GradeBook, and this is the name you must use when importing this class.
Read http://download.oracle.com/javase/tutorial/java/package/packages.html to learn more about packages.
The classes located in the same package do not have to be imported, as they are visible to each other. You simply import a class that is in another package:
import java.util.ArrayList;
Note that you are not importing the file, but the class.
It's all about packages. You are trying to use a class from the default package which does not need explicit import of the java file, ie GradeBook inside GradeBookTest
Here is where you can start with learning about packages :
Java Package Tutorial
and :
Creating and Using Packages
Java doesn't use includes the way C does. Instead java uses a concept called the classpath, a list of resources containing java classes. The JVM can access any class on the classpath by name so if you can extend classes and refer to types simply by declaring them.
From: Include one java file in another java file
Imports are for importing classes that are in a different package. Since you didn't declare a package for either they are both put in the default package. The compiler can find it because the class lives in the same directory.
You don't have to import classes which are in the same package.
Well, classes in the same package are automatically imported.
They're in the same package. This tutorial will do more justice than I will.
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")