2.1 Java Installation

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 38

Being Familiar with

Java

By Upekha Vandebona
Alternative OO Programming
Languages
Using Java
Lightweight IDEs
online/offline

Command Prompt
&
Notepad

Workbench
IDEs
Download & Install Java JDK
If you cannot see the version, the reason is PATH
not set.
If you use an installer to install java, it will
automatically set the path environment variable.
Installer will automatically
set this path for Java in
environment variables.
Setting the path of Java in the
computer temporarily

In Command Prompt, type


the above
Setting the path of
Java in the
computer
Permanently
D:\Program Files\Java\jdk-21\
bin
The Way Java Works

The compiled bytecode is platform-independent.


You’ll type a source code file, compile it using the javac compiler, and then run the compiled
bytecode on a Java virtual machine.
Code Structure in Java
Anatomy of a Class

When the JVM starts running, it looks for the class you give
it at the command line.
Then it starts looking for a specially-written method that
looks exactly like:

Next, the JVM runs everything between the curly braces {} of your main
method.
“Hello World” Driver
Program

public class MyFirstApp{


public static void main(String
args[]){
System.out.println("Hello
World.");
}
}
Running a program means telling the Java virtual Machine
(JVM) to “Load the class, then start executing its main ()
method. Keep running till all the code in main is finished."
How to change directory in
command prompt

Working Directory: All the


created source codes saved in
this folder
‘Path’ Environment Variable
If you do not like to PATH variable
set, then you need to specify the full
path to the executable file every
time you run it in the command
prompt , such as:
C:\> "C:\Program Files\Java\jdk-21\bin\javac" MyClass.java
Save, Compile & Run

1.Save
• MyFirstApp.java

2.Compile
• javac MyFirstApp.java

3.Run
• Java MyFirstApp
Main Method
Once you're inside main method,
you can say all the normal things
that you say in most programming
languages to make the computer to
do something.
do something again and again
do something under a condition
Java -Few Basic Rules
 Each statement must end in a semicolon.
 x = x + 1;
 Most white space doesn't matter.
 x = 3 ;
 Classes and methods must be defined within a pair of
curly braces.
 public void go() {
// amazing code here
}
 Filename should be exactly same as the class name
which main method reside.
 Java is case-sensitive.
‘println’Vs ‘print’

public class Main{


public static void main(String
args[]){
System.out.print (“1,”);
System.out.print (“2,”);
System.out.println (“3,”);
System.out.println (“4,”);
System.out.println (“5,”);
}
}
Exercises

Hello!
Good Morning!

Thank You! You’re Welcome

The Answer of 5+5 is :


10
Few Useful DOS Commands

Clear the Screen

n A rro w
se U p / D ow
U u se
t h e re Make new directory/folder
keys m a n d s
v i o u s c om
pre
sily
Few Useful DOS Commands

List Items in current


Go back one folder
folder
Comments
 The contents of a comment are
ignored by the compiler.
 A comment describes or explains the
operation of the program to anyone
who is reading its source code.
 comments generally explain how some
part of the program works or what a
specific feature does.
Comments
A single-line comment begins with two forward
slashes.
 //This is a single line comment
 Documentation comment can span across
multiple lines
 /** The HelloWorldApp class implements an
application that * simply prints "Hello World!" to
standard output. */
 Multiline comments span across multiple lines
 /*This is a
Multiline Comment*/
Documentation comment
This type of comment is used to
produce an HTML file that
documents your program.
Select from among the following valid option(s)
that can be used to execute the Java
program.

(a) java Ex1.java (b) java Ex1 (c)


class
(d) javajava (e) Ex1.txt.java
3) Select from among the following, what JDK
stands for.

(a) Java Design Kit (b) Java Data Kit


(c) Java Definition Kit (d) Java Development
Kit
(e) Java Deployment Kit
Select from among the following, valid output
generated after a Java source file is successfully
compiled.

(a) Object Code (b) Byte Code


(c) P Code (d) Java
Compiler
(e) Java Interpreter
Thank You!

You might also like