Introduction to Java Programming Basics
Introduction to Java Programming Basics
Objectives
Introduction to Java
Collections
Programming Language
Java Sir, if there are
many
programming
languages, why
learn only Java?
Programming Language
Because Java is
highly secured,
Java
object oriented and
most widely used
language in the
Industry.
Programming Language
But where
Java do we use
it? Why
should I
learn Java?
Programming Language
Java
My teacher started
programming
languages today. He
started with Java and
said it’s very useful
and important. I am
not able to
understand why?
Well.. He is
right. Java is
very important.
It’s used
everywhere.
Look there. Do
you see the
set-top box
near the TV? It
works on
Java..
The billing
machine
also works on
Java.
Look John. I
have bought
you a gift.
Wow! An
android
phone!!
Thank you
Object-Oriented
.
Object-Oriented
Object-Oriented
.
Concurrent Class-based
Low
Object-Oriented
Dependencies
[Link]
February 1997 May 2000 September 2004 July 2011 Sep 2017
January 1996 December 1998 February 2002 December 2006 March 2014
{OOPS
}
Simple Portable Object-oriented Secure
Simple
Portable
Object-oriented
Secure Java was designed to be easy for professional
Distributed programmer to learn and use effectively
Dynamic Simple
Robust
High
Performan
ce
Simple
Portable
Object-oriented Applications written using Java are portable
Secure in the sense that they can be executed on
Distribute any kind of computer containing any CPU or
Robust
High
Performan
ce
Simple
Portable
Robust
High
Perform
ance Copyright © 2020, Dursikshya and/or its affiliates. All rights reserved.
Features of Java
Simple
Portable
Robust
High
Performan
ce
Simple
Portable
Robust
High
Performance
Simple
Portable
High
Performance
Simple
Portable
Java checks the code during the compilation
Object-oriented
time and run time also
Secure
Java completely takes care of memory
Distributed
allocation and releasing, which makes the
Robust
Dynamic
Java program more robust
Robust
High
Performance
Simple
Portable
Object-oriented
Java achieves high performance through the
Secure
use of bytecode which can be easily
Distributed
translated into native machine code
High Performance
Dynami
Robust
High
Performanc
e Copyright © 2020, Dursikshya and/or its affiliates. All rights reserved.
C++: Platform Dependent
Window
s
Ma
c
Solution: Bytecode is an intermediate code which gets generated when a Java file is compiled using a Javac
compiler. After compilation .class file is generated which contains the byte code. This code is platform
independent.
Solution: When many tasks/threads run at the same time, performance of the system increases.
JR
JDK
E
Copyright © 2020, Dursikshya and/or its affiliates. All rights reserved.
Java Memory Management
C/C++ has pointers. User can allocate memory to
these pointers
The
Garbage
Collector
looks for© 2020, Dursikshya and/or its affiliates. All rights reserved.
Copyright
Heap and Garbage Collector
The memory area in JVM
where objects are created
is called Heap
Java C Compiler
Java Source Java Bytecode
(.java)
JVM
Java
Java is easy Interpret
er
JIT
Compiler
Object Code
Runtime System
Operating System
Hardware
% Modulus
Q
In Class Question
1. Why do you think we need byte, short and long datatypes when int can be used?
Solution: ‘byte’ takes 1 byte, ‘short’ takes 2 bytes and ‘int’ takes 4 bytes in memory. If we know that the variable
need not be very big then ‘short’ is fine as it reduces the memory consumption which in turn increases the
performance of the project.
[Link]
[Link]
class FirstProgram
{
public static void main
(String[] args)
{
[Link]
n ("Hello
World");
}
}
Copyright © 2020, Dursikshya and/or its affiliates. All rights reserved.
Execute java Program
Short-cut ctrl + F11
Switch..
If.. else break continue
Case
Selection
Statements Syntax:
If it is raining
if (condition):
Iteration TRUE
Statements statements 1 …
else: Take an Umbrella
Jump statements 2 … FALSE
Statements
Go Play Football
Selection
Statements
Syntax:
EXECUTE BLOCK
do
Iteration
Statements {
repeat
statements…
Jump } while (condition is True) CHECK FALSE
Statements CONDITION
TRUE
EXIT LOOP
STAR
T
Selection
Statements
Syntax: FALSE
CHECK
while (condition is True) CONDITIO
Iteration
N
Statements {
statements… TRUE
repeat
Jump EXIT
} LOO
Statements P
EXECUTE BLOCK
Jump }
Statements repeat Execute Statements
Iteration
This is annoying. I
need to take 100
printouts in 10 mins
and I have to wait to
press the button
everytime it prints.
This is annoying. I
need to take 100
printouts in 10 mins
and I have to wait to
press the button
everytime it prints.
Selection
Statements
Synta FALSE
x: brea Check Loop
Iteration k;
Condition
Statements
TRUE EXIT LOOP
repeat
Jump TRUE
Check Break
Statements Condition
Execute Block
Selection
Statements
FALSE
Syntax: Check Loop
Condition
Iteration continue;
TRUE
Statements EXIT LOOP
repeat Execute Block 1
Jump
Check
Statements Continue
Conditio
TRU
n
E
FALSE
Execute Block 2
Write program to perform all the arithmetic operations given in the table
Arithmetic Operators
+ Addition
- Subtraction
* Multiplication
/ Division
++ Increment operator
-- Decrement operator