SlideShare a Scribd company logo
OBJECT ORIENTED
PROGRAMMING
TOPICS TO BE COVERED TODAY
 Array
 Single & Multi-dimensional
 Java Operators
 Assignment
 Arithmetic
 Relational
 Logical
 Bitwise & other
ARRAYS
 An array is a group of liked-typed variables referred to by a
common name, with individual variables accessed by their
index.
 Arrays are: 1) declared, 2) created, 3) initialized 4) used
 Also, arrays can have one or several dimensions.
 Array declaration involves:
1) declaring an array identifier
2) declaring the number of dimensions
3) declaring the data type of the array elements
 Two styles of array declaration:
type array-variable[ ];
or
type [ ] array-variable;
ARRAY CREATION
 After declaration, no array actually exists.
 In order to create an array, we use the new
operator:
type array-variable[ ];
array-variable = new type[size];
 This creates a new array to hold size elements of
type type, whose reference will be kept in the
variable array-variable.
ARRAY INDEXING
 Later we can refer to the elements of this array
through their indexes:
array-variable[index]
 The array index always starts with zero!
 The Java run-time system makes sure that all array
indexes are in the correct range, otherwise raises a
run-time error.
object oriented programming java lectures
ARRAY INITIALIZATION
 Arrays can be initialized when they are declared:
int monthDays[ ] =
{31,28,31,30,31,30,31,31,30,31,30,31};
Comments:
1) there is no need to use the new operator
2) the array is created large enough to hold all specified
elements
MULTI-DIMENSIONAL ARRAY
 Multidimensional arrays are arrays of arrays:
1) declaration
int array[ ][ ];
2) creation
int array = new int[2][3];
3) initialization
int array[ ][ ] = { {1, 2, 3}, {4, 5, 6} };
EXAMPLE: MULTI-DIMENSIONAL ARRAY
e-Macao-16-2-134
EXERCISE: ARRAYS
1) Write a program that creates an array of 10 integers with the initial values
of 3.
2) Write a Java program to find the average of a sequence of nonnegative
numbers entered by the user, where the user enters a negative number
to terminate the input. Assume the only method in the class is the main
method.
3) What's the index of the first and the last component of a one hundred
component array?
4) What will happen if you try to compile and run the following code?
public class Q {
public static void main(String argv[]){
int var[]=new int[5]; System.out.println(var[0]);
} }
ASSIGNMENT 01 (CLO-1, 2)
(DEADLINE JANUARY 26, 2024)
 Differentiate compile time vs run time errors.
 Try example codes
 Explore Arrays class in java.util package.
 Try example codes of different methods such as
binarysearch(), sort(), equals(), fill(), hashCode(),
copyOf(), copyOfRange(), ….
 These methods are overloaded.
 Visit the following link for help :
https://www.geeksforgeeks.org/array-class-in-java/
Prepare Array Class for Quiz, it will be taken after
assignment submission.
JAVA OPERATORS
 Java operators are used to build value expressions.
 Java provides a rich set of operators:
1) assignment
2) arithmetic
3) relational
4) logical
5) bitwise
6) other
OPERATORS AND OPERANDS
 Each operator takes one, two or three operands:
1) a unary operator takes one operand
j++;
2) a binary operator takes two operands
i = j++;
3) a ternary operator requires three operands
i = (i>12) ? 1 : i++;
ASSIGNMENT OPERATOR
 A binary operator:
variable = expression;
 It assigns the value of the expression to the
variable.
 The types of the variable and expression must be
compatible.
 The value of the whole assignment expression is
the value of the expression on the right, so it is
possible to chain assignment expressions as
follows:
◦ int x, y, z;
◦ x = y = z = 2;
ARITHMETIC OPERATORS
 Java supports various arithmetic operators for:
1) integer numbers
2) floating-point numbers
 There are two kinds of arithmetic operators:
1) basic: addition, subtraction, multiplication, division and
modulo
2) shortcut: arithmetic assignment, increment and
decrement
BASIC ARITHMETIC OPERATOR
SIMPLE ARITHMETIC
public class Example {
public static void main(String[] args) {
int j, k, p, q, r, s, t;
j = 5;
k = 2;
p = j + k;
q = j - k;
r = j * k;
s = j / k;
t = j % k;
System.out.println("p = " + p);
System.out.println("q = " + q);
System.out.println("r = " + r);
System.out.println("s = " + s);
System.out.println("t = " + t);
}
}
> java Example
p = 7
q = 3
r = 10
s = 2
t = 1
>
ARITHMETIC ASSIGNMENT / SHORTHAND
OPERATOR
SHORTHAND OPERATOR
public class Example {
public static void main(String[] args) {
int j, p, q, r, s, t;
j = 5;
p = 1; q = 2; r = 3; s = 4; t = 5;
p += j;
q -= j;
r *= j;
s /= j;
t %= j;
System.out.println("p = " + p);
System.out.println("q = " + q);
System.out.println("r = " + r);
System.out.println("s = " + s);
System.out.println("t = " + t);
}
}
> java Example
p = 6
q = -3
r = 15
s = 0
t = 0
>
INCREMENT/ DECREMENT OPERATORS
 Two unary operators:
1) ++ increments its operand by 1
2) -- decrements its operand by 1
 The operand must be a numerical variable.
 Each operation can appear in two versions:
• prefix version evaluates the value of the operand after
performing the increment/decrement operation
• postfix version evaluates the value of the operand
before performing the increment/decrement operation
INCREMENT/ DECREMENT
INCREMENT AND DECREMENT
public class Example {
public static void main(String[] args) {
int j, p, q, r, s;
j = 5;
p = ++j; // j = j + 1; p = j;
System.out.println("p = " + p);
q = j++; // q = j; j = j + 1;
System.out.println("q = " + q);
System.out.println("j = " + j);
r = --j; // j = j -1; r = j;
System.out.println("r = " + r);
s = j--; // s = j; j = j - 1;
System.out.println("s = " + s);
}
}
> java example
p = 6
q = 6
j = 7
r = 6
s = 6
>
RELATIONAL OPERATOR
 Relational operators determine the relationship that
one operand has to the other operand, specifically
equality and ordering.
 The outcome is always a value of type boolean.
 They are most often used in branching and loop
control statements.
RELATIONAL OPERATORS
RELATIONAL OPERATOR EXAMPLES
public class Example {
public static void main(String[] args) {
int p =2; int q = 2; int r = 3;
System.out.println("p < r " + (p < r));
System.out.println("p > r " + (p > r));
System.out.println("p == q " + (p == q));
System.out.println("p != q " + (p != q));
}
}
> java Example
p < r true
p > r false
p == q true
p != q false
>
LOGICAL OPERATORS
 Logical operators act upon boolean operands only.
 The outcome is always a value of type boolean.
 In particular, logical operators occur in two forms:
1) full op1 & op2 and op1 | op2 where both op1 and op2
are evaluated
2) short-circuit - op1 && op2 and op1 || op2 where op2 is
only evaluated if the value of op1 is insufficient to
determine the final outcome
LOGICAL OPERATORS
LOGICAL (&&) OPERATOR EXAMPLES
public class Example {
public static void main(String[] args) {
boolean t = true;
boolean f = false;
System.out.println("f && f " + (f && f));
System.out.println("f && t " + (f && t));
System.out.println("t && f " + (t && f));
System.out.println("t && t " + (t && t));
}
}
> java Example
f && f false
f && t false
t && f false
t && t true
>
LOGICAL (||) OPERATOR EXAMPLES
public class Example {
public static void main(String[] args) {
boolean t = true;
boolean f = false;
System.out.println("f || f " + (f || f));
System.out.println("f || t " + (f || t));
System.out.println("t || f " + (t || f));
System.out.println("t || t " + (t || t));
}
}
> java Example
f || f false
f || t true
t || f true
t || t true
>
LOGICAL (!) OPERATOR EXAMPLES
public class Example {
public static void main(String[] args) {
boolean t = true;
boolean f = false;
System.out.println("!f " + !f);
System.out.println("!t " + !t);
}
}
> java Example
!f true
!t false
>
LOGICAL OPERATOR EXAMPLES
SHORT CIRCUITING WITH &&
public class Example {
public static void main(String[] args) {
boolean b;
int j, k;
j = 0; k = 0;
b = ( j++ == k ) && ( j == ++k );
System.out.println("b, j, k " + b + ", " + j + ", " + k);
j = 0; k = 0;
b = ( j++ != k ) && ( j == ++k );
System.out.println("b, j, k " + b + ", " + j + ", " + k);
}
}
> java Example
b, j, k true 1, 1
> java Example
b, j, k true 1, 1
b, j, k false 1, 0
>
LOGICAL OPERATOR EXAMPLES
SHORT CIRCUITING WITH ||
public class Example {
public static void main(String[] args) {
boolean b;
int j, k;
j = 0; k = 0;
b = ( j++ == k ) || ( j == ++k );
System.out.println("b, j, k " + b + ", " + j + ", " + k);
j = 0; k = 0;
b = ( j++ != k ) || ( j == ++k );
System.out.println("b, j, k " + b + ", " + j + ", " + k);
}
} > java Example
b, j, k true 1, 0
> java Example
b, j, k true 1, 0
b, j, k true 1, 1
>
CLASS PARTICIPATION
ANSWER
BITWISE OPERATORS
 Bitwise operators apply to integer types only.
 They act on individual bits of their operands.
 There are three kinds of bitwise operators:
1) basic bitwise AND, OR, NOT and XOR
2) shifts left, right and right-zero-fill
BITWISE OPERATORS
TWOS COMPLEMENT NUMBERS
Base 10 A byte of binary
+127 01111111
+4 00000100
+3 00000011
+2 00000010
+1 00000001
+0 00000000
-1 11111111
-2 11111110
-3 11111101
-4 11111100
-128 10000000
LOGICAL OPERATORS (BIT LEVEL)
& | ^ ~
int a = 10; // 00001010 = 10
int b = 12; // 00001100 = 12
a 00000000000000000000000000001010 10
b 00000000000000000000000000001100 12
a & b 00000000000000000000000000001000 8
a 00000000000000000000000000001010 10
b 00000000000000000000000000001100 12
a | b 00000000000000000000000000001110 14
a 00000000000000000000000000001010 10
b 00000000000000000000000000001100 12
a ^ b 00000000000000000000000000000110 6
a 00000000000000000000000000001010 10
~a 11111111111111111111111111110101 -11
&
AND
|
OR
^
XOR
~
NOT
LOGICAL (BIT) OPERATOR EXAMPLES
public class Example {
public static void main(String[] args) {
int a = 10; // 00001010 = 10
int b = 12; // 00001100 = 12
int and, or, xor, na;
and = a & b; // 00001000 = 8
or = a | b; // 00001110 = 14
xor = a ^ b; // 00000110 = 6
na = ~a; // 11110101 = -11
System.out.println("and " + and);
System.out.println("or " + or);
System.out.println("xor " + xor);
System.out.println("na " + na);
}
}
> java Example
and 8
or 14
xor 6
na -11
>
SHIFT OPERATORS (BIT LEVEL)
<< >> >>>
• Shift Left << Fill with Zeros
• Shift Right >> Based on Sign
• Shift Right >>> Fill with Zeros
SHIFT OPERATORS << >>
int a = 3; // ...00000011 = 3
int b = -4; // ...11111100 = -4
a 00000000000000000000000000000011 3
a << 2 00000000000000000000000000001100 12
b 11111111111111111111111111111100 -4
b << 2 11111111111111111111111111110000 -16
<<
Left
>>
Right
a 00000000000000000000000000000011 3
a >> 2 00000000000000000000000000000000 0
b 11111111111111111111111111111100 -4
b >> 2 11111111111111111111111111111111 -1
SHIFT OPERATOR >>>
int a = 3; // ...00000011 = 3
int b = -4; // ...11111100 = -4
>>>
Right 0
a 00000000000000000000000000000011 3
a >>> 2 00000000000000000000000000000000 0
b 11111111111111111111111111111100 -4
b >>> 2 00111111111111111111111111111111 +big
1073741823
SHIFT OPERATOR EXAMPLES
public class Example {
public static void main(String[] args) {
int a = 3; // ...00000011 = 3
int b = -4; // ...11111100 = -4
System.out.println("a<<2 = " + (a<<2));
System.out.println("b<<2 = " + (b<<2));
System.out.println("a>>2 = " + (a>>2));
System.out.println("b>>2 = " + (b>>2));
System.out.println("a>>>2 = " + (a>>>2));
System.out.println("b>>>2 = " + (b>>>2));
}
}
> java Example
a<<2 = 12
b<<2 = -16
a>>2 = 0
b>>2 = -1
a>>>2 = 0
b>>>2 = 1073741823
>
SHIFT OPERATOR >>> AND
AUTOMATIC ARITHMETIC PROMOTION
byte a = 3; // 00000011 = 3
byte b = -4; // 11111100 = -4
byte c;
c = (byte) a >>> 2
c = (byte) b >>> 2
>>>
Right
Fill 0
a 00000011 3
a >>> 2 00000000000000000000000000000000 0
c = (byte) 00000000 0
b 11111100 -4
b >>> 2 00111111111111111111111111111111 1073741823
c = (byte) Much to big for byte 11111111 -1
OTHER OPERATORS
CONDITIONAL OPERATORS
 General form:
expr1? expr2 : expr3
where:
1) expr1 is of type boolean
2) expr2 and expr3 are of the same type If expr1 is true,
expr2 is evaluated, otherwise expr3 is evaluated.
EXAMPLE: CONDITIONAL OPERATOR
OPERATOR PRECEDENCE
 Java operators are assigned precedence order.
 Precedence determines that the expression
1 + 2 * 6 / 3 > 4 && 1 < 0
is equivalent to
(((1 + ((2 * 6) / 3)) > 4) && (1 < 0))
 When operators have the same precedence, the earlier
one binds stronger.
OPERATOR PRECEDENCE
CLASS PARTICIPATION
1) What would be the result of running the following
program:
Class test
{public static void main(String abc[])
{
byte x=256;
System.out.println(x);
}
}
a) 256
b) Compilation Error
c) Run Time Error
CLASS PARTICIPATION
 Given a byte value of 01110111, which of the following
statements will produce 00111011?
(Note: 01110111= 0x77)
A. 0x77<<1;
B. 0x77>>>1;
C. 0x77>>1;
D. B and C
E. None of the above
52
OUTPUT??
 System.out.println (“result: “ + 3/5);
 What does it print?
 result: 0
 System.out.println (“result: “ + 5 % 3);
 What does it print?
 result: 2
 System.out.println (“result: “ + 3/5.0);
 What does it print?
 result: 0.6
 System.out.println (“result: “ + 3+4.0);
 What does it print?
 result: 34.0
 System.out.println (“result: “ + (3+4.0));
 What does it print?
 result: 7.0
Questions?

More Related Content

Similar to object oriented programming java lectures (20)

Java operators
Java operatorsJava operators
Java operators
Shehrevar Davierwala
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
Munsif Ullah
 
Operators
OperatorsOperators
Operators
loidasacueza
 
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLESPPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
merabapudc
 
Oop using JAVA
Oop using JAVAOop using JAVA
Oop using JAVA
umardanjumamaiwada
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
raksharao
 
Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
V.V.Vanniapermal College for Women
 
L3 operators
L3 operatorsL3 operators
L3 operators
teach4uin
 
L3 operators
L3 operatorsL3 operators
L3 operators
teach4uin
 
L3 operators
L3 operatorsL3 operators
L3 operators
teach4uin
 
Java Operators with Simple introduction.pptx
Java Operators with Simple introduction.pptxJava Operators with Simple introduction.pptx
Java Operators with Simple introduction.pptx
kuntadinesh21
 
OOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptx
OOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptxOOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptx
OOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptx
SrinivasGopalan2
 
BIT211_2.pdf
BIT211_2.pdfBIT211_2.pdf
BIT211_2.pdf
Sameer607695
 
Operators
OperatorsOperators
Operators
Daman Toor
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
Atul Sehdev
 
3.OPERATORS_MB.ppt .
3.OPERATORS_MB.ppt                      .3.OPERATORS_MB.ppt                      .
3.OPERATORS_MB.ppt .
happycocoman
 
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptxChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
berihun18
 
Lecture-02-JAVA, data type, token, variables.pptx
Lecture-02-JAVA, data type, token, variables.pptxLecture-02-JAVA, data type, token, variables.pptx
Lecture-02-JAVA, data type, token, variables.pptx
ChandrashekharSingh859453
 
Java unit1 b- Java Operators to Methods
Java  unit1 b- Java Operators to MethodsJava  unit1 b- Java Operators to Methods
Java unit1 b- Java Operators to Methods
SivaSankari36
 
Java Operators with Simple introduction.pptx
Java Operators with Simple introduction.pptxJava Operators with Simple introduction.pptx
Java Operators with Simple introduction.pptx
kuntadinesh21
 
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLESPPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
merabapudc
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
raksharao
 
L3 operators
L3 operatorsL3 operators
L3 operators
teach4uin
 
L3 operators
L3 operatorsL3 operators
L3 operators
teach4uin
 
L3 operators
L3 operatorsL3 operators
L3 operators
teach4uin
 
Java Operators with Simple introduction.pptx
Java Operators with Simple introduction.pptxJava Operators with Simple introduction.pptx
Java Operators with Simple introduction.pptx
kuntadinesh21
 
OOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptx
OOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptxOOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptx
OOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptx
SrinivasGopalan2
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
Atul Sehdev
 
3.OPERATORS_MB.ppt .
3.OPERATORS_MB.ppt                      .3.OPERATORS_MB.ppt                      .
3.OPERATORS_MB.ppt .
happycocoman
 
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptxChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
berihun18
 
Lecture-02-JAVA, data type, token, variables.pptx
Lecture-02-JAVA, data type, token, variables.pptxLecture-02-JAVA, data type, token, variables.pptx
Lecture-02-JAVA, data type, token, variables.pptx
ChandrashekharSingh859453
 
Java unit1 b- Java Operators to Methods
Java  unit1 b- Java Operators to MethodsJava  unit1 b- Java Operators to Methods
Java unit1 b- Java Operators to Methods
SivaSankari36
 
Java Operators with Simple introduction.pptx
Java Operators with Simple introduction.pptxJava Operators with Simple introduction.pptx
Java Operators with Simple introduction.pptx
kuntadinesh21
 

Recently uploaded (20)

From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025
Orangescrum
 
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptxwAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
Maximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdfMaximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdf
Elena Mia
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentricIntegration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Natan Silnitsky
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free DownloadWondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdfdp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage OverlookCode and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025
Orangescrum
 
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptxwAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
Maximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdfMaximizing Business Value with AWS Consulting Services.pdf
Maximizing Business Value with AWS Consulting Services.pdf
Elena Mia
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentricIntegration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Natan Silnitsky
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free DownloadWondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdfdp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage OverlookCode and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Ad

object oriented programming java lectures

  • 2. TOPICS TO BE COVERED TODAY  Array  Single & Multi-dimensional  Java Operators  Assignment  Arithmetic  Relational  Logical  Bitwise & other
  • 3. ARRAYS  An array is a group of liked-typed variables referred to by a common name, with individual variables accessed by their index.  Arrays are: 1) declared, 2) created, 3) initialized 4) used  Also, arrays can have one or several dimensions.  Array declaration involves: 1) declaring an array identifier 2) declaring the number of dimensions 3) declaring the data type of the array elements  Two styles of array declaration: type array-variable[ ]; or type [ ] array-variable;
  • 4. ARRAY CREATION  After declaration, no array actually exists.  In order to create an array, we use the new operator: type array-variable[ ]; array-variable = new type[size];  This creates a new array to hold size elements of type type, whose reference will be kept in the variable array-variable.
  • 5. ARRAY INDEXING  Later we can refer to the elements of this array through their indexes: array-variable[index]  The array index always starts with zero!  The Java run-time system makes sure that all array indexes are in the correct range, otherwise raises a run-time error.
  • 7. ARRAY INITIALIZATION  Arrays can be initialized when they are declared: int monthDays[ ] = {31,28,31,30,31,30,31,31,30,31,30,31}; Comments: 1) there is no need to use the new operator 2) the array is created large enough to hold all specified elements
  • 8. MULTI-DIMENSIONAL ARRAY  Multidimensional arrays are arrays of arrays: 1) declaration int array[ ][ ]; 2) creation int array = new int[2][3]; 3) initialization int array[ ][ ] = { {1, 2, 3}, {4, 5, 6} };
  • 10. e-Macao-16-2-134 EXERCISE: ARRAYS 1) Write a program that creates an array of 10 integers with the initial values of 3. 2) Write a Java program to find the average of a sequence of nonnegative numbers entered by the user, where the user enters a negative number to terminate the input. Assume the only method in the class is the main method. 3) What's the index of the first and the last component of a one hundred component array? 4) What will happen if you try to compile and run the following code? public class Q { public static void main(String argv[]){ int var[]=new int[5]; System.out.println(var[0]); } }
  • 11. ASSIGNMENT 01 (CLO-1, 2) (DEADLINE JANUARY 26, 2024)  Differentiate compile time vs run time errors.  Try example codes  Explore Arrays class in java.util package.  Try example codes of different methods such as binarysearch(), sort(), equals(), fill(), hashCode(), copyOf(), copyOfRange(), ….  These methods are overloaded.  Visit the following link for help : https://www.geeksforgeeks.org/array-class-in-java/ Prepare Array Class for Quiz, it will be taken after assignment submission.
  • 12. JAVA OPERATORS  Java operators are used to build value expressions.  Java provides a rich set of operators: 1) assignment 2) arithmetic 3) relational 4) logical 5) bitwise 6) other
  • 13. OPERATORS AND OPERANDS  Each operator takes one, two or three operands: 1) a unary operator takes one operand j++; 2) a binary operator takes two operands i = j++; 3) a ternary operator requires three operands i = (i>12) ? 1 : i++;
  • 14. ASSIGNMENT OPERATOR  A binary operator: variable = expression;  It assigns the value of the expression to the variable.  The types of the variable and expression must be compatible.  The value of the whole assignment expression is the value of the expression on the right, so it is possible to chain assignment expressions as follows: ◦ int x, y, z; ◦ x = y = z = 2;
  • 15. ARITHMETIC OPERATORS  Java supports various arithmetic operators for: 1) integer numbers 2) floating-point numbers  There are two kinds of arithmetic operators: 1) basic: addition, subtraction, multiplication, division and modulo 2) shortcut: arithmetic assignment, increment and decrement
  • 17. SIMPLE ARITHMETIC public class Example { public static void main(String[] args) { int j, k, p, q, r, s, t; j = 5; k = 2; p = j + k; q = j - k; r = j * k; s = j / k; t = j % k; System.out.println("p = " + p); System.out.println("q = " + q); System.out.println("r = " + r); System.out.println("s = " + s); System.out.println("t = " + t); } } > java Example p = 7 q = 3 r = 10 s = 2 t = 1 >
  • 18. ARITHMETIC ASSIGNMENT / SHORTHAND OPERATOR
  • 19. SHORTHAND OPERATOR public class Example { public static void main(String[] args) { int j, p, q, r, s, t; j = 5; p = 1; q = 2; r = 3; s = 4; t = 5; p += j; q -= j; r *= j; s /= j; t %= j; System.out.println("p = " + p); System.out.println("q = " + q); System.out.println("r = " + r); System.out.println("s = " + s); System.out.println("t = " + t); } } > java Example p = 6 q = -3 r = 15 s = 0 t = 0 >
  • 20. INCREMENT/ DECREMENT OPERATORS  Two unary operators: 1) ++ increments its operand by 1 2) -- decrements its operand by 1  The operand must be a numerical variable.  Each operation can appear in two versions: • prefix version evaluates the value of the operand after performing the increment/decrement operation • postfix version evaluates the value of the operand before performing the increment/decrement operation
  • 22. INCREMENT AND DECREMENT public class Example { public static void main(String[] args) { int j, p, q, r, s; j = 5; p = ++j; // j = j + 1; p = j; System.out.println("p = " + p); q = j++; // q = j; j = j + 1; System.out.println("q = " + q); System.out.println("j = " + j); r = --j; // j = j -1; r = j; System.out.println("r = " + r); s = j--; // s = j; j = j - 1; System.out.println("s = " + s); } } > java example p = 6 q = 6 j = 7 r = 6 s = 6 >
  • 23. RELATIONAL OPERATOR  Relational operators determine the relationship that one operand has to the other operand, specifically equality and ordering.  The outcome is always a value of type boolean.  They are most often used in branching and loop control statements.
  • 25. RELATIONAL OPERATOR EXAMPLES public class Example { public static void main(String[] args) { int p =2; int q = 2; int r = 3; System.out.println("p < r " + (p < r)); System.out.println("p > r " + (p > r)); System.out.println("p == q " + (p == q)); System.out.println("p != q " + (p != q)); } } > java Example p < r true p > r false p == q true p != q false >
  • 26. LOGICAL OPERATORS  Logical operators act upon boolean operands only.  The outcome is always a value of type boolean.  In particular, logical operators occur in two forms: 1) full op1 & op2 and op1 | op2 where both op1 and op2 are evaluated 2) short-circuit - op1 && op2 and op1 || op2 where op2 is only evaluated if the value of op1 is insufficient to determine the final outcome
  • 28. LOGICAL (&&) OPERATOR EXAMPLES public class Example { public static void main(String[] args) { boolean t = true; boolean f = false; System.out.println("f && f " + (f && f)); System.out.println("f && t " + (f && t)); System.out.println("t && f " + (t && f)); System.out.println("t && t " + (t && t)); } } > java Example f && f false f && t false t && f false t && t true >
  • 29. LOGICAL (||) OPERATOR EXAMPLES public class Example { public static void main(String[] args) { boolean t = true; boolean f = false; System.out.println("f || f " + (f || f)); System.out.println("f || t " + (f || t)); System.out.println("t || f " + (t || f)); System.out.println("t || t " + (t || t)); } } > java Example f || f false f || t true t || f true t || t true >
  • 30. LOGICAL (!) OPERATOR EXAMPLES public class Example { public static void main(String[] args) { boolean t = true; boolean f = false; System.out.println("!f " + !f); System.out.println("!t " + !t); } } > java Example !f true !t false >
  • 31. LOGICAL OPERATOR EXAMPLES SHORT CIRCUITING WITH && public class Example { public static void main(String[] args) { boolean b; int j, k; j = 0; k = 0; b = ( j++ == k ) && ( j == ++k ); System.out.println("b, j, k " + b + ", " + j + ", " + k); j = 0; k = 0; b = ( j++ != k ) && ( j == ++k ); System.out.println("b, j, k " + b + ", " + j + ", " + k); } } > java Example b, j, k true 1, 1 > java Example b, j, k true 1, 1 b, j, k false 1, 0 >
  • 32. LOGICAL OPERATOR EXAMPLES SHORT CIRCUITING WITH || public class Example { public static void main(String[] args) { boolean b; int j, k; j = 0; k = 0; b = ( j++ == k ) || ( j == ++k ); System.out.println("b, j, k " + b + ", " + j + ", " + k); j = 0; k = 0; b = ( j++ != k ) || ( j == ++k ); System.out.println("b, j, k " + b + ", " + j + ", " + k); } } > java Example b, j, k true 1, 0 > java Example b, j, k true 1, 0 b, j, k true 1, 1 >
  • 35. BITWISE OPERATORS  Bitwise operators apply to integer types only.  They act on individual bits of their operands.  There are three kinds of bitwise operators: 1) basic bitwise AND, OR, NOT and XOR 2) shifts left, right and right-zero-fill
  • 37. TWOS COMPLEMENT NUMBERS Base 10 A byte of binary +127 01111111 +4 00000100 +3 00000011 +2 00000010 +1 00000001 +0 00000000 -1 11111111 -2 11111110 -3 11111101 -4 11111100 -128 10000000
  • 38. LOGICAL OPERATORS (BIT LEVEL) & | ^ ~ int a = 10; // 00001010 = 10 int b = 12; // 00001100 = 12 a 00000000000000000000000000001010 10 b 00000000000000000000000000001100 12 a & b 00000000000000000000000000001000 8 a 00000000000000000000000000001010 10 b 00000000000000000000000000001100 12 a | b 00000000000000000000000000001110 14 a 00000000000000000000000000001010 10 b 00000000000000000000000000001100 12 a ^ b 00000000000000000000000000000110 6 a 00000000000000000000000000001010 10 ~a 11111111111111111111111111110101 -11 & AND | OR ^ XOR ~ NOT
  • 39. LOGICAL (BIT) OPERATOR EXAMPLES public class Example { public static void main(String[] args) { int a = 10; // 00001010 = 10 int b = 12; // 00001100 = 12 int and, or, xor, na; and = a & b; // 00001000 = 8 or = a | b; // 00001110 = 14 xor = a ^ b; // 00000110 = 6 na = ~a; // 11110101 = -11 System.out.println("and " + and); System.out.println("or " + or); System.out.println("xor " + xor); System.out.println("na " + na); } } > java Example and 8 or 14 xor 6 na -11 >
  • 40. SHIFT OPERATORS (BIT LEVEL) << >> >>> • Shift Left << Fill with Zeros • Shift Right >> Based on Sign • Shift Right >>> Fill with Zeros
  • 41. SHIFT OPERATORS << >> int a = 3; // ...00000011 = 3 int b = -4; // ...11111100 = -4 a 00000000000000000000000000000011 3 a << 2 00000000000000000000000000001100 12 b 11111111111111111111111111111100 -4 b << 2 11111111111111111111111111110000 -16 << Left >> Right a 00000000000000000000000000000011 3 a >> 2 00000000000000000000000000000000 0 b 11111111111111111111111111111100 -4 b >> 2 11111111111111111111111111111111 -1
  • 42. SHIFT OPERATOR >>> int a = 3; // ...00000011 = 3 int b = -4; // ...11111100 = -4 >>> Right 0 a 00000000000000000000000000000011 3 a >>> 2 00000000000000000000000000000000 0 b 11111111111111111111111111111100 -4 b >>> 2 00111111111111111111111111111111 +big 1073741823
  • 43. SHIFT OPERATOR EXAMPLES public class Example { public static void main(String[] args) { int a = 3; // ...00000011 = 3 int b = -4; // ...11111100 = -4 System.out.println("a<<2 = " + (a<<2)); System.out.println("b<<2 = " + (b<<2)); System.out.println("a>>2 = " + (a>>2)); System.out.println("b>>2 = " + (b>>2)); System.out.println("a>>>2 = " + (a>>>2)); System.out.println("b>>>2 = " + (b>>>2)); } } > java Example a<<2 = 12 b<<2 = -16 a>>2 = 0 b>>2 = -1 a>>>2 = 0 b>>>2 = 1073741823 >
  • 44. SHIFT OPERATOR >>> AND AUTOMATIC ARITHMETIC PROMOTION byte a = 3; // 00000011 = 3 byte b = -4; // 11111100 = -4 byte c; c = (byte) a >>> 2 c = (byte) b >>> 2 >>> Right Fill 0 a 00000011 3 a >>> 2 00000000000000000000000000000000 0 c = (byte) 00000000 0 b 11111100 -4 b >>> 2 00111111111111111111111111111111 1073741823 c = (byte) Much to big for byte 11111111 -1
  • 46. CONDITIONAL OPERATORS  General form: expr1? expr2 : expr3 where: 1) expr1 is of type boolean 2) expr2 and expr3 are of the same type If expr1 is true, expr2 is evaluated, otherwise expr3 is evaluated.
  • 48. OPERATOR PRECEDENCE  Java operators are assigned precedence order.  Precedence determines that the expression 1 + 2 * 6 / 3 > 4 && 1 < 0 is equivalent to (((1 + ((2 * 6) / 3)) > 4) && (1 < 0))  When operators have the same precedence, the earlier one binds stronger.
  • 50. CLASS PARTICIPATION 1) What would be the result of running the following program: Class test {public static void main(String abc[]) { byte x=256; System.out.println(x); } } a) 256 b) Compilation Error c) Run Time Error
  • 51. CLASS PARTICIPATION  Given a byte value of 01110111, which of the following statements will produce 00111011? (Note: 01110111= 0x77) A. 0x77<<1; B. 0x77>>>1; C. 0x77>>1; D. B and C E. None of the above
  • 52. 52 OUTPUT??  System.out.println (“result: “ + 3/5);  What does it print?  result: 0  System.out.println (“result: “ + 5 % 3);  What does it print?  result: 2  System.out.println (“result: “ + 3/5.0);  What does it print?  result: 0.6  System.out.println (“result: “ + 3+4.0);  What does it print?  result: 34.0  System.out.println (“result: “ + (3+4.0));  What does it print?  result: 7.0