SlideShare a Scribd company logo
LANGUAGE BASICS PART2
JAVA
BY AMR ELGHADBAN
JAVA : Language Basics Part2
Operators Precedence
postfix expr++ expr--
unary ++expr --expr +expr -expr ~ !
multiplicative * / %
additive + -
shift << >> >>>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
JAVA :Language Basics part2
OPERATORS
▸ Operators are special symbols that perform specific
operations on one, two, or three operands, and then return
a result.
▸ The operators in the following table are listed according to
precedence order.
▸ The closer to the top of the table an operator appears, the
higher its precedence.
▸ Operators with higher precedence are evaluated before
operators with relatively lower precedence.
JAVA :Language Basics part2
OPERATORS
▸ In general-purpose programming, certain operators tend
to appear more frequently than others.
▸ for example, the assignment operator "=" is far more
common than the unsigned right shift operator ">>>".
JAVA :Language Basics part2
OPERATORS
▸ The Simple Assignment Operator
▸ One of the most common operators that you'll encounter
is the simple assignment operator "=". You saw this
operator in the Bicycle class; it assigns the value on its
right to the operand on its left:
▸ int cadence = 0;
▸ int speed = 0;
▸ int gear = 1;
JAVA :Language Basics part2
OPERATORS
▸ The Arithmetic Operators
▸ Java provides operators that perform addition, subtraction, multiplication, and
division.
▸ The only symbol that might look new to you is "%", which divides one operand by
another and returns the remainder as its result.
Operator Description
+ Additive operator (also
- Subtraction operator
* Multiplication operator
/ Division operator
% Remainder operator
JAVA :Language Basics part2
▸ class ArithmeticDemo {
▸ public static void main (String[] args) {
▸ int result = 1 + 2;
▸ // result is now 3
▸ System.out.println("1 + 2 = " + result);
▸ int original_result = result;
▸ result = result - 1;
▸ // result is now 2
▸ System.out.println(original_result + " - 1 = " + result);
▸ original_result = result;
JAVA :Language Basics part2
▸ result = result * 2;
▸ // result is now 4
▸ System.out.println(original_result + " * 2 = " + result);
▸ original_result = result;
▸ result = result / 2;
▸ // result is now 2
▸ System.out.println(original_result + " / 2 = " + result);
▸ original_result = result;
JAVA :Language Basics part2
▸ result = result + 8;
▸ // result is now 10
▸ System.out.println(original_result + " + 8 = " + result);
▸ original_result = result;
▸ result = result % 7;
▸ // result is now 3
▸ System.out.println(original_result + " % 7 = " + result);
▸ }
▸ }
JAVA :Language Basics part2
▸ This program prints the following:
▸ 1 + 2 = 3
▸ 3 - 1 = 2
▸ 2 * 2 = 4
▸ 4 / 2 = 2
▸ 2 + 8 = 10
▸ 10 % 7 = 3
JAVA :Language Basics part2
▸ You can also combine the arithmetic operators with the simple assignment operator to
create compound assignments. For example, x+=1; and x=x+1; both increment the
value of x by 1.
▸ The + operator can also be used for concatenating (joining) two strings together, as
shown in the following ConcatDemo program:
▸ class ConcatDemo {
▸ public static void main(String[] args){
▸ String firstString = "This is";
▸ String secondString = " a concatenated string.";
▸ String thirdString = firstString+secondString;
▸ System.out.println(thirdString);
▸ }
▸ }
▸ By the end of this program, the variable thirdString contains "This is a concatenated
string.", which gets printed to standard output.
JAVA :Language Basics part2
OPERATORS
▸ The Arithmetic Operators
▸ Java provides operators that perform addition, subtraction, multiplication, and
division.
▸ The only symbol that might look new to you is "%", which divides one operand by
another and returns the remainder as its result.
Operator Description
+ Unary plus operator indicates positive value
(numbers are positive without this,- Unary minus operator negates an expression
++ Increment operator, increments a value by 1
- - Decrement operator, decrements a value by 1
! Logical complement operator, inverts the
JAVA :Language Basics part2
▸ class UnaryDemo {
▸ public static void main(String[] args) {
▸ int result = +1;
▸ System.out.println(result); // result is now 1
▸ result--;
▸ System.out.println(result); // result is now 0
▸ result++;
▸ System.out.println(result); // result is now 1
▸ result = -result;
▸ System.out.println(result); // result is now -1
▸ boolean success = false;
▸ System.out.println(success); // false
▸ System.out.println(!success); // true } }
JAVA :Language Basics part2
▸ The increment/decrement operators can be applied
before (prefix) or after (postfix) the operand.
▸ The code result++ and ++result will both end in result
being incremented by one.
▸ The only difference is that the prefix version (++result)
evaluates to the incremented value, whereas the postfix
version (result++) evaluates to the original value.
▸ If you are just performing a simple increment/decrement,
it doesn't really matter which version you choose.
▸ But if you use this operator in part of a larger expression,
the one that you choose may make a significant difference.
JAVA :Language Basics part2
▸ The following program, PrePostDemo, illustrates the prefix/postfix unary increment
operator:
▸ class PrePostDemo {
▸ public static void main(String[] args){
▸ int i = 3;
▸ i++;
▸ System.out.println(i); // prints 4
▸ ++i;
▸ System.out.println(i); // prints 5
▸ System.out.println(++i); // prints 6
▸ System.out.println(i++); // prints 6
▸ System.out.println(i); // prints 7
▸ }
▸ }
JAVA :Language Basics part2
▸ The Equality and Relational Operators
▸ The equality and relational operators determine if one operand is
greater than, less than, equal to, or not equal to another operand.
The majority of these operators will probably look familiar to you as
well. Keep in mind that you must use "==", not "=", when testing if
two primitive values are equal.
▸ == equal to
▸ != not equal to
▸ > greater than
▸ >= greater than or equal to
▸ < less than
▸ <= less than or equal to
JAVA :Language Basics part2
▸ class ComparisonDemo {
▸ public static void main(String[] args){
▸ int value1 = 1;
▸ int value2 = 2;
▸ if(value1 == value2)
▸ System.out.println("value1 == value2");
▸ if(value1 != value2)
▸ System.out.println("value1 != value2");
▸ if(value1 > value2)
▸ System.out.println("value1 > value2");
▸ if(value1 < value2)
▸ System.out.println("value1 < value2");
▸ if(value1 <= value2)
▸ System.out.println("value1 <= value2”); } }
JAVA :Language Basics part2
▸ Output:
▸ value1 != value2
▸ value1 < value2
▸ value1 <= value2
JAVA :Language Basics part2
▸ Another conditional operator is ?:, which can be thought of as shorthand for an if-then-else
statement (discussed in the Control Flow Statements section of this lesson). This operator is also
known as the ternary operator because it uses three operands. In the following example, this
operator should be read as: "If someCondition is true, assign the value of value1 to result.
Otherwise, assign the value of value2 to result."
▸ The following program, ConditionalDemo2, tests the ?: operator:
▸ class ConditionalDemo2 {
▸ public static void main(String[] args){
▸ int value1 = 1;
▸ int value2 = 2;
▸ int result;
▸ boolean someCondition = true;
▸ result = someCondition ? value1 : value2;
▸ System.out.println(result); } }
▸ Because someCondition is true, this program prints "1" to the screen. Use the ?: operator instead of
an if-then-else statement if it makes your code more readable; for example, when the expressions
are compact and without side-effects (such as assignments).
JAVA :Language Basics part2
▸ The following quick reference summarizes the operators supported by the Java programming language.
▸ Simple Assignment Operator
▸ = Simple assignment operator
▸ Arithmetic Operators
▸ + Additive operator (also used for String concatenation)
▸ - Subtraction operator
▸ * Multiplication operator
▸ / Division operator
▸ % Remainder operator
▸ Unary Operators
▸ + Unary plus operator; indicates positive value (numbers are positive without this, however)
▸ - Unary minus operator negates an expression
▸ ++ Increment operator increments a value by 1
▸ -- Decrement operator decrements a value by 1
▸ ! Logical complement operator inverts the value of a boolean
▸ Equality and Relational Operators
▸ == Equal to
▸ != Not equal to
▸ > Greater than
▸ >= Greater than or equal to
▸ < Less than
▸ <= Less than or equal to
JAVA :Language Basics part2
▸ The following quick reference summarizes the operators supported by the Java programming
language.
▸ Conditional Operators
▸ && Conditional-AND
▸ || Conditional-OR
▸ ?: Ternary (shorthand for if-then-else statement)
▸ Type Comparison Operator
▸ instanceof Compares an object to a specified type
▸ Bitwise and Bit Shift Operators
▸ ~ Unary bitwise complement
▸ << Signed left shift
▸ >> Signed right shift
▸ >>> Unsigned right shift
▸ & Bitwise AND
▸ ^ Bitwise exclusive OR
▸ | Bitwise inclusive OR
THANKS
WISH YOU A WONDERFUL DAY
▸ Skype : amr_elghadban
▸ Email :amr.elghadban@gmail.com
▸ Phone : (+20)1098558500
▸ Fb/amr.elghadban
▸ Linkedin/amr_elghadban
Ad

More Related Content

What's hot (20)

Functions
FunctionsFunctions
Functions
Septi Ratnasari
 
Object Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of ExamsObject Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of Exams
MuhammadTalha436
 
Functional Effects - Part 2
Functional Effects - Part 2Functional Effects - Part 2
Functional Effects - Part 2
Philip Schwarz
 
Understanding Subroutines and Functions in VB6
Understanding Subroutines and Functions in VB6Understanding Subroutines and Functions in VB6
Understanding Subroutines and Functions in VB6
Notre Dame of Midsayap College
 
Pointer basics
Pointer basicsPointer basics
Pointer basics
Mohammed Sikander
 
Function
Function Function
Function
Kathmandu University
 
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
ssuserd6b1fd
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
Bansari Shah
 
Python functions
Python functionsPython functions
Python functions
Prof. Dr. K. Adisesha
 
Functional programming java
Functional programming javaFunctional programming java
Functional programming java
Maneesh Chaturvedi
 
Functional Objects in Ruby: new horizons – Valentine Ostakh
Functional Objects in Ruby: new horizons  – Valentine OstakhFunctional Objects in Ruby: new horizons  – Valentine Ostakh
Functional Objects in Ruby: new horizons – Valentine Ostakh
Ruby Meditation
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
Ñirmal Tatiwal
 
DataWeave 2.0 - MuleSoft CONNECT 2019
DataWeave 2.0 - MuleSoft CONNECT 2019DataWeave 2.0 - MuleSoft CONNECT 2019
DataWeave 2.0 - MuleSoft CONNECT 2019
Sabrina Marechal
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
Functional programming 101
Functional programming 101Functional programming 101
Functional programming 101
Maneesh Chaturvedi
 
Optimization toolbox presentation
Optimization toolbox presentationOptimization toolbox presentation
Optimization toolbox presentation
Ravi Kannappan
 
User defined functions
User defined functionsUser defined functions
User defined functions
Randy Riness @ South Puget Sound Community College
 
C function presentation
C function presentationC function presentation
C function presentation
Touhidul Shawan
 
Clean code and refactoring
Clean code and refactoringClean code and refactoring
Clean code and refactoring
Yuriy Gerasimov
 
Object Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of ExamsObject Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of Exams
MuhammadTalha436
 
Functional Effects - Part 2
Functional Effects - Part 2Functional Effects - Part 2
Functional Effects - Part 2
Philip Schwarz
 
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
ssuserd6b1fd
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
 
Functional Objects in Ruby: new horizons – Valentine Ostakh
Functional Objects in Ruby: new horizons  – Valentine OstakhFunctional Objects in Ruby: new horizons  – Valentine Ostakh
Functional Objects in Ruby: new horizons – Valentine Ostakh
Ruby Meditation
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
Ñirmal Tatiwal
 
DataWeave 2.0 - MuleSoft CONNECT 2019
DataWeave 2.0 - MuleSoft CONNECT 2019DataWeave 2.0 - MuleSoft CONNECT 2019
DataWeave 2.0 - MuleSoft CONNECT 2019
Sabrina Marechal
 
Optimization toolbox presentation
Optimization toolbox presentationOptimization toolbox presentation
Optimization toolbox presentation
Ravi Kannappan
 
Clean code and refactoring
Clean code and refactoringClean code and refactoring
Clean code and refactoring
Yuriy Gerasimov
 

Viewers also liked (20)

9-java language basics part3
9-java language basics part39-java language basics part3
9-java language basics part3
Amr Elghadban (AmrAngry)
 
10- java language basics part4
10- java language basics part410- java language basics part4
10- java language basics part4
Amr Elghadban (AmrAngry)
 
7-Java Language Basics Part1
7-Java Language Basics Part17-Java Language Basics Part1
7-Java Language Basics Part1
Amr Elghadban (AmrAngry)
 
1-oop java-object
1-oop java-object1-oop java-object
1-oop java-object
Amr Elghadban (AmrAngry)
 
0-oop java-intro
0-oop java-intro0-oop java-intro
0-oop java-intro
Amr Elghadban (AmrAngry)
 
3-oop java-inheritance
3-oop java-inheritance3-oop java-inheritance
3-oop java-inheritance
Amr Elghadban (AmrAngry)
 
single leg mlm plan software | single line mlm plan software
single leg  mlm plan software | single line mlm plan softwaresingle leg  mlm plan software | single line mlm plan software
single leg mlm plan software | single line mlm plan software
Websoftex Software Solutions Pvt Ltd
 
Gprs franchisee projected income
Gprs franchisee projected incomeGprs franchisee projected income
Gprs franchisee projected income
mary jane amatos
 
Infinite mlm software
Infinite mlm softwareInfinite mlm software
Infinite mlm software
Infinite Open Source Solutions LLP
 
Infinite mlm compensation plans
Infinite mlm compensation plansInfinite mlm compensation plans
Infinite mlm compensation plans
Infinite Open Source Solutions LLP
 
MLM Business
MLM BusinessMLM Business
MLM Business
AJ Square Inc
 
For Loops and Variables in Java
For Loops and Variables in JavaFor Loops and Variables in Java
For Loops and Variables in Java
Pokequesthero
 
02basics
02basics02basics
02basics
Waheed Warraich
 
Non ieee dot net projects list
Non  ieee dot net projects list Non  ieee dot net projects list
Non ieee dot net projects list
Mumbai Academisc
 
Yaazli International AngularJS 5 Training
Yaazli International AngularJS 5 TrainingYaazli International AngularJS 5 Training
Yaazli International AngularJS 5 Training
Arjun Sridhar U R
 
09events
09events09events
09events
Waheed Warraich
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
yugandhar vadlamudi
 
Yaazli International Web Project Workshop
Yaazli International Web Project WorkshopYaazli International Web Project Workshop
Yaazli International Web Project Workshop
Arjun Sridhar U R
 
Toolbarexample
ToolbarexampleToolbarexample
Toolbarexample
yugandhar vadlamudi
 
Core java online training
Core java online trainingCore java online training
Core java online training
Glory IT Technologies Pvt. Ltd.
 
Gprs franchisee projected income
Gprs franchisee projected incomeGprs franchisee projected income
Gprs franchisee projected income
mary jane amatos
 
For Loops and Variables in Java
For Loops and Variables in JavaFor Loops and Variables in Java
For Loops and Variables in Java
Pokequesthero
 
Non ieee dot net projects list
Non  ieee dot net projects list Non  ieee dot net projects list
Non ieee dot net projects list
Mumbai Academisc
 
Yaazli International AngularJS 5 Training
Yaazli International AngularJS 5 TrainingYaazli International AngularJS 5 Training
Yaazli International AngularJS 5 Training
Arjun Sridhar U R
 
Yaazli International Web Project Workshop
Yaazli International Web Project WorkshopYaazli International Web Project Workshop
Yaazli International Web Project Workshop
Arjun Sridhar U R
 
Ad

Similar to 8- java language basics part2 (20)

Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1 Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1
To Sum It Up
 
Python_UNIT-I.pptx
Python_UNIT-I.pptxPython_UNIT-I.pptx
Python_UNIT-I.pptx
mustafatahertotanawa1
 
Operators
OperatorsOperators
Operators
loidasacueza
 
Python advance
Python advancePython advance
Python advance
Deepak Chandella
 
C operators
C operatorsC operators
C operators
GPERI
 
As Level Computer Science Book -2
As Level Computer Science  Book -2As Level Computer Science  Book -2
As Level Computer Science Book -2
DIGDARSHAN KUNWAR
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
jacksnathalie
 
operators.pptx
operators.pptxoperators.pptx
operators.pptx
ruchisuru20001
 
Algorithms, Structure Charts, Corrective and adaptive.ppsx
Algorithms, Structure Charts, Corrective and adaptive.ppsxAlgorithms, Structure Charts, Corrective and adaptive.ppsx
Algorithms, Structure Charts, Corrective and adaptive.ppsx
DaniyalManzoor3
 
presentation on array java program operators
presentation on array java program operatorspresentation on array java program operators
presentation on array java program operators
anushaashraf20
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
ishan743441
 
Operators, Strings and Math built-in functions.pdf
Operators, Strings and Math built-in functions.pdfOperators, Strings and Math built-in functions.pdf
Operators, Strings and Math built-in functions.pdf
ssusere3b1a2
 
Operators in java
Operators in javaOperators in java
Operators in java
Madishetty Prathibha
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
bajiajugal
 
Program 1 (Practicing an example of function using call by referenc.pdf
Program 1 (Practicing an example of function using call by referenc.pdfProgram 1 (Practicing an example of function using call by referenc.pdf
Program 1 (Practicing an example of function using call by referenc.pdf
ezhilvizhiyan
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
shandicollingwood
 
[1062BPY12001] Data analysis with R / April 26
[1062BPY12001] Data analysis with R / April 26[1062BPY12001] Data analysis with R / April 26
[1062BPY12001] Data analysis with R / April 26
Kevin Chun-Hsien Hsu
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
Ashita Agrawal
 
Chapter 3.3
Chapter 3.3Chapter 3.3
Chapter 3.3
sotlsoc
 
Functions and tasks in verilog
Functions and tasks in verilogFunctions and tasks in verilog
Functions and tasks in verilog
Nallapati Anindra
 
Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1 Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1
To Sum It Up
 
C operators
C operatorsC operators
C operators
GPERI
 
As Level Computer Science Book -2
As Level Computer Science  Book -2As Level Computer Science  Book -2
As Level Computer Science Book -2
DIGDARSHAN KUNWAR
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
jacksnathalie
 
Algorithms, Structure Charts, Corrective and adaptive.ppsx
Algorithms, Structure Charts, Corrective and adaptive.ppsxAlgorithms, Structure Charts, Corrective and adaptive.ppsx
Algorithms, Structure Charts, Corrective and adaptive.ppsx
DaniyalManzoor3
 
presentation on array java program operators
presentation on array java program operatorspresentation on array java program operators
presentation on array java program operators
anushaashraf20
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
ishan743441
 
Operators, Strings and Math built-in functions.pdf
Operators, Strings and Math built-in functions.pdfOperators, Strings and Math built-in functions.pdf
Operators, Strings and Math built-in functions.pdf
ssusere3b1a2
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
bajiajugal
 
Program 1 (Practicing an example of function using call by referenc.pdf
Program 1 (Practicing an example of function using call by referenc.pdfProgram 1 (Practicing an example of function using call by referenc.pdf
Program 1 (Practicing an example of function using call by referenc.pdf
ezhilvizhiyan
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
shandicollingwood
 
[1062BPY12001] Data analysis with R / April 26
[1062BPY12001] Data analysis with R / April 26[1062BPY12001] Data analysis with R / April 26
[1062BPY12001] Data analysis with R / April 26
Kevin Chun-Hsien Hsu
 
Chapter 3.3
Chapter 3.3Chapter 3.3
Chapter 3.3
sotlsoc
 
Functions and tasks in verilog
Functions and tasks in verilogFunctions and tasks in verilog
Functions and tasks in verilog
Nallapati Anindra
 
Ad

More from Amr Elghadban (AmrAngry) (9)

Code detox
Code detoxCode detox
Code detox
Amr Elghadban (AmrAngry)
 
08 objective-c session 8
08  objective-c session 808  objective-c session 8
08 objective-c session 8
Amr Elghadban (AmrAngry)
 
07 objective-c session 7
07  objective-c session 707  objective-c session 7
07 objective-c session 7
Amr Elghadban (AmrAngry)
 
05 objective-c session 5
05  objective-c session 505  objective-c session 5
05 objective-c session 5
Amr Elghadban (AmrAngry)
 
04 objective-c session 4
04  objective-c session 404  objective-c session 4
04 objective-c session 4
Amr Elghadban (AmrAngry)
 
03 objective-c session 3
03  objective-c session 303  objective-c session 3
03 objective-c session 3
Amr Elghadban (AmrAngry)
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
Amr Elghadban (AmrAngry)
 
01 objective-c session 1
01  objective-c session 101  objective-c session 1
01 objective-c session 1
Amr Elghadban (AmrAngry)
 
00 intro ios
00 intro ios00 intro ios
00 intro ios
Amr Elghadban (AmrAngry)
 

Recently uploaded (20)

Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 

8- java language basics part2

  • 2. JAVA : Language Basics Part2 Operators Precedence postfix expr++ expr-- unary ++expr --expr +expr -expr ~ ! multiplicative * / % additive + - shift << >> >>> relational < > <= >= instanceof equality == != bitwise AND & bitwise exclusive OR ^ bitwise inclusive OR | logical AND && logical OR || ternary ? : assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
  • 3. JAVA :Language Basics part2 OPERATORS ▸ Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result. ▸ The operators in the following table are listed according to precedence order. ▸ The closer to the top of the table an operator appears, the higher its precedence. ▸ Operators with higher precedence are evaluated before operators with relatively lower precedence.
  • 4. JAVA :Language Basics part2 OPERATORS ▸ In general-purpose programming, certain operators tend to appear more frequently than others. ▸ for example, the assignment operator "=" is far more common than the unsigned right shift operator ">>>".
  • 5. JAVA :Language Basics part2 OPERATORS ▸ The Simple Assignment Operator ▸ One of the most common operators that you'll encounter is the simple assignment operator "=". You saw this operator in the Bicycle class; it assigns the value on its right to the operand on its left: ▸ int cadence = 0; ▸ int speed = 0; ▸ int gear = 1;
  • 6. JAVA :Language Basics part2 OPERATORS ▸ The Arithmetic Operators ▸ Java provides operators that perform addition, subtraction, multiplication, and division. ▸ The only symbol that might look new to you is "%", which divides one operand by another and returns the remainder as its result. Operator Description + Additive operator (also - Subtraction operator * Multiplication operator / Division operator % Remainder operator
  • 7. JAVA :Language Basics part2 ▸ class ArithmeticDemo { ▸ public static void main (String[] args) { ▸ int result = 1 + 2; ▸ // result is now 3 ▸ System.out.println("1 + 2 = " + result); ▸ int original_result = result; ▸ result = result - 1; ▸ // result is now 2 ▸ System.out.println(original_result + " - 1 = " + result); ▸ original_result = result;
  • 8. JAVA :Language Basics part2 ▸ result = result * 2; ▸ // result is now 4 ▸ System.out.println(original_result + " * 2 = " + result); ▸ original_result = result; ▸ result = result / 2; ▸ // result is now 2 ▸ System.out.println(original_result + " / 2 = " + result); ▸ original_result = result;
  • 9. JAVA :Language Basics part2 ▸ result = result + 8; ▸ // result is now 10 ▸ System.out.println(original_result + " + 8 = " + result); ▸ original_result = result; ▸ result = result % 7; ▸ // result is now 3 ▸ System.out.println(original_result + " % 7 = " + result); ▸ } ▸ }
  • 10. JAVA :Language Basics part2 ▸ This program prints the following: ▸ 1 + 2 = 3 ▸ 3 - 1 = 2 ▸ 2 * 2 = 4 ▸ 4 / 2 = 2 ▸ 2 + 8 = 10 ▸ 10 % 7 = 3
  • 11. JAVA :Language Basics part2 ▸ You can also combine the arithmetic operators with the simple assignment operator to create compound assignments. For example, x+=1; and x=x+1; both increment the value of x by 1. ▸ The + operator can also be used for concatenating (joining) two strings together, as shown in the following ConcatDemo program: ▸ class ConcatDemo { ▸ public static void main(String[] args){ ▸ String firstString = "This is"; ▸ String secondString = " a concatenated string."; ▸ String thirdString = firstString+secondString; ▸ System.out.println(thirdString); ▸ } ▸ } ▸ By the end of this program, the variable thirdString contains "This is a concatenated string.", which gets printed to standard output.
  • 12. JAVA :Language Basics part2 OPERATORS ▸ The Arithmetic Operators ▸ Java provides operators that perform addition, subtraction, multiplication, and division. ▸ The only symbol that might look new to you is "%", which divides one operand by another and returns the remainder as its result. Operator Description + Unary plus operator indicates positive value (numbers are positive without this,- Unary minus operator negates an expression ++ Increment operator, increments a value by 1 - - Decrement operator, decrements a value by 1 ! Logical complement operator, inverts the
  • 13. JAVA :Language Basics part2 ▸ class UnaryDemo { ▸ public static void main(String[] args) { ▸ int result = +1; ▸ System.out.println(result); // result is now 1 ▸ result--; ▸ System.out.println(result); // result is now 0 ▸ result++; ▸ System.out.println(result); // result is now 1 ▸ result = -result; ▸ System.out.println(result); // result is now -1 ▸ boolean success = false; ▸ System.out.println(success); // false ▸ System.out.println(!success); // true } }
  • 14. JAVA :Language Basics part2 ▸ The increment/decrement operators can be applied before (prefix) or after (postfix) the operand. ▸ The code result++ and ++result will both end in result being incremented by one. ▸ The only difference is that the prefix version (++result) evaluates to the incremented value, whereas the postfix version (result++) evaluates to the original value. ▸ If you are just performing a simple increment/decrement, it doesn't really matter which version you choose. ▸ But if you use this operator in part of a larger expression, the one that you choose may make a significant difference.
  • 15. JAVA :Language Basics part2 ▸ The following program, PrePostDemo, illustrates the prefix/postfix unary increment operator: ▸ class PrePostDemo { ▸ public static void main(String[] args){ ▸ int i = 3; ▸ i++; ▸ System.out.println(i); // prints 4 ▸ ++i; ▸ System.out.println(i); // prints 5 ▸ System.out.println(++i); // prints 6 ▸ System.out.println(i++); // prints 6 ▸ System.out.println(i); // prints 7 ▸ } ▸ }
  • 16. JAVA :Language Basics part2 ▸ The Equality and Relational Operators ▸ The equality and relational operators determine if one operand is greater than, less than, equal to, or not equal to another operand. The majority of these operators will probably look familiar to you as well. Keep in mind that you must use "==", not "=", when testing if two primitive values are equal. ▸ == equal to ▸ != not equal to ▸ > greater than ▸ >= greater than or equal to ▸ < less than ▸ <= less than or equal to
  • 17. JAVA :Language Basics part2 ▸ class ComparisonDemo { ▸ public static void main(String[] args){ ▸ int value1 = 1; ▸ int value2 = 2; ▸ if(value1 == value2) ▸ System.out.println("value1 == value2"); ▸ if(value1 != value2) ▸ System.out.println("value1 != value2"); ▸ if(value1 > value2) ▸ System.out.println("value1 > value2"); ▸ if(value1 < value2) ▸ System.out.println("value1 < value2"); ▸ if(value1 <= value2) ▸ System.out.println("value1 <= value2”); } }
  • 18. JAVA :Language Basics part2 ▸ Output: ▸ value1 != value2 ▸ value1 < value2 ▸ value1 <= value2
  • 19. JAVA :Language Basics part2 ▸ Another conditional operator is ?:, which can be thought of as shorthand for an if-then-else statement (discussed in the Control Flow Statements section of this lesson). This operator is also known as the ternary operator because it uses three operands. In the following example, this operator should be read as: "If someCondition is true, assign the value of value1 to result. Otherwise, assign the value of value2 to result." ▸ The following program, ConditionalDemo2, tests the ?: operator: ▸ class ConditionalDemo2 { ▸ public static void main(String[] args){ ▸ int value1 = 1; ▸ int value2 = 2; ▸ int result; ▸ boolean someCondition = true; ▸ result = someCondition ? value1 : value2; ▸ System.out.println(result); } } ▸ Because someCondition is true, this program prints "1" to the screen. Use the ?: operator instead of an if-then-else statement if it makes your code more readable; for example, when the expressions are compact and without side-effects (such as assignments).
  • 20. JAVA :Language Basics part2 ▸ The following quick reference summarizes the operators supported by the Java programming language. ▸ Simple Assignment Operator ▸ = Simple assignment operator ▸ Arithmetic Operators ▸ + Additive operator (also used for String concatenation) ▸ - Subtraction operator ▸ * Multiplication operator ▸ / Division operator ▸ % Remainder operator ▸ Unary Operators ▸ + Unary plus operator; indicates positive value (numbers are positive without this, however) ▸ - Unary minus operator negates an expression ▸ ++ Increment operator increments a value by 1 ▸ -- Decrement operator decrements a value by 1 ▸ ! Logical complement operator inverts the value of a boolean ▸ Equality and Relational Operators ▸ == Equal to ▸ != Not equal to ▸ > Greater than ▸ >= Greater than or equal to ▸ < Less than ▸ <= Less than or equal to
  • 21. JAVA :Language Basics part2 ▸ The following quick reference summarizes the operators supported by the Java programming language. ▸ Conditional Operators ▸ && Conditional-AND ▸ || Conditional-OR ▸ ?: Ternary (shorthand for if-then-else statement) ▸ Type Comparison Operator ▸ instanceof Compares an object to a specified type ▸ Bitwise and Bit Shift Operators ▸ ~ Unary bitwise complement ▸ << Signed left shift ▸ >> Signed right shift ▸ >>> Unsigned right shift ▸ & Bitwise AND ▸ ^ Bitwise exclusive OR ▸ | Bitwise inclusive OR
  • 22. THANKS WISH YOU A WONDERFUL DAY ▸ Skype : amr_elghadban ▸ Email :[email protected] ▸ Phone : (+20)1098558500 ▸ Fb/amr.elghadban ▸ Linkedin/amr_elghadban