This is really bad programming style
java.lang.String s = new String("hello");
Remember that all classes in java.lang
are imported automatically. If you have a class called String
in the same package, it will also be imported but shadow the java.lang.String
class. That might be a reason to fully qualify the type like
java.lang.String s;
But in this case, you could only ever assign a java.lang.String
reference to it since that class is final
and therefore cannot be extended. The conventional thing to do would be
java.lang.String s = new java.lang.String("hello");
If you were asking about
java.lang.String s = new String("hello");
vs
java.lang.String s = "hello";
then check out the other answers or the duplicate.