Today I am providing you all quick crash course on how to compile and execute java codes using CMD but the there is a small catch :P the java codes are stored in packages ;)
So, i have created 3 packages A,B,C
A contains a.java class [this is the entry point i.e. a.java contains public static void main(String ap[]) method]
B contains b.java class
C contains c.java class
Lets begin, below are the steps accompanied by screenshots to make it easy to understand and implement
Steps are as follows:
1. Create three folders at your desired location the folders are: A,B, and C
P.S. : I have created these folders on my Desktop :)
2. Open your notepad and create a.java below is the screenshot of a.java
and save this a.java in A folder
NOTE: import B.b links the b class stored in B package
3. Open Notepad and create b.java file, below is the screenshot of the code
and save this b.java in B folder
NOTE: import C.c links the c class stored in C package
4. Open Notepad and create c.java file, below is the screenshot of the code
and save this c.java in C folder
5. Now comes compilation, We have to be careful in this step. We can not directly compile in any order.
We have to follow the order, for example in this case where I have A,B, and C package i will compile that java file which is not dependent on any package i.e. which do not import any class which we have created. In this case c class should be compiled first and then b class should be compiled then a class.
If you do not follow this series then you will encounter errors during javac command :(
Below is the screen shot of the cmd during compiling and executing the code
NOTE: use / for packages
6. Give a smile :) you have successfully compiled and executed java files using packages in CMD :) :)
NOTE: this style can be used in Mac and Linux also :) so enjoy
Thats it for this post
Take Care
Peace
For Any Query mail me: ravjot.singh.28@gmail.com
No comments:
Post a Comment