Saturday, December 24, 2016

How to Install JAVA part-3

5. Compile JAVA file:

--------------------------------------------------------------------------------------------------------------------
The main Intention to compile JAVA files is:

A. To translate JAVA code from high level representation to low level representation.
B. To check developers mistake in JAVA application

To compile JAVA files, we have to use the following command on command prompt:

Javac File_Name.java

EX: D:\java10>javac FirstApp.java
---------------------------------------------

C. If we provide the above command on command prompt then operating system will perform the following actions:
i. Operating System will take “javac” command prompt
ii. Operating System will search for javac command at its predefined command list and at  the location refereed by “path” environment variable.
iii. If “javac” is not identified at both the location then operating system will display the following message.
iv. ‘javac’ is not recognized as an internal or external command, operable program or batch file.

Note: To give all java commands location information to the operating system, we have to set “path” environment variable to “C:\java\jdk1.7.0_79\bin;
On command Prompt:

D:\Java10>set path=C:\java\jdk1.7.0_79\bin;

D. If javac is identified by the operating system at either of the above location then operating system will execute “javac” command, with this, JAVA compiler software will be activated and JAVA compiler will perform the following actions.
 I.     Compiler will take the provided JAVA file from command prompt.
II.     Compiler will check whether the specified JAVA file is existed or not at current location
III.    If the specified JAVA file is not existed then compiler will provide the following message :   

         javac: file not Found: FirstApp.java
run java through command prompt
File not found in JAVA


IV.     If the specified in the JAVA file then the compiler will display error message on command  prompt.
V.     If no error is identified in the present JAVA file then the compiler will generate .class files.

Note: Generating Number of .class files is not at all depending on the no. of .java files which we compiled, it is completely depending on the no. of classes, abstract classes, interfaces, enums and inner classes which we used In present JAVA file.

If we want to compile JAVA file from current location & if we want to select generated .class file to a particular target file then we have to use ‘-d’ option.
EX: D:\java10\javac –d C:\abc FirstApp.java

If we want to compile JAVA file from current location and if we want to generate .class files by creating folder, structure with respect to the package name then we have to use ‘-d’ option along with “javac” command.

EX: File Name: D:\java10\FirstApp.java
enum E
{          
}
interface I
{
}
abstract class A{
           
}
class B {
            class C{
                       
            }
}
class FirstApp {
            public static void main(String[] args){
                        System.out.println("First JAVA Application");
            }
}

On command Prompt:
D:\java10>javac –d C:\abc FirstApp.java
compilation process of a java file
Compilation Format of JAVA File


If we want to compile all JAVA files which are existed at current location then we have to use the following command on command Prompt.
 D:\java10>javac *.java

If we want to compile all JAVA files which started with a common prefix then we have to use the following command on command prompt:
D:\java10>javac student*.java

If we want to compile all JAVA files which are having a common postfix then we have to use the following command on command prompt:
D:\java10>javac *Emails.java

If we want to compile all java files which contains a common word then we have to use the following command on command prompt:

D:\java10>javac *Account*.java

No comments:

Post a Comment