Created
October 20, 2017 14:24
-
-
Save javamultiplex/d3bbbd0d77964407056aca980be42e2e to your computer and use it in GitHub Desktop.
Example of ClassNotFoundException present in java.lang package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javamultiplex.java.lang.exceptions; | |
/** | |
* @author Rohit Agarwal | |
* @version 1.0 | |
* @category java.lang/Exception | |
* @since JDK 1.0 | |
*/ | |
public class ClassNotFoundExceptionDemo { | |
public static void main(String[] args) { | |
try { | |
/* | |
* ClassNotFoundException will be thrown because OracleJdbcDriver | |
* class is not present in classpath. | |
*/ | |
// Method 1 | |
Class.forName("oracle.jdbc.OracleJdbcDriver"); | |
// Method 2 | |
ClassLoader classLoader = ClassLoader.getSystemClassLoader(); | |
classLoader.loadClass("oracle.jdbc.OracleJdbcDriver"); | |
} catch (ClassNotFoundException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment