Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Friday 18 November 2016

Java Path


The path is required to be set for using tools such as javac(for compiling java), java(for running java), javap, javah, jar, appletviewer, which are used in java programming language. Path is used to define where the system can find the executable(.exe) files e.g java.exe, javac.exe, It is a location of bin files(binary executable files). javac, java, javap, all these tools are available in bin folder so we set path upto bin folder.


There are 2 ways to set path in java:

  1. Temporary path.
  2. Permanent path.

(1)  How to set temporary path of JDK in windows

  • copy the path of jdk/bin directory after installing jdk e.g (C:Program Files\Java \jdk1.8.0_20\bin)
  • open command prompt 
  • and write command on command prompt set path=paste the path.
For example:

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


We can see in figure below:


Temporary path in java

(2) How to set permanent path of JDK in windows


Go to MyComputer icon and right click go to properties ->advanced system settings->environment variables->new tab on user variables->write path in variable name box->paste path of bin folder in variable value->ok->ok.


Setting permanent path in java
Permanent Path: (1)  Go to My Computer Properties

Setting permanent path in java
Permanent Path: (2) Go to Advanced system settings

Setting permanent path in java
Permanent Path: (3) Go to environment variables


Setting permanent path in java
Permanent Path: (4) click new button (User variables box)


Setting permanent path in java
Permanent Path: (5)  Type "path" word in variable name box and paste the path of bin folder in variable value box 
(6) Ok
(7) Ok



Java Source File declaration rules

A java file is a plain text file containing java source code and having '.java' extension. The '.java' extension means that the file is java source file. These java source file contains source code for class, interface, annotation, enumeration.

There are some rules associated with java source file
  • There can be only one public class per java source code file.
  • If there is a public class in java source file, the name of the file must match the name of the public class e.g public class First {   } must be in source code file name First.java, you can't try other name like one.java, this is wrong source file name if class is declared as public .
  • If the class is a part of package, the 'package' statement must be the first line in source code file, before any import statements that may be present.
  • If there are 'import' statements, they must go between the 'package' statements and class declaration. If there is not package statements, then the 'import' statement must be the first line in the source code file. If there are no 'package and import' statements in java source file then class must be the first line .
  • A file can have more than one non public class.
  • Files with non public classes can have a name that does not match any of the classes in the file.


src.zip file in java

src.zip file means java source file and these src(source) file contains all the '.java' files. you can extract src.zip file, If you want to see all '.java files or java source files'.
  • Go to C:\Program Files\Java\jdk1.8.0_20
  • Extract src.zip file

Share:

0 comments:

Post a Comment

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate