found = test.contains("B"); System.out.println("element B : " + (found ? "found" : "not found"));
found = test.contains("c"); System.out.println("element c : " + (found ? "found" : "not found"));
found = test.contains("C"); System.out.println("element C : " + (found ? "found" : "not found"));
} }
输出
1 2 3 4 5 6 7 8
element a : not found element B : found element c : not found element C : found element a : found element B : found element c : found element C : found
publicstaticvoidmain(String[] args){ String s = "Hello, World!"; System.out.println(s); s = "Welcome to Hello World!"; System.out.println(s); // we lost reference to "Hello, World!" System.out.println();
StringBuffer stringBuffer = new StringBuffer("Hello, World!"); System.out.println(stringBuffer); System.out.println(stringBuffer.toString()); // convert to String object stringBuffer = new StringBuffer("Welcome to Hello World!"); System.out.println(stringBuffer); System.out.println();
StringBuilder stringBuilder = new StringBuilder("Hello, World!"); System.out.println(stringBuilder); System.out.println(stringBuilder.toString()); // convert to String // object stringBuilder = new StringBuilder("Welcome to Hello World!"); System.out.println(stringBuilder); }
}
输出
1 2 3 4 5 6 7 8 9 10
Hello, World! Welcome to Hello World!
Hello, World! Hello, World! Welcome to Hello World!
Hello, World! Hello, World! Welcome to Hello World!
java.lang.ClassNotFoundException: ClassA at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at CoreJavaLearn.ClassNotFoundExceptionTest.main(ClassNotFoundExceptionTest.java:8)
```java Exception in thread "main" java.lang.Error: Unresolved compilation problems: ConnectionFactory cannot be resolved to a type ActiveMQConnectionFactory cannot be resolved to a type ActiveMQConnection cannot be resolved to a variable at com.roytuts.classexception.NoClassDefinitionFoundExceptionTest.main(NoClassDefinitionFoundExceptionTest.java.11