How to set path in Java?

We need to set jdk bin path to complie and java source code.

if Java source file is inside the JDK/bin directory, then you don't need to set path of java because all the tools will be available in the current directory.

if your Java file is outside the JDK/bin folder, it is necessary to set the path of JDK.

You can set the path in Java by two ways as below.

  • Temporary
  • Permanent

1) How to set the Temporary Path of JDK in Windows?

  •  Open the command prompt
  • Copy the path of the JDK/bin directory
  • Write in command prompt: set path=jdk_bin_path
    Example,
     set path=C:\Program Files\Java\jdk-19\bin

Look at below screeshots.

set the Temporary Path of JDK in Windows

 

2) How to set the Permanent Path of JDK in Windows?

 Go to MyComputer properties -> advanced tab -> environment variables -> new tab of user variable -> write path in variable name -> write path of bin folder in variable value -> ok -> ok -> ok

Look at below screenshots,

Set Permanent Path of JDK in Windows

How to set Java Path in Linux OS ?

you can use below command in linux to set java path in linux OS.

export PATH=$PATH:/home/jdk-19/bin/

 

Comments

Leave a Reply

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

21336