Java Tutorial

What is Java

Control Statements

Java Object Class

Java Inheritance

Java Polymorphism

Java Abstraction

Java Encapsulation

Java Array

Java OOPs Misc

How to set path in Java

The path is required to be set for using tools such as javac, java etc.
If you are saving the java source file inside the jdk/bin directory, path is not required to be set because all the tools will be available in the current directory.
But If you are having your java file outside the jdk/bin folder, it is necessary to set path of JDK.

    There are 2 ways to set java path:

  1. Temporary
  2. permanent

1) How to set Temporary Path of JDK in Windows

To set the temporary path of JDK, you need to follow following steps:

  1. Open command prompt
  2. copy the path of jdk/bin directory
  3. write in command prompt: set path=copied_path

For Example:

set path=C:\Program Files\Java\jdk1.8.0_171\bin

Let's see it in the figure given below:

>2) How to set Permanent Path of JDK in Windows

For setting the permanent path of JDK, you need to follow these steps:

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

What happens at compile time?

At compile time, java file is compiled by Java Compiler (It does not interact with OS) and converts the java code into bytecode.

What happens at runtime?

At runtime, following steps are performed:

Classloader: is the subsystem of JVM that is used to load class files.

Bytecode Verifier: checks the code fragments for illegal code that can violate access right to objects.

Interpreter: read bytecode stream then execute the instructions.

  1. Q) Can you save a java source file by other name than the class name?
  2. Yes, if the class is not public. It is explained in the figure given below:

    To Compile: Javac

    To Execute: Java Simple

  3. Q)Can you have multiple classes in a java source file?
  4. Yes, like the figure given below illustrates:

Copyright 2017 Design& development