JAVA PROGRAMMING LANGUAGE

                                        Java



 01. Download JDK setup and then install it. This is the link>>>>https://www.oracle.com/java/technologies/javase-jdk13-downloads.html 
It will be in the C:/Progarmming files/Java

Then open cmd and type java(space)-version. It should be appear as follows.


If this isn't appear on the screen, Go to Control Panel and search for Environment Variables. And following screen will appear on the desktop.
Now in my prompt there is no variable called, Path. So, first of all I have to create a variable called Path. In order to do that, click on the New button and it'll appear as follows.
That prompt is asking for Variable name and Variable value. Type Path for the Variable name. In order to give the variable value, click Browse Directory and follow this path. 
C:>Program Files>Java>jdk-13.0.2>bin
Select the bin folder in  jdk folder.
Then click the Okay button. And it'll appear in the Environment variable prompt. If you already have a Path variable and if it doesn't have above address, then click Edit and change it as above. Then close the current Command Prompt and open a new command prompt and type path then it'll appear as below.
If selected line appeared in your prompt, you're ready to go for further steps.

02. Open notepad and type following lines.


public class MyClass{
public static void main (String args[]) {
(press Tab button once)System.out.println("Creative Programming");
}}

 IMPORTANT
  • Java is a case sensitive language(That means it recognizes Simple and Capital letters. So, when you are typing a code, be aware regarding capital and simple letters.)
  • Every statement should end with semicolon(;)
  • Class should open with a curly brackets({) and close with curly brackets(}).
Go to File>Save as and save the source file using the Class name(Compulsory). Add the extension .java . According to my example, it's as follows.



03. Compile the source file into Class file
 In this procedure, we are using javac tool. First of all open cmd and go to the folder you've stored the MyClass.java . In order to go this we have to learn 2 small functions using in cmd.
           
     a) cd(space)..  (Go back 1 step from currrent directory.)
According to this I'm now in Local Disk (C)>Users folder>Acer folder. But my saved text file is in,
Local Disk (C)>Users folder>Acer folder>3D Objects . So I don't need to go back. 
(b)You can see the path in the above picture.So, i have to go into the 3D Objects folder. In order to do that I have to type cd(space)3D Objects.
In this you can see I didn't use any capital letters to type 3D Objects. It's because cmd is not case sensitive. Now I have to compile .java file. So, I have to type javac(space)MyClass.java and press Enter. It'll as below.

 When it's compiled successfully it displays as a CLASS file(Byte Code) in the same folder/directory.
Though the extension of this file is .class, you don't need to type it when executing.

04. Executing/Run the Class file
We are using java tool from bin folder in JDK. This acts as the JVM(interpreter). Interpreters convert Byte codes in to Machine codes step by step while executing. This process is called as Interpretation.

Type java(space)MyClass and press Enter. Don't use .class extension as this is a Java program.
As you can see "Creative Programming" is being displayed.

Comments

Popular posts from this blog

EXPLAINED ANSWERS FOR IP MID-TERM MODEL QUESTIONS

FEDORA 31 BASIC