SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
4.1 Object Operations
4.1.1 operators
•   Dot ( . ) and new operate on objects
•   The assignment operator ( = )
•   Arithmetic operators + - * / %
•   Unary operators ++, --, *=, %=
•   Operator precedence
•   Arithmetic expressions are left associative
•   Assignment operators are right associative
4.2.6 Boolean data and comparison
            operators
• boolean values are true or false ( not 1 or 0)
• Less than <, greater than >, equal to ==, less
  than or equal to <=, greater than or equal to >=,
  not equal !=
• AND &, OR |, XOR ^
• Short curcuit AND &&, OR ||
4.2.8 Conditional operator
• Alternative for if - else

y = x > 4 ? 99: 9;
Is the same as:
if(x > 4)
    y = 99;
else
    y = 9;
4.2.9 Bitwise operators
• Perform shifting of bits on integral types,
  preferably int of long
• <<3 shifts all bits left 3 places. All new bits are 0
• >>>3 shifts all bits right 3 places. All new bits
  are 0
• >>3 shifts all bits right 3 places. The new bits
  are the same as the most significant bit before
  the shift.
4.3.1 Casting and conversion
• Casting assigns a value of one type to a
   variable of another type
• If it is possible to lose information, an explicit
   cast is required
long bigValue = 99L;
int squashed = (int)bigValue;
4.4.2 String and StringBuffer class
• The String object can be used to store an
  arbitrary number of textual characters
• Strings are immutable: They do not change
• Concatenating two Strings results in the
  creation of another String
• Use StringBuffer to hold Strings that will
  change
4.5.1 Decision making and
              repetition
• Control structures control the flow of statement
  execution
• Three control structures: Sequence, selection
  or decision, repetition
• In OOP, control structures exist within methods
  only
• Selection control structure provides conditional
  execution (if-else)
• Repitition control structure causes the computer
  to repeat certain actions (for <loop>, while
  <loop>, do <loop>)
4.5.3 If statement
• Basic
if(x == 3) {
   System.out.println(“x equals 3”);
   }
else {
   System.out.println(“x does not equal 3”);
   }
4.5.4 Multiple condition If
• Multiple condition
if(a < b) {
   System.out.println(“a is less than b”);
}
else if (a < c) {
   System.out println(“a is less than c”);
}
else {
   System.out.println(“a is not less than b or c”);
}
4.5.5 Nested if
• Nested If
if(x == 3) {
   System.out.println(“x equals 3”);
   if( y == 4) {
      System.out.println(“ …and y equals 4”);
      }
   }
else {
   System.out.println(“x does not equal 3”);
   }
4.5.6 Switch statements
•     A conditional control structure that allows a value to be compared to
      more than one other value
switch(test) {
    case 1:
      System.out.println(“test equals 1”);
      break;
    case 2:
      System.out.println(“test equals 2”);
      break;
     case 3:
      System.out.println(“test equals 3”);
      break;
    default:
      System.out.println(“test does not equal 1, 2 or 3”);
      break;
}
4.5.7 Loop
• do while: Execution loops. Conditional
  evaluation at the end of the loop
• while: Execution loops through the block.
  Conditional evaluation occurs at the start of the
  loop
• for next: Specifies an initialization block, a
  conditional evaluation and a block that is
  executed in every loop
4.5.11 Use of break, continue, and
               label
• break is used to exit a block
• continue is used to return to the start of the loop
• label can be applied to a statement or block,
  then used with continue or break
• break can be used to exit a labeled block
• continue can be used to resume at a statement
4.6.1 The java.lang.System class

Más contenido relacionado

La actualidad más candente (19)

Array sorting
Array sortingArray sorting
Array sorting
 
3.3 shell sort
3.3 shell sort3.3 shell sort
3.3 shell sort
 
Sorting techniques
Sorting techniquesSorting techniques
Sorting techniques
 
Sorting
SortingSorting
Sorting
 
Selection sort
Selection sortSelection sort
Selection sort
 
It elective cs366-barizo-shell
It elective cs366-barizo-shellIt elective cs366-barizo-shell
It elective cs366-barizo-shell
 
Ora faq
Ora faqOra faq
Ora faq
 
The selection sort algorithm
The selection sort algorithmThe selection sort algorithm
The selection sort algorithm
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
 
single linked list
single linked listsingle linked list
single linked list
 
Selection sort
Selection sortSelection sort
Selection sort
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Selection Sort - Vipin Ramola
Selection Sort - Vipin RamolaSelection Sort - Vipin Ramola
Selection Sort - Vipin Ramola
 
Sorting
SortingSorting
Sorting
 
Ifi7107 lesson4
Ifi7107 lesson4Ifi7107 lesson4
Ifi7107 lesson4
 
Linked List
Linked ListLinked List
Linked List
 
Implementing Merge Sort
Implementing Merge SortImplementing Merge Sort
Implementing Merge Sort
 
shell and merge sort
shell and merge sortshell and merge sort
shell and merge sort
 
Algorithms Analysis
Algorithms Analysis Algorithms Analysis
Algorithms Analysis
 

Destacado (6)

Chapter2 bag2
Chapter2 bag2Chapter2 bag2
Chapter2 bag2
 
Chapter1
Chapter1Chapter1
Chapter1
 
Chapter3 bag1
Chapter3 bag1Chapter3 bag1
Chapter3 bag1
 
Chapter3 bag2
Chapter3 bag2Chapter3 bag2
Chapter3 bag2
 
Chapter2 bag1
Chapter2 bag1Chapter2 bag1
Chapter2 bag1
 
Chapter1
Chapter1Chapter1
Chapter1
 

Similar a Chapter4

Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysDevaKumari Vijay
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statementsVladislav Hadzhiyski
 
Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...
Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...
Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...FabMinds
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming LanguageAhmad Idrees
 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#Rohit Rao
 
CSC111-Chap_03.pdf
CSC111-Chap_03.pdfCSC111-Chap_03.pdf
CSC111-Chap_03.pdf2b75fd3051
 
Rule Modularity and Execution Control
Rule Modularity and Execution ControlRule Modularity and Execution Control
Rule Modularity and Execution ControlMark Proctor
 
Operating system 23 process synchronization
Operating system 23 process synchronizationOperating system 23 process synchronization
Operating system 23 process synchronizationVaibhav Khanna
 
Pi j1.3 operators
Pi j1.3 operatorsPi j1.3 operators
Pi j1.3 operatorsmcollison
 
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdfBasic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdfComputer Programmer
 
Repetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniquesRepetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniquesJason J Pulikkottil
 

Similar a Chapter4 (20)

Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statements
 
Arrays
ArraysArrays
Arrays
 
matrices_and_loops.pptx
matrices_and_loops.pptxmatrices_and_loops.pptx
matrices_and_loops.pptx
 
Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...
Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...
Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control S...
 
Md04 flow control
Md04 flow controlMd04 flow control
Md04 flow control
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
 
Slide 6_Control Structures.pdf
Slide 6_Control Structures.pdfSlide 6_Control Structures.pdf
Slide 6_Control Structures.pdf
 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#
 
Java data types
Java data typesJava data types
Java data types
 
CSC111-Chap_03.pdf
CSC111-Chap_03.pdfCSC111-Chap_03.pdf
CSC111-Chap_03.pdf
 
Rule Modularity and Execution Control
Rule Modularity and Execution ControlRule Modularity and Execution Control
Rule Modularity and Execution Control
 
Operating system 23 process synchronization
Operating system 23 process synchronizationOperating system 23 process synchronization
Operating system 23 process synchronization
 
control structure
control structurecontrol structure
control structure
 
Pi j1.3 operators
Pi j1.3 operatorsPi j1.3 operators
Pi j1.3 operators
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdfBasic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
 
Repetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniquesRepetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniques
 
Critical section operating system
Critical section  operating systemCritical section  operating system
Critical section operating system
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
 

Más de teknik komputer ui (20)

Modul 1
Modul 1Modul 1
Modul 1
 
Modul 5
Modul 5Modul 5
Modul 5
 
Modul 4
Modul 4Modul 4
Modul 4
 
Modul 3
Modul 3Modul 3
Modul 3
 
Modul 1
Modul 1Modul 1
Modul 1
 
Modul 2
Modul 2Modul 2
Modul 2
 
The cisco networking academy net riders indonesia 2010 competition
The cisco networking academy net riders indonesia 2010 competitionThe cisco networking academy net riders indonesia 2010 competition
The cisco networking academy net riders indonesia 2010 competition
 
Rencana Proyek Divisi Komputer.doc
Rencana Proyek Divisi Komputer.docRencana Proyek Divisi Komputer.doc
Rencana Proyek Divisi Komputer.doc
 
Salinan Research Paper
Salinan Research PaperSalinan Research Paper
Salinan Research Paper
 
Chapter_1_Case_Study
Chapter_1_Case_StudyChapter_1_Case_Study
Chapter_1_Case_Study
 
Iins practice questions
Iins practice questionsIins practice questions
Iins practice questions
 
S1 intr ftui
S1 intr ftuiS1 intr ftui
S1 intr ftui
 
Exploration network chapter7
Exploration network chapter7Exploration network chapter7
Exploration network chapter7
 
Exploration network chapter6
Exploration network chapter6Exploration network chapter6
Exploration network chapter6
 
Exploration network chapter5
Exploration network chapter5Exploration network chapter5
Exploration network chapter5
 
Exploration network chapter4
Exploration network chapter4Exploration network chapter4
Exploration network chapter4
 
Exploration network chapter3
Exploration network chapter3Exploration network chapter3
Exploration network chapter3
 
Exploration network chapter2
Exploration network chapter2Exploration network chapter2
Exploration network chapter2
 
Exploration network chapter1
Exploration network chapter1Exploration network chapter1
Exploration network chapter1
 
Exploration network chapter11
Exploration network chapter11Exploration network chapter11
Exploration network chapter11
 

Chapter4

  • 2. 4.1.1 operators • Dot ( . ) and new operate on objects • The assignment operator ( = ) • Arithmetic operators + - * / % • Unary operators ++, --, *=, %= • Operator precedence • Arithmetic expressions are left associative • Assignment operators are right associative
  • 3. 4.2.6 Boolean data and comparison operators • boolean values are true or false ( not 1 or 0) • Less than <, greater than >, equal to ==, less than or equal to <=, greater than or equal to >=, not equal != • AND &, OR |, XOR ^ • Short curcuit AND &&, OR ||
  • 4. 4.2.8 Conditional operator • Alternative for if - else y = x > 4 ? 99: 9; Is the same as: if(x > 4) y = 99; else y = 9;
  • 5. 4.2.9 Bitwise operators • Perform shifting of bits on integral types, preferably int of long • <<3 shifts all bits left 3 places. All new bits are 0 • >>>3 shifts all bits right 3 places. All new bits are 0 • >>3 shifts all bits right 3 places. The new bits are the same as the most significant bit before the shift.
  • 6. 4.3.1 Casting and conversion • Casting assigns a value of one type to a variable of another type • If it is possible to lose information, an explicit cast is required long bigValue = 99L; int squashed = (int)bigValue;
  • 7. 4.4.2 String and StringBuffer class • The String object can be used to store an arbitrary number of textual characters • Strings are immutable: They do not change • Concatenating two Strings results in the creation of another String • Use StringBuffer to hold Strings that will change
  • 8. 4.5.1 Decision making and repetition • Control structures control the flow of statement execution • Three control structures: Sequence, selection or decision, repetition • In OOP, control structures exist within methods only • Selection control structure provides conditional execution (if-else) • Repitition control structure causes the computer to repeat certain actions (for <loop>, while <loop>, do <loop>)
  • 9. 4.5.3 If statement • Basic if(x == 3) { System.out.println(“x equals 3”); } else { System.out.println(“x does not equal 3”); }
  • 10. 4.5.4 Multiple condition If • Multiple condition if(a < b) { System.out.println(“a is less than b”); } else if (a < c) { System.out println(“a is less than c”); } else { System.out.println(“a is not less than b or c”); }
  • 11. 4.5.5 Nested if • Nested If if(x == 3) { System.out.println(“x equals 3”); if( y == 4) { System.out.println(“ …and y equals 4”); } } else { System.out.println(“x does not equal 3”); }
  • 12. 4.5.6 Switch statements • A conditional control structure that allows a value to be compared to more than one other value switch(test) { case 1: System.out.println(“test equals 1”); break; case 2: System.out.println(“test equals 2”); break; case 3: System.out.println(“test equals 3”); break; default: System.out.println(“test does not equal 1, 2 or 3”); break; }
  • 13. 4.5.7 Loop • do while: Execution loops. Conditional evaluation at the end of the loop • while: Execution loops through the block. Conditional evaluation occurs at the start of the loop • for next: Specifies an initialization block, a conditional evaluation and a block that is executed in every loop
  • 14. 4.5.11 Use of break, continue, and label • break is used to exit a block • continue is used to return to the start of the loop • label can be applied to a statement or block, then used with continue or break • break can be used to exit a labeled block • continue can be used to resume at a statement