SlideShare a Scribd company logo
Java Language and OOP
Part I
By Hari Christian
Agenda
• 01 Java Keyword
• 02 Primitive Data Type
• 03 Wrapper Class
• 04 Variabel or Identifier
• 05 Expression Statement
• 06 Comment in Java
• 07 Comment Single Line
• 08 Comment Multiple Line
• 09 Casting
• 10 Overflow
Keywords
• Keywords are reserved words, which means
they cannot be used as identifiers. Java now has
50 keywords ("enum" became a keyword in JDK
1.5)
Keywords
• abstract continue for new switch
• assert default goto package synchronized
• boolean do if private this
• break double implements protected throw
• byte else import public throws
Keywords
• case enum instanceof return transient
• catch extends int short try
• char final interface static void
• class finally long strictfp volatile
• const float native super while
Primitive Data Type
• There are eight built-in, non-object types in
Java, known as primitive types. Every piece of
data in a class is ultimately represented in terms
of these primitive types. The eight primitive types
are:
– boolean (for true/false values)
– char (for character data, ultimately to be input or
printed)
– int, long, byte, short (for arithmetic on whole numbers)
– double, float (for arithmetic on the real numbers)
Primitive Data Type - Literal
• As we mention each of the eight primitive types,
we'll show a typical declaration; say what range
of values it can hold; and also describe the literal
values for the type.
• A "literal" is a value provided at compile time.
Just write down the value that you mean, and
that's the literal.
Primitive Data Type - Literal
• Example:
int i = 2; // 2 is a literal
double d = 3.14; // 3.14 is a literal
if ( c == 'j' ) // 'j' is a literal
Primitive Data Type - Literal
• Every literal has a type, just like every variable
has a type.
• The literal written as 2 has type int.
• The literal written as 3.14 belongs to the type
double.
• For booleans, the literals are the words false
and true.
Primitive Data Type - Literal
• It is not valid to directly assign a literal of one
type to a variable of another. In other words, this
code is invalid:
int i = 3.14; // type mismatch! BAD CODE
Primitive Data Type – The Eigth
Data Type Size Min Max
byte 8 bit -128 127
short 16 bit -32.768 32.767
int 32 bit -2.147.483.648 2.147.483.647
long 64 bit -9.223.372.036.854.775.808 9.223.372.036.854.775.807
float 32 bit -3.4E38 3.4E38
double 64 bit -1.7E308 1.7E308
boolean - - -
char 16 bit 'u0000' atau 0 'uffff‘ atau 65535
Primitive Data Type - byte
• Example declaration:
byte aByte;
• Range of values: –128 to 127
• Literals: There are no byte literals. You can use,
without a cast, int literals provided their values fit
in 8 bits. You can use char, long, and floating-
point literals if you cast them
Primitive Data Type - byte
• You always have to cast a (non-literal) value of a
larger type if you want to put it into a variable of
a smaller type
• Since arithmetic is always performed at least at
32-bit precision, this means that assignments to
a byte variable must always be cast into the
result if they involve any arithmetic, like this:
byte b1=1, b2=2;
byte b3 = b2 + b1; // NO! compilation error
byte b3 = (byte) (b2 + b1); // correct, uses a cast
Primitive Data Type - short
• Example declaration:
short aShort;
• Range of values: –32,768 to 32,767
• Literals: There are no short literals. You can use,
without a cast, int literals provided their values
will fit in 16 bits. You can use char, long, and
floating-point literals if you cast them
Primitive Data Type - int
• Example declaration:
int i;
• Range of values: –2,147,483,648 to 2,147,483,647
• Literals:
– A decimal literal, e.g., 10 or –256
– With a leading zero, meaning an octal literal, e.g.,
077777
– With a leading 0x, meaning a hexadecimal literal,
e.g., 0xA5 or 0Xa5
Primitive Data Type - long
• Example declaration:
long debt;
• Range of values: –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
• Literals: (always put L)
– A decimal literal, e.g., 2047L or –10L
– An octal literal, e.g., 0777777L
– A hexadecimal literal, e.g., 0xA5L or
OxABadBabbeL
Primitive Data Type - float
• Example declaration:
float total;
• Range of values: –3.4E38 to 3.4E38
• Literals: (always put f)
1e1f 2.f .3f 3.14f 6.02e+23f
Primitive Data Type - double
• Example declaration:
double salary;
• Range of values: –1.7E308 to +1.7E308
• Literals: (optionally put d)
1e1 2. .3 3.14 6.02e+23d
Primitive Data Type - boolean
• Example declaration:
boolean b;
• Range of values: false, true
• Literals: false true
Primitive Data Type - char
• Example declaration:
char grade;
• Range of values: a value in the Unicode code set 0 to 65,535
• Literals: Char literals are always between single
quotes. String literals are always between
double quotes, so you can tell apart a one-
character String from a char
Primitive Data Type - char
• Here are the four ways you can write a char literal:
– A single character in single quotes, char tShirtSize = 'L';
– A character escape sequence
– An octal escape sequence
– A Unicode escape sequence
Character Description
‘n’ Linefeed
‘r’ Carriage Return
‘’f’ Formfeed
‘b’ Backspace
Character Description
‘t’ Tab
‘’ Backslash
‘’”’ Double Quote
‘’’ Single Quote
Wrapper Class
• Each of the eight primitive types we have just
seen has a corresponding class type, predefined
in the Java library
• For example, there is a class java.lang.Integer
that corresponds to primitive type int
• These class types accompanying the primitive
types are known as object wrappers
Wrapper Class
• Wrapper Class serve several purposes:
– The class is a convenient place to store constants like
the biggest and smallest values the primitive type can
store
– The class also has methods that can convert both
ways between primitive values of each type and
printable Strings. Some wrapper classes have
additional utility methods
– Some data structure library classes only operate on
objects, not primitive variables. The object wrappers
provide a convenient way to convert a primitive into
the equivalent object, so it can be processed by these
data structure classes
Wrapper Class – The Eight
Primitive Type Wrapper Class
byte java.lang.Byte
short java.lang.Short
int java.lang.Integer
long java.lang.Long
float java.lang.Float
double java.lang.Double
boolean java.lang.Boolean
char java.lang.Character
Wrapper Class
• Example:
int i = 15;
Integer myInt = new Integer(i); //wrap an int in a object
// get the printable representation of an Integer
String s = myInt.toString();
// gets the Integer as a printable hex string
String s = myInt.toHexString(15); // s is now "f"
// reads a string, and gives you back an
int i = myInt.parseInt( "2047" );
// reads a string, and gives you back an Integer object
myInt = myInt.valueOf( "2047" );
Identifier
• Identifiers are the names provided by the
programmer, and can be ANY LENGTH in Java
• Identifiers must start with a LETTER,
UNDERSCORE, or DOLAR SIGN, and in
subsequent positions can also contain digits.
• Letter with unicode character also valid
Identifier
– calories
Legal Java identifiers
calories Häagen_Dazs déconnage
_99 Puñetas fottío
i $_ p
Identifier – Forward Reference
public class Identifier {
public int calculate() {
// not yet declared
print(“METHOD FORWARD REFERENCE”);
return total;
}
public void print(String aString) {
System.out.println(aString);
}
int total;
}
Expression Statement
• Example:
public static void main(String[] args) {
int a = b; // assignment
int number = 5; // assignment
w.setSize(200,100); // method invocation
new WarningWindow(f); // Instance creation
Person p = new Person(); // Instance creation
++i; // pre-increment
}
Expression Statement
• Example:
public static void main(String[] args) {
int i = 4;
int j = 6;
int x = i++ + ++i - --j + ++j + j++;
System.out.println(“x = “ + x);
System.out.println(“i = “ + i);
System.out.println(“j = “ + j);
}
Expression
Expression in Java
A literal 245
This object reference this
A field access now.hh
A method call now.fillTimes()
An object creation new Timestamp(12, 0, 0)
An array creation new int[27]
An array access myArray[i][j]
Any expression with operator now.mins / 60
Any Expression in parens (now.millisecs * 1000)
Comment in Java
• Comment is used to make a description of a
program
• Comment can be used to make a program
readable
• Comment is ignored by compiler
Comment Single Line
• Use double slash
• Example:
// This is a single line comment
Comment Multiple Line
• Use /* */
• Example:
/*
This is a multiple line comment
Use this if we want to make multiple line of comment
Just remember the format:
/* = to open the comment
*/ = to close the comment
*/
Comment Multiple Line
• Use /** */
• Example:
/**
This is a multiple line comment for Java Documentation
Use this if we want to make multiple line of comment
And also want to publish to Java Documentation
We can also use HTML tag like this <br/>
Just remember the format:
/** = to open the comment
*/ = to close the comment
*/
Casting
• When you assign an expression to a variable, a
conversion must be done.
• Conversions among the primitive types are
either identity, widening, or narrowing
conversions.
Casting - Identity
• Identity conversions are an assignment between
two identical types, like an int to int assignment.
• The conversion is trivial: just copy the bits
unchanged.
Casting - Identity
• Example:
int i = 5;
int j = i; // The result is ?
Casting - Widening
• Widening conversions occur when you assign
from a less capacious type (such as a short) to a
more capacious one (such as a long). You may
lose some digits of precision when you convert
either way between an integer type and a
floating point type. An example of this appeared
in the previous section with a long-to-float
assignment. Widening conversions preserve the
approximate magnitude of the result, even if it
cannot be represented exactly in the new type.
Casting - Widening
• Example:
int i = 5;
double d = i; // The result is ?
Casting - Narrowing
• Narrowing conversions are the remaining
conversions. These are assignments from one
type to a different type with a smaller range.
They may lose the magnitude information.
Magnitude means the largeness of a number, as
in the phrase "order of magnitude." So a
conversion from a long to a byte will lose
information about the millions and billions, but
will preserve the least significant digits.
Casting - Narrowing
• Example:
double d = 5.5;
int i = (int) d; // The result is ?
Overflow
• When a result is too big for the type intended to
hold it because of a cast, an implicit type
conversion, or the evaluation of an expression,
something has to give!
• What happens depends on whether the result
type is integer or floating point.
Overflow
• When an integer-valued expression is too big for
its type, only the low end (least significant) bits
get stored
• Because of the way two's-complement numbers
are stored, adding one to the highest positive
integer value gives a result of the highest
negative integer value. Watch out for this (it's
true for all languages that use standard
arithmetic, not just Java)
Overflow
• There is only one case in which integer
calculation ceases and overflow is reported to
the programmer: division by zero (using / or %)
will throw an exception
Overflow
• Example:
int min = Integer.MIN_VALUE; // -2147483648
int max = Integer.MAX_VALUE; // 2147483647
int num1 = 2147483648; // The result is ?
int num2 = max + 1; // The result is ?
int num3 = min - 1; // The result is ?
int num4 = 5 / 0; // The result is ?
Thank You

More Related Content

What's hot

Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
Edureka!
 
OOPs in Java
OOPs in JavaOOPs in Java
OOPs in Java
Ranjith Sekar
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
Ramrao Desai
 
Wrapper classes
Wrapper classes Wrapper classes
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
Jussi Pohjolainen
 
L9 wrapper classes
L9 wrapper classesL9 wrapper classes
L9 wrapper classes
teach4uin
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and Variables
Nilesh Dalvi
 
Java basic
Java basicJava basic
Java basic
Sonam Sharma
 
Presentation 4th
Presentation 4thPresentation 4th
Presentation 4th
Connex
 
wrapper classes
wrapper classeswrapper classes
wrapper classes
Rajesh Roky
 
06 Java Language And OOP Part VI
06 Java Language And OOP Part VI06 Java Language And OOP Part VI
06 Java Language And OOP Part VI
Hari Christian
 
Programming in c++
Programming in c++Programming in c++
Programming in c++
Baljit Saini
 
Farhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd YearFarhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd Year
dezyneecole
 
Java Building Blocks
Java Building BlocksJava Building Blocks
Java Building Blocks
Cate Huston
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
Lorna Mitchell
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
teach4uin
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
Praveen M Jigajinni
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
Bhushan Nagaraj
 
C++ classes
C++ classesC++ classes
C++ classes
imhammadali
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
Tareq Hasan
 

What's hot (20)

Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
OOPs in Java
OOPs in JavaOOPs in Java
OOPs in Java
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
L9 wrapper classes
L9 wrapper classesL9 wrapper classes
L9 wrapper classes
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and Variables
 
Java basic
Java basicJava basic
Java basic
 
Presentation 4th
Presentation 4thPresentation 4th
Presentation 4th
 
wrapper classes
wrapper classeswrapper classes
wrapper classes
 
06 Java Language And OOP Part VI
06 Java Language And OOP Part VI06 Java Language And OOP Part VI
06 Java Language And OOP Part VI
 
Programming in c++
Programming in c++Programming in c++
Programming in c++
 
Farhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd YearFarhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd Year
 
Java Building Blocks
Java Building BlocksJava Building Blocks
Java Building Blocks
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
C++ classes
C++ classesC++ classes
C++ classes
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
 

Similar to 01 Java Language And OOP PART I

Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
Connex
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
Rakesh Madugula
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
Madishetty Prathibha
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
Way2itech
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptx
ssuserb1a18d
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
Jayfee Ramos
 
C Sharp Nagina (1)
C Sharp Nagina (1)C Sharp Nagina (1)
C Sharp Nagina (1)
guest58c84c
 
C Sharp Jn (1)
C Sharp Jn (1)C Sharp Jn (1)
C Sharp Jn (1)
jahanullah
 
Python Programming
Python ProgrammingPython Programming
Python Programming
Saravanan T.M
 
demo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.pptdemo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.ppt
FerdieBalang
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
One97 Communications Limited
 
Variable
VariableVariable
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptx
lemonchoos
 
C programming language
C programming languageC programming language
C programming language
Mahmoud Eladawi
 
Java session3
Java session3Java session3
Java session3
Jigarthacker
 
introduction to python
 introduction to python introduction to python
introduction to python
Jincy Nelson
 
Data types
Data typesData types
Data types
Nokesh Prabhakar
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
Kamal Acharya
 
06.pptx
06.pptx06.pptx
06.pptx
saiproject
 
Data types slides by Faixan
Data types slides by FaixanData types slides by Faixan
Data types slides by Faixan
ٖFaiXy :)
 

Similar to 01 Java Language And OOP PART I (20)

Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptx
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
C Sharp Nagina (1)
C Sharp Nagina (1)C Sharp Nagina (1)
C Sharp Nagina (1)
 
C Sharp Jn (1)
C Sharp Jn (1)C Sharp Jn (1)
C Sharp Jn (1)
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
demo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.pptdemo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.ppt
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Variable
VariableVariable
Variable
 
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptx
 
C programming language
C programming languageC programming language
C programming language
 
Java session3
Java session3Java session3
Java session3
 
introduction to python
 introduction to python introduction to python
introduction to python
 
Data types
Data typesData types
Data types
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
 
06.pptx
06.pptx06.pptx
06.pptx
 
Data types slides by Faixan
Data types slides by FaixanData types slides by Faixan
Data types slides by Faixan
 

More from Hari Christian

HARI CV AND RESUME
HARI CV AND RESUMEHARI CV AND RESUME
HARI CV AND RESUME
Hari Christian
 
01 Java Language And OOP Part I LAB
01 Java Language And OOP Part I LAB01 Java Language And OOP Part I LAB
01 Java Language And OOP Part I LAB
Hari Christian
 
02 Java Language And OOP Part II LAB
02 Java Language And OOP Part II LAB02 Java Language And OOP Part II LAB
02 Java Language And OOP Part II LAB
Hari Christian
 
DB2 Sql Query
DB2 Sql QueryDB2 Sql Query
DB2 Sql Query
Hari Christian
 
02 Java Language And OOP PART II
02 Java Language And OOP PART II02 Java Language And OOP PART II
02 Java Language And OOP PART II
Hari Christian
 
MM38 kelas B Six Sigma
MM38 kelas B Six SigmaMM38 kelas B Six Sigma
MM38 kelas B Six Sigma
Hari Christian
 

More from Hari Christian (6)

HARI CV AND RESUME
HARI CV AND RESUMEHARI CV AND RESUME
HARI CV AND RESUME
 
01 Java Language And OOP Part I LAB
01 Java Language And OOP Part I LAB01 Java Language And OOP Part I LAB
01 Java Language And OOP Part I LAB
 
02 Java Language And OOP Part II LAB
02 Java Language And OOP Part II LAB02 Java Language And OOP Part II LAB
02 Java Language And OOP Part II LAB
 
DB2 Sql Query
DB2 Sql QueryDB2 Sql Query
DB2 Sql Query
 
02 Java Language And OOP PART II
02 Java Language And OOP PART II02 Java Language And OOP PART II
02 Java Language And OOP PART II
 
MM38 kelas B Six Sigma
MM38 kelas B Six SigmaMM38 kelas B Six Sigma
MM38 kelas B Six Sigma
 

Recently uploaded

openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 

Recently uploaded (20)

openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 

01 Java Language And OOP PART I

  • 1. Java Language and OOP Part I By Hari Christian
  • 2. Agenda • 01 Java Keyword • 02 Primitive Data Type • 03 Wrapper Class • 04 Variabel or Identifier • 05 Expression Statement • 06 Comment in Java • 07 Comment Single Line • 08 Comment Multiple Line • 09 Casting • 10 Overflow
  • 3. Keywords • Keywords are reserved words, which means they cannot be used as identifiers. Java now has 50 keywords ("enum" became a keyword in JDK 1.5)
  • 4. Keywords • abstract continue for new switch • assert default goto package synchronized • boolean do if private this • break double implements protected throw • byte else import public throws
  • 5. Keywords • case enum instanceof return transient • catch extends int short try • char final interface static void • class finally long strictfp volatile • const float native super while
  • 6. Primitive Data Type • There are eight built-in, non-object types in Java, known as primitive types. Every piece of data in a class is ultimately represented in terms of these primitive types. The eight primitive types are: – boolean (for true/false values) – char (for character data, ultimately to be input or printed) – int, long, byte, short (for arithmetic on whole numbers) – double, float (for arithmetic on the real numbers)
  • 7. Primitive Data Type - Literal • As we mention each of the eight primitive types, we'll show a typical declaration; say what range of values it can hold; and also describe the literal values for the type. • A "literal" is a value provided at compile time. Just write down the value that you mean, and that's the literal.
  • 8. Primitive Data Type - Literal • Example: int i = 2; // 2 is a literal double d = 3.14; // 3.14 is a literal if ( c == 'j' ) // 'j' is a literal
  • 9. Primitive Data Type - Literal • Every literal has a type, just like every variable has a type. • The literal written as 2 has type int. • The literal written as 3.14 belongs to the type double. • For booleans, the literals are the words false and true.
  • 10. Primitive Data Type - Literal • It is not valid to directly assign a literal of one type to a variable of another. In other words, this code is invalid: int i = 3.14; // type mismatch! BAD CODE
  • 11. Primitive Data Type – The Eigth Data Type Size Min Max byte 8 bit -128 127 short 16 bit -32.768 32.767 int 32 bit -2.147.483.648 2.147.483.647 long 64 bit -9.223.372.036.854.775.808 9.223.372.036.854.775.807 float 32 bit -3.4E38 3.4E38 double 64 bit -1.7E308 1.7E308 boolean - - - char 16 bit 'u0000' atau 0 'uffff‘ atau 65535
  • 12. Primitive Data Type - byte • Example declaration: byte aByte; • Range of values: –128 to 127 • Literals: There are no byte literals. You can use, without a cast, int literals provided their values fit in 8 bits. You can use char, long, and floating- point literals if you cast them
  • 13. Primitive Data Type - byte • You always have to cast a (non-literal) value of a larger type if you want to put it into a variable of a smaller type • Since arithmetic is always performed at least at 32-bit precision, this means that assignments to a byte variable must always be cast into the result if they involve any arithmetic, like this: byte b1=1, b2=2; byte b3 = b2 + b1; // NO! compilation error byte b3 = (byte) (b2 + b1); // correct, uses a cast
  • 14. Primitive Data Type - short • Example declaration: short aShort; • Range of values: –32,768 to 32,767 • Literals: There are no short literals. You can use, without a cast, int literals provided their values will fit in 16 bits. You can use char, long, and floating-point literals if you cast them
  • 15. Primitive Data Type - int • Example declaration: int i; • Range of values: –2,147,483,648 to 2,147,483,647 • Literals: – A decimal literal, e.g., 10 or –256 – With a leading zero, meaning an octal literal, e.g., 077777 – With a leading 0x, meaning a hexadecimal literal, e.g., 0xA5 or 0Xa5
  • 16. Primitive Data Type - long • Example declaration: long debt; • Range of values: –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 • Literals: (always put L) – A decimal literal, e.g., 2047L or –10L – An octal literal, e.g., 0777777L – A hexadecimal literal, e.g., 0xA5L or OxABadBabbeL
  • 17. Primitive Data Type - float • Example declaration: float total; • Range of values: –3.4E38 to 3.4E38 • Literals: (always put f) 1e1f 2.f .3f 3.14f 6.02e+23f
  • 18. Primitive Data Type - double • Example declaration: double salary; • Range of values: –1.7E308 to +1.7E308 • Literals: (optionally put d) 1e1 2. .3 3.14 6.02e+23d
  • 19. Primitive Data Type - boolean • Example declaration: boolean b; • Range of values: false, true • Literals: false true
  • 20. Primitive Data Type - char • Example declaration: char grade; • Range of values: a value in the Unicode code set 0 to 65,535 • Literals: Char literals are always between single quotes. String literals are always between double quotes, so you can tell apart a one- character String from a char
  • 21. Primitive Data Type - char • Here are the four ways you can write a char literal: – A single character in single quotes, char tShirtSize = 'L'; – A character escape sequence – An octal escape sequence – A Unicode escape sequence Character Description ‘n’ Linefeed ‘r’ Carriage Return ‘’f’ Formfeed ‘b’ Backspace Character Description ‘t’ Tab ‘’ Backslash ‘’”’ Double Quote ‘’’ Single Quote
  • 22. Wrapper Class • Each of the eight primitive types we have just seen has a corresponding class type, predefined in the Java library • For example, there is a class java.lang.Integer that corresponds to primitive type int • These class types accompanying the primitive types are known as object wrappers
  • 23. Wrapper Class • Wrapper Class serve several purposes: – The class is a convenient place to store constants like the biggest and smallest values the primitive type can store – The class also has methods that can convert both ways between primitive values of each type and printable Strings. Some wrapper classes have additional utility methods – Some data structure library classes only operate on objects, not primitive variables. The object wrappers provide a convenient way to convert a primitive into the equivalent object, so it can be processed by these data structure classes
  • 24. Wrapper Class – The Eight Primitive Type Wrapper Class byte java.lang.Byte short java.lang.Short int java.lang.Integer long java.lang.Long float java.lang.Float double java.lang.Double boolean java.lang.Boolean char java.lang.Character
  • 25. Wrapper Class • Example: int i = 15; Integer myInt = new Integer(i); //wrap an int in a object // get the printable representation of an Integer String s = myInt.toString(); // gets the Integer as a printable hex string String s = myInt.toHexString(15); // s is now "f" // reads a string, and gives you back an int i = myInt.parseInt( "2047" ); // reads a string, and gives you back an Integer object myInt = myInt.valueOf( "2047" );
  • 26. Identifier • Identifiers are the names provided by the programmer, and can be ANY LENGTH in Java • Identifiers must start with a LETTER, UNDERSCORE, or DOLAR SIGN, and in subsequent positions can also contain digits. • Letter with unicode character also valid
  • 27. Identifier – calories Legal Java identifiers calories Häagen_Dazs déconnage _99 Puñetas fottío i $_ p
  • 28. Identifier – Forward Reference public class Identifier { public int calculate() { // not yet declared print(“METHOD FORWARD REFERENCE”); return total; } public void print(String aString) { System.out.println(aString); } int total; }
  • 29. Expression Statement • Example: public static void main(String[] args) { int a = b; // assignment int number = 5; // assignment w.setSize(200,100); // method invocation new WarningWindow(f); // Instance creation Person p = new Person(); // Instance creation ++i; // pre-increment }
  • 30. Expression Statement • Example: public static void main(String[] args) { int i = 4; int j = 6; int x = i++ + ++i - --j + ++j + j++; System.out.println(“x = “ + x); System.out.println(“i = “ + i); System.out.println(“j = “ + j); }
  • 31. Expression Expression in Java A literal 245 This object reference this A field access now.hh A method call now.fillTimes() An object creation new Timestamp(12, 0, 0) An array creation new int[27] An array access myArray[i][j] Any expression with operator now.mins / 60 Any Expression in parens (now.millisecs * 1000)
  • 32. Comment in Java • Comment is used to make a description of a program • Comment can be used to make a program readable • Comment is ignored by compiler
  • 33. Comment Single Line • Use double slash • Example: // This is a single line comment
  • 34. Comment Multiple Line • Use /* */ • Example: /* This is a multiple line comment Use this if we want to make multiple line of comment Just remember the format: /* = to open the comment */ = to close the comment */
  • 35. Comment Multiple Line • Use /** */ • Example: /** This is a multiple line comment for Java Documentation Use this if we want to make multiple line of comment And also want to publish to Java Documentation We can also use HTML tag like this <br/> Just remember the format: /** = to open the comment */ = to close the comment */
  • 36. Casting • When you assign an expression to a variable, a conversion must be done. • Conversions among the primitive types are either identity, widening, or narrowing conversions.
  • 37. Casting - Identity • Identity conversions are an assignment between two identical types, like an int to int assignment. • The conversion is trivial: just copy the bits unchanged.
  • 38. Casting - Identity • Example: int i = 5; int j = i; // The result is ?
  • 39. Casting - Widening • Widening conversions occur when you assign from a less capacious type (such as a short) to a more capacious one (such as a long). You may lose some digits of precision when you convert either way between an integer type and a floating point type. An example of this appeared in the previous section with a long-to-float assignment. Widening conversions preserve the approximate magnitude of the result, even if it cannot be represented exactly in the new type.
  • 40. Casting - Widening • Example: int i = 5; double d = i; // The result is ?
  • 41. Casting - Narrowing • Narrowing conversions are the remaining conversions. These are assignments from one type to a different type with a smaller range. They may lose the magnitude information. Magnitude means the largeness of a number, as in the phrase "order of magnitude." So a conversion from a long to a byte will lose information about the millions and billions, but will preserve the least significant digits.
  • 42. Casting - Narrowing • Example: double d = 5.5; int i = (int) d; // The result is ?
  • 43. Overflow • When a result is too big for the type intended to hold it because of a cast, an implicit type conversion, or the evaluation of an expression, something has to give! • What happens depends on whether the result type is integer or floating point.
  • 44. Overflow • When an integer-valued expression is too big for its type, only the low end (least significant) bits get stored • Because of the way two's-complement numbers are stored, adding one to the highest positive integer value gives a result of the highest negative integer value. Watch out for this (it's true for all languages that use standard arithmetic, not just Java)
  • 45. Overflow • There is only one case in which integer calculation ceases and overflow is reported to the programmer: division by zero (using / or %) will throw an exception
  • 46. Overflow • Example: int min = Integer.MIN_VALUE; // -2147483648 int max = Integer.MAX_VALUE; // 2147483647 int num1 = 2147483648; // The result is ? int num2 = max + 1; // The result is ? int num3 = min - 1; // The result is ? int num4 = 5 / 0; // The result is ?