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

Java

1
Agenda
 Introduction to Java
 Features of Java
 Java Development Kit
 Variables and Data Types in Java
 Operators in Java
 Decision-Making Statements
 Object Oriented Concepts in Java
Introduction to Java
What is Java?
Java was created by James Gosling in 1995 for Sun Microsystems
Java is a platform independent programming language that follows the
logic of Write once , Run anywhere”.
Features of Java Compiled &
Interepreted
Independent &
Scalability & Portable
Performance

Object –
Ease of Oriented
Development

Java
Dynamic & Robust & secure
Extensible

High Distributed
Performance

Multithreaded Simple
Java Development Kit
Fundamentals of Java
Variables

Keywords DataTypes

Basic
Fundamentals

Operators Identifiers

Literals
Keywords
• Keywords are the reserved words which are having predefined meaning in Java.
• All the keywords are defined in lower case and the meaning of these keywords can’t be modified.
• We cannot use keywords as names for variables, classes, methods, or as any other identifiers.
• const & goto are the keywords but no implementation available in Java. You cannot use in Java.
Identifiers
• By the name, it is clear that identifiers are used for identification purpose.
• Identifiers can be a class name, method name, variable name, or a label name. 

Rules for defining identifiers:


• Identifier can contain alphabets [A-Z] & [a-z], Digits [0-9], underscore(_) and dollar($).
• The first letter must be an alphabet, digit, underscore or dollar sign.
• Space is not allowed in between the identifier name.
• Keywords cannot be used as identifiers. For example:
 Valid Identifiers:  ch, _integer, del123, deal_var, etc.
Invalid Identifiers: 12ch, @charm, My var, a+6, while, int, true, etc.
Data Type
 Data Types
 Data types represent the type of data you want to use and memory required for that data.
There are two types of data:
• Primitive Data Type int
• Non-Primitive Data Type Character char
byte
Integer
Numeric
short

Primitive Integral long

Boolean boolean float


Float
double
Data Type
String

Non-
Array
Primitive

Class
Data Types Default Values Range Default Size Example

boolean False True/false N/D boolean b = true;

char 0 or \u0000 0   to   65535 (2^16-1) 2byte char c=’A’


\u0000 to \uffff
byte 0 -128(-2^7) to 127 (2^7 1 byte byte b=12
-1)
Short 0 -32,768 (-2^15)  to 2 byte short s=10
 32,767(2^15 -1)
Int 0 – 2,147,483,648 (- 2 byte int I=10
2^31)
 to2147483647(2^31 -
1)
long 0 -2^63   to   2^63-1 8 byte long l = 1000L

Float 0.0 1.4E-45   to   3.40E+38 4 byte float f = 25.9f

double 0.0 4.9E-324   to   8byte double d = 152.3


1.79E+308
Any null Reference of the 8byte String str=null
Reference corresponding type
type object
Variables
 Variable is nothing but the container which is use to hold or store data
 Variable names are constructed by using alphabets, numbers and using special symbols i.e dollar and underscore. 
  Variables hold only one value at time.
Memory cell

10

a – reference name given


to the memory cell
a = 10
Types of Variables
Local Variable
Instance Variable
Static or Class Variable
Operators
Arithmetic Operators
Relational Operators
Logical Operators
AssignmentOperators
Bitwise Operators
Arithmetic Operators
Operator Description Example

+ Addition Adds values on either side of the A+B=30


operator
Subtracts the right-hand operator
– Subtraction with left-hand operator A-B=-10
Multiplies values on either side of
* Multiplication the operator A*B=200
Divides left hand operand with
/ Division right hand operator A/B=0
Divides left hand operand by right
% Modulus hand operand and returns A%B=0
remainder
Relational Operators
Operator Description Example

If the values of two operands are equal, then


== (A == B) is not true
the condition becomes true.
If the values of two operands are not equal,
!= (A != B) is true
then condition becomes true.
If the value of the left operand is greater than
> the value of right operand, then condition  (a > b) is not true
becomes true.
If the value of the left operand is less than the
< value of right operand, then condition  (a < b) is true
becomes true.
If the value of the left operand is greater than
>= or equal to the value of the right operand,  (a >= b) is not true
then condition becomes true.
If the value of the left operand is less than or
<= equal to the value of right operand, then  (a <= b) is true
condition becomes true.
Logical Operator
Operator Description Example

&& (and) True if both the operands is true a<10 && a<20

|| (or) True if either of the operands is true a<10 || a<20


True if an operand is false (complements
! (not) !(x<10 && a<20)
the operand)
Assignment Operator
Operator Description Example

Assigns values from right side operands to left


= c = a + b 
side operand
It adds right operand to the left operand and
+= c += a
assigns the result to left operand
It subtracts right operand from the left operand
-= c -= a
and assigns the result to left operand
It multiplies right operand with the left operand
*= c *= a
and assigns the result to left operand
It divides left operand with the right operand
/= c /= a
and assigns the result to left operand
It takes modulus using two operands and
%= c %= a
assigns the result to left operand
Performs exponential (power) calculation on
^= c ^= a
operators and assign value to the left operand
Bitwise Operator
Operator Description Example

& (AND) returns bit by bit AND of input a&b

| (OR) returns OR of input values a|b

^ (XOR) returns XOR of input values a^b


returns the one’s complement. (all bits
~ (Complement) ~a
reversed)
Decision-Making Statement
• Simple if statement
• if-else statement
• Nested if statement
• Switch statement
• Looping statements
• While
• Do-while
• For
• For-Each
• Branching statements
• Break
• Continue
OOPs Concepts in Java
What is Object Oriented Programming?
OOPs in java is to improve code readability and reusability by defining a Java
program efficiently. 
The main principles of OOPs are

Abstraction
Encapsulation
Inheritance
Polymorphism

23
Structure of
• Classes are user-defined data types that act as the blueprint for individual objects,
attributes and methods.
• Objects are instances of a class created with specifically defined data. Objects can
correspond to real-world objects or an abstract entity. When class is defined initially, the
description is the only object that is defined.
• Methods are functions that are defined inside a class that describe the behaviors of an
object.

24

You might also like