Javac/Java searching algorithm for other classes


With this post, I would like to explain how exactly the Java/Java will search for its dependencies in the project or application level. Java Applications can be run using the command line or in the Web/Application servers. For both the scenarios will be covered as below:

When you are accessing standalone application using command prompt, below will be the search criteria steps:

Step 1: The first place that look in the directories that contains the classes that come with Java SE.

Step 2: The classpath that declared as command line options for either Java/Javac. Since the classpath declared in command line options override the classpath declared in command line options persists only for the length of the invocation.

Step 3: Looks for the the default classpath that declared as System Environment Variables.

When you are accessing the application from Web or application servers, below will be the search criteria steps:

Step 1: The first place that look in the directories that contains the classes that come with Java SE.

Step 2: If the dependencies not able to identify in the JRE lib folder, then it will be looked into the Application lib folder.

Step 3: If the dependencies not able to fine in above two steps, then it will be looked into Web/App server lib folder.

 

Other Useful Links:

Differences between Object and Instance
Difference between Abstract Class and Interface:
Threads Interview questions in Java
Access Specifiers in Java
Avoid nested loops using Collection Framework in Java