coderz.py

Keep Coding Keep Cheering!

Setting CLASSPATH in Java

method overloading and method overriding

In Java, you can set the CLASSPATH variable.

CLASSPATH:

Application ClassLoader uses CLASSPATH as an environment variable to locate and load .class files. The CLASSPATH specifies the location of third-party and user-defined classes that are not extensions or components of the Java platform. When setting the CLASSPATH, make sure to include all directories that contain .class files and JAR files.

If the following conditions apply, you must set the CLASSPATH:

  • You must load a class that isn’t in the current directory or any of its subdirectories.
  • You need to load a class that isn’t in the extensions mechanism’s specified location.

A dot is the default value for CLASSPATH (.). It refers to the only directory that is currently being searched. When you set the CLASSPATH variable or use the -classpath command, the default value of CLASSPATH takes precedence (for short -cp). If you want to include the current directory in the search path, add a dot (.) to the new setting.

There are two ways to ways to set CLASSPATH: through Command Prompt or by setting Environment Variable.

Let’s see how to set CLASSPATH of MySQL database:

Step 1: Click on the Windows button and choose Control Panel. Select System.

How to Set CLASSPATH in Java

Step 2: Click on Advanced System Settings.

How to Set CLASSPATH in Java

Step 3: A dialog box will open. Click on Environment Variables.

How to Set CLASSPATH in Java

Step 4: If the CLASSPATH already exists in System Variables, click on the Edit button then put a semicolon (;) at the end. Paste the Path of MySQL-Connector Java.jar file.

If the CLASSPATH doesn’t exist in System Variables, then click on the New button and type Variable name as CLASSPATH and Variable value as C:\Program Files\Java\jre1.8\MySQL-Connector Java.jar;.;

Remember: Put ;.; at the end of the CLASSPATH.

How to Set CLASSPATH in Java

How to Set CLASSPATH in Windows Using Command Prompt

Type the following command in your Command Prompt and press enter

set CLASSPATH=%CLASSPATH%;C:\Program Files\Java\jre1.8\rt.jar;

The set command is an internal DOS command that allows the user to change the variable value in the above command. CLASSPATH is the name of a variable. The variable enclosed in the percent sign (%) is already present in the environment. The semicolon is a separator, and the PATH to the rt.jar file is after the (;).

Note: also read about the What is Java programming language

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Leave a Comment

Your email address will not be published. Required fields are marked *

Advertisement