0% found this document useful (0 votes)
23 views22 pages

1.introduction To JAVA

Uploaded by

tazeenurrehman19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views22 pages

1.introduction To JAVA

Uploaded by

tazeenurrehman19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Introduction to JAVA

Why JAVA?
• Write Once Run Anywhere
• One of the most popular programming language in the world
• Easy to learn and simple to use
• Open-source and free
• A huge community support (tens of millions of developers)
• An object-oriented language which gives a clear structure to programs
and allows code to be reused, lowering development costs
• Java is close to C++ and C#, it makes it easy for programmers to switch
to Java or vice versa
How JAVA is Platform
Independent
• Whenever, a program is written in
JAVA, the javac compiles it.
• The result of the JAVA compiler is
the .class file or the bytecode
• The bytecode generated is a non-
executable code and needs an
interpreter to execute on a machine.
• This interpreter is the JVM and thus
the Bytecode is executed by the JVM.
• And finally, program runs to give the
desired output.
Java Software Development Tool
Getting Started

• Download Eclipse
https://www.eclipse.org/downloads/
• Install, Choose development kit for JAVA developers
• Eclipse 2022 will automatically install JRE / JVM
Creating New JAVA Project in
Eclipse
Creating New JAVA Project in
Eclipse
Creating New JAVA Project in
Eclipse
Adding Class to the Project
Adding Class to the Project
Hello World in JAVA
• In Java, every application begins with a class name, and that class
must match the filename.

public class Test {


public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World");
}
}
• Every line of code that runs in Java must be inside a class
JAVA Output
Example
• Java System Library
provides two display
functions
• print
• println
Example
JAVA Comments
• Single Line // This is a single line comment
• Multi Line /* This is a Multi
line comment */
JAVA Variables
• Variable Declaration Example
type variableName = value;

• Data types in JAVA includes Primitive


(int, char, float, double, byte, short,
long, boolean) and non-Primitive
(String, Arrays, … etc.)
Exercises
• Create a variable named carName and assign the value Volvo to it.
• Create a variable named maxSpeed and assign the value 120 to it.
• Display the sum of 5 + 10, using two variables: x and y.
• Create a variable called z, assign x + y to it, and display the result.
• Fill in the missing parts to create three variables of the same type,
using a comma-separated list:
Variable Naming Conventions
• Names can contain letters, digits, underscores, and dollar signs
• Names must begin with a letter
• Names should start with a lowercase letter and it cannot contain
whitespace
• Names can also begin with $ and _
• Names are case sensitive ("myVar" and "myvar" are different
variables)
• Reserved words (like Java keywords, such as int or boolean)
cannot be used as names
Type Casting
• Widening
Casting (automatically) - Example
converting a smaller type to a
larger type size
byte -> short -> char -
> int -> long -> float -
> double

• Narrowing Casting (manually) - Example


converting a larger type to a
smaller size type
double -> float -> long -
> int -> char -> short -
> byte
If else in JAVA
switch case in JAVA
Exercise
Iterations in JAVA

while Loop

for Loop
Arrays
• Array declaration
type [] arr_name;

• Memory Initialization
arr_name=new type[size];

• Assigning Values
arr_name[0]=dataValue;
arr_name[1]=dataValue1;
E
X
A
M
P
L
E

You might also like