Sunday, 7 August 2016

Compile java file

Date :25- july-2016
Mr. nagur babu


5.       Compile java file :
The main intention to perform compilation is,
1.       To check developers mistakes before execution program.
2.       To translate java code from high level representation to low level representation.
To perform compilation, we have to use the following commend on commend prompt
 javac File_Name.java
Ex:-
D:\java10>javac FirstApp.java
If we use the above commends  on commend prompt then operating system will perform the following actions
1.       Operating system will take “javac” commend from commend prompt.
2.       Operating system will search for “javac” commend in its internal commends list and at the locations referred by “path” environment variable.
3.       If “javac” is not available at the above specified location then operating system will provide the following messages  on commend prompt.

“javac”  is not recognized as an internal or external commend, operable program or batch file.
Note: -
To make available all JDK tools to the operating system, we have to set path environment variable to
“C:\java\jdk1.7.0\bin”.
D :\java10>set path:C:\java\jdk1.7.0\bin;

4.       When operating system identities “javac” command at “C:\java\jdk1.7.0\bi n” through “path” environment variable, operating system will execute “javac” commend, with this java compiler software will be activated and java complier will perform the following actions.

a.        Compiler will take the provided java file name from command prompts.
b.      Compiler will search for the specified java file  at current location
c.       If the specified java file is not available current location then compiler will provide the following message on commend prompt.
Javac: file not found :FirstApp.java
d.      If the provide java file is available at current location then “compiler” will perform compilation right. From starting point of the file to ending point of the files.
e.      While performing compilation, if any error is identifies then compiler will display the respective error message on command prompt.
f.        If no error is identified in the java file then compiler will generate .class files.
Note :-
Generating number of  .class file is not at all depending on the number of java file which we compiled, if is totally depending on the number of classes, number of abstract classes, number of interfaces, number of enums and number of inner classes which we provided in java file.
g.       If we want to compile java file current location and if we want to send the generated .class files to some other location then we have to use the following commend on commend prompt.

Javac –d target_location File_Name.java   
Ex:-
D:\java10>javac –d c:\abc FirstApp.java
Note:-
In real time application development, to ménage minimum the following folders in application folder.
1.       “src” folder:-
To store all java files in the form of packages.
2.       “classes” folder:-
To store all the general .class after compilation.
3.       “lib” folder:-
To manage all the third party libraries, which are required in present java application (jar files).
In above situation, we  have to compile all java files from “src” folder and we have to send the generated .class files to “classes” folder, for this “we need ‘-d’ up to along with “javac” commend.

bankApp[application Folder]

D:\java10\bankapp\src\javac –d D:\java10\bankapp\classes Transaction.java

Date :26- july-2016
Mr. nagur babu
In java application, if we provide package declaration standard in a java file then compiles has to create folder structure with respect to the package name in order to store the generator .class files, to achieve this required, we have to use ‘-d’ option along with “javac” command.
Note :-
In java applications compilation, -d optional is able to make the compiler to send the generator .class files to the specified target location and to create folder stricter with respect to package name which we defined in java files.
Example:-
File name: D:\java10\FirstApp.java

package com.jntusuperfastupdates.core;
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");
                }
}
D:\java10>javac –d C:\abc FirstApp.java  


If we want to compile all java files which are available at the current location. Then we have to use the following commend.
D:\java10>javac *.java
If we want to compile all java files which are having a common prefix then we have to use the following commend.
>>javac Prefix_Name*.java
D:\java10>javac Employee*.java
If we want to compile all java file which are having a common postfix then, we have to use the following command
>>javac *Postfix_Name.java
Ex:-
D:\java10>javac *Names.java
If we want to compile all java files which are having a common name then we have to use the following commend.
>>javac *common_Name*.java
Ex:-
D:\java10>javac *Account*.java
Ex:-
EmployeeAccount.java
AccountStudent.java
EmployeeAccountStudent.java



No comments:

Post a Comment