Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

OBJECT ORIENTED PROGRAMMING, Summaries of Object Oriented Programming

CSC 235 summary handout to read and understand with point taken

Typology: Summaries

2020/2021

Available from 09/04/2021

Segungabriel
Segungabriel 🇳🇬

2 documents

Partial preview of the text

Download OBJECT ORIENTED PROGRAMMING and more Summaries Object Oriented Programming in PDF only on Docsity! Object Oriented Programming Prof. S. O. Akinola Fundamental Principles of Programming In this Lecture, the basic principles of programming are explained. We start by defining the word ‘programming’ and then the various tools needed for writing programs are discussed. Steps of programming as well as programming tools are also discussed. Good programming styles are not left out in this Lecture. The criteria for judging good programs concludes the Lecture. Is Programming an Art or a Science or Both? = Programming is on one hand an artistic or creative endeavour, and on other hand, a scientific endeavour. » As a scientist, the programmer begins with a clearly defined set of principles, or axioms of programming. = He or she then applies them systematically to a problem, in such way that at any stage in the process the (mathematical) correctness of the program can be routinely demonstrated. » For instance, in testing our programs and their designs, scientific approaches are usually employed. Programming as an Art = As an artist, the programmer begins with an understanding of the medium or application area. =The art of programming seems therefore to be the development of creative solutions to problems, so that the overall quality of activity within that application area will be enhanced. = For example, the aspect of user interface, data structure and program module designs are artistic or creative in nature. = You must be creative to design an interface that is usable by and fascinating to users of your programs. Programming is both scientific and artistic = These two philosophies of programming have some implications. » The art of programming demands a variety of “tools” or a “programming environment” within which the total process of program development can take place. ™ The science philosophy demands a language, which supports the axiomatic proof of program behaviour Algorithms = An algorithm literarily means the step-by-step procedure of solving a problem. Technically, it is defined as a finite solution steps to a problem. As a matter of fact, an algorithm must have the following properties: (i)Finiteness: It must have a terminating point after some points. (ii)Definiteness: It must be clear and unambiguous. (iii)Input: It must have allowable set of data input to the system. (iv)Output: It must properly define the nature of result expected; that is, the format. (v)Efficiency: Its implementation must be space (memory) and time efficient. Illustration: suppose we want to add some numbers together continuously until when we encounter any negative data, which shall terminate the addition. In addition, we also want to report the total number of valid data added so far before the program halts. = The Algorithm: 1. Set up a counter, count = @ 1. Initialize an accumulator, sum = @ 1. Read in data, d 1. If (d = 0) then 5. Sum = sum + d 6. Count = count + 1 7. Goto 3 8. Else 9. Print out Results, Sum, Count 10. Terminate The Flowchart: Print cut Results, sum, count Sum = sum + d Count = count + 1 4/30/202 Steps of Programming ... Step 2. Designing algorithm for the problem. A suitable algorithm is designed for the problem in question, such as was done in section 1.6.2. Step 3. Testing the correctness of the algorithm. The algorithm developed has to be desk-checked or dry-run line by line to make sure it solve the problem accurately. Step 4. Translating the algorithm into a suitable programming language. The tested algorithm is now coded with a suitable programming language. Step 5. Testing and executing the program. The program developed is compiled and executed. The program must be tested with different kinds of data, valid and invalid to make sure that it can work properly in all data input conditions. Steps of Programming ... Step 6. Documenting the program. ™ Documentation is very essential in programming. ™ We have two types — internal and external. ™ Internal documentation involves putting comments and white spaces in our program source codes. ™ (hey are there to introduce the functionality of the program as well as to introduce the different sections of the code for readability and maintenance of the code. ™ External documentation are in form of a manual for operating and maintaining the program by any user of the program. ™ The user will specify the functionality of the program, inputs and their formats, expected outputs and their formats, operating instructions for the program, etc. ™ To maintain any code, the documentation on the code will have to be consulted first. 50/0 Good Programming Style Choose appropriate names for your variables. m The names you use for your variables should be meaningful and suggest clearly the purpose of the variable. m® They should communicate what the variable is meant for at least. » For example, Area_of_Rect suggests that the variable is for the ea of arectangle. For a program to work properly, it is of Utmost importance to know exactly what each variable represents, and to know exacily what each subprograms must be included with their names chosen with care to identify their meanings clearly. Good Programming Style ... = Modularize the program for easy maintenance. The program should be broken down into various functional Units. This is achieved through the use of subroutines and functions in programs. = Appropriate documentation formats such as comments and white spaces (blank lines) must be used in the program. The white spaces separate the program into logical functional sections for ease of debugging and maintenance. » Test the program with different sets of data (both valid and invalid) to ascertain that the program is error-free. Errors in Programming = Syntax error: This error occurs when the grammatical rules of the programming language in use is not followed. For instance, if we misspelt a keyword, or we don't put semi-colon at the appropriate places, syntax errors OCCur. = Semantic error: By semantics we mean attaching meanings to program statements. w/lherefore a semantic error occurs if the compiler cannot attach meaning to a program statement. For instance, if we are trying To assign a floating-point value to an integer location, or we are trying to divide a value by zero. m Another example is when data listed as parameters in a function are of different types from those listed in the calling program; or the name of the function is different from the one used To call it fram. the main program. Errors in Programming ... Logic Error: ® This error is Usually committed by programmers. ® The program will definitely compile and run very well but the output will not be correct. ® For instance, if we supposed to use <= in our statement but we now use < without the equal (=) symbol attached, then logic error will occur when it comes to a stage fo test for equality in the statement. What will happen is that the program will not test and generate result for this case of equality and error thus occurred. This is due to the fact that the programmer has used a wrong logic somewhere in the program. Infinite looping is a serious case of logic errors in programs. To resolve this error, the programmer has to go back to the program and check all important sections of the code for logic correctness. Programming languages High level languages ® Today, most programs are written in high level languages, which resemble English and are therefore easier to use than machine code, ™ But they have a limited, specialised vocabulary and a simple syntax free from ambiguity. High level language instructions are not executable. Instead, a high level language source program is read as input by a program called a compiler, which checks its syntax ® if it is free from errors, compiles an equivalent machine code object program. ® |f the source program contains syntax errors, the compiler outputs a number of messages indicating the nature of the errors and where they occur. Categories of Programming Languages ™ Basically, we have many categories of programming languages such as imperative versus non-imperative, functional versus non-functional, object versus procedural, scientific versus non-scientific languages, etc. A more generic categorization is as follows: (a)High Level Languages: These programming languages are English-like, user-friendly, non-machine dependent and take less effort and time in coding. Examples are the common programming languages found around such as COBOL, C++, C, Java, FORTRAN, etc. (a)Assembly language: These languages are in form of mnemonics (symbolic codes). They are more or less English-like but they are full of abbreviations. User-friendliness is somehow low compared to the high level languages. Assembly languages are in between the high level and machine languages. They are machine dependent in the sense that one has to be familiar with the instruction sets of the computer before we can write an Assembly code for, it. Categories of Programming Languages ... = Low Level / Machine Language: This is the native language of the computer. ™ Programming is done with writing of sequences of Os and Is. = Computer only understands the high level (logic 1) and low level (logic 0) signals. ®So, to program in machine language of the blessed memory, one has to be conversant with bits representation of characters and symbols to use. = For example, Capital letter A, whose ASCII codeword is 65 is encoded as 1000001 in binary. To code A, the binary representation is encoded. m™ Machine languages are highly machine dependent. pecenine code for Motorola machines is different trom that of Pentium. Loosely Typed or Typeless Languages: ® In these types of languages, variables declared can assume any value depending on the context of usage. ® The variables have multiple or dynamic usages. m In PHP, we can declare a variable $Name and be assigned a value 3.4. ® This means that $Name is a floating-point or real variable. At latter time, if we assign to it “Akinola”, this assignment has changed its data type to a string value. ® The same variable is used in different contexts. ® In other words, the data types of variables depend on their present assignmenis. ™ These languages are highly case sensitive. Structured Programming Paradigm = Structured programming is an approach that breaks a program into logical sections, called modules, in such a way as to minimize the program’s complexity. ™ In other words, modularity of programs’ source code is the essence of structured programming. A _ structured program is assified as readable program. ™ Structured programming is a way of ensuring that subsidiary sections are arranged in such a way that they can be worked on, truly independently, that is, without reference to other parts of the program. Structured Programming Paradigm ... ™ Each section can be tested and debugged as it is completed; thus, considerably enhancing the chances of obtaining a working program. ™In addition, if problems do occur, they can be isolated and found very more easily than in a single complete (monolithic) program. ™ It is usually only necessary to correct code in the section in which the problem occurred so that re-programming can also be minimized. Approaches to Structured Program Design ... mSecond, we evaluate each module to make sure that its implementation is feasible, given the system's environment constraints. = Generally, program design performs two functions: m Decision as to what data structures to use in implementing a system is best handled by program design. mlt also provides more details about algorithms. For example, system design specification may be that a module is to sort a list; program design then identifies what sorting algorithm to use for this task. Approaches to Program Design ... 1. Top-down Approach ™ This is also called modular design and it encompasses the concept of stepwise refinement. ™ We examine and analyze the problem from the highest or more general level to a more detailed level. ™ This means that a top down analysis examines all modules but first ranslate higher levels to more concrete program specifications before descending to lower levels. ™ At any point, only data and control information with structures necessary for a module are defined. ™ The details of the design at lower levels remain hidden. In this way, as little codes as possible need to be written. ® This allows an error in the design of the program to be corrected before too much time or work has been spent on trying to implement it. The essential elements of top-down design are: e Design the program in levels or modules. e It must be initial language-independent. e Postponement of details to the lower level. e Defining the interface with the lower level. e Verification of each module as it is written Bottom-up Approach ... ® Finally, we build all these routines from the bottom up into a complete system. ™ However, coupling among modules usually increases, since more control mechanisms are needed and since more data may be passed or shared by modules. ® This increased coupling makes detecting and correcting an error or changing a function latter in the life of the system much more difficult. ® In addition, it is sometimes hard to maintain the degree of information hiding originally designed into the system. ™ Consequently, bottom-up approach is employed only when its advantages outweigh these disadvantages. Criteria for Judging a Program ® The following yardsticks are normally used to judge if a program is good or not: » Problem Solvability: Does the program solve the problem as requested, that is, according to the given specifications? » Workability: Does the program work Under all conditions? » Sufficient Information: Does it include clear and sufficient information for its users in form of instructions and documentations? ® Logically Written: Is the program logically and clearly written, with short modules and subprograms as appropriate? = Time and Space Efficient: Does it make efficient use of time and space? 2: Java Programming Basics ® Java is an Object Oriented programming language with a relatively simple grammar. ® Java omits rarely used, poorly understood, confusing features of C++ such as header files, pointer arithmetic, structures, unions, operator overloading, and templates. ® Java also adds new features like automatic garbage collection. wAll methods, fields and constructors are local to classes—that is, there is no global data. Java supports static methods and fields, exception handling, inheritance, and control structures such as while loops, for loops and if/else statemenis. ® In this Lecture, the basic principles of writing and executing program codes in Java language are discussed. ® We begin by introducing you to writing codes in the language The Java Language... ® In the Java programming language, all source code is first written in plain text files ending with the java extension. m Those source files are then compiled into .class files by the javac compiler. » A .class file does not contain code that is native to your processor; it instead contains bytecodes - the machine language of the Java Virtual Machine (Java VM). ® The java launcher tool then runs your application with an instance of the Java Virtual Machine. igure below shows the process of translating java programs from the high level state to the understanding level of the machine. ompiler Ze gq 0100101... | ee oe MyProgram. java MyProgram.class My Program 30/202 The Java Platform ® A platform is the hardware or software environment in which a program runs. = Most popular platforms: Microsoft Windows, Linux, Solaris OS, and Mac OS. ™ Most platforms can be described as a combination of the operating system and underlying hardware. ™ The Java platform differs from most other platforms in that it's a software - only platform that runs on top of other hardware-based platforms. ™ The Java platform has two components: a The Java Virtual Machine a The Java Application Programming Interface (API) ™ The Java Virtual Machine is the base for the Java platform and is ported onto various hardware-based platforms. ™ The API is a large collection of ready-made software components that provide many useful capabilities. It is grouped into libraries of related classes and interfaces; these libraries are known as packages. Creating and Running a Java Program ® First, the Java toolkit is downloaded and installed on the computer. ® The Java Development Kit (JDK), officially named "Java Platform Standard Edition” or “Java SE", is needed for writing Java programs. ® The JDK is freely available from Sun Microsystems (now part of Oracle). The mother site for JDK (Java SE) is http://www.oracle.com/technetwork/java/javase/overview/index.html. DK" or "JRE"? m® JRE (Java Runtime) is needed for running Java programs. ® JDK (Java Development Kit), which includes JRE plus the development tools (such as compiler and debugger), is needed for writing as well as running Java programs. ® \Inother words, JRE is a subset of JDK. m Since you are supposed to write Java Programs, you should install JDK, which includes JRE 0/20 Writing your first program ® A simple Java code looks like this: public class Welcome { public static void main(String[] args) { System.out.printin(“Welcome to Java world”) ; } //End main method } // End class Welcome ® Note: Java is case-sensitive. Capital letters must be capitals e.g. String, System. ® The first line declares a class named Welcome. public class Welcome { ® This line could be regarded as the header of the program. — m Java sees a program as a class and the name of the class must be the same as the name of the file, i.e., the name you use fo save the file. m® In this case we save the file as Welcome.java. m Any nonempty string of letters and digits can be used for the class name as long as it begins with a letter and contains no blanks. public class Welcome { public static void main(String[ ] args) { System.out.printin(“Welcome to Java world”) ; } //End main method } // End class Welcome ™ The second line begins with the left brace character; just like BEGIN in Pascal. > The e must be a corresponding right brace at the last line of the program, . representing END as in Pascal. m/The two braces form the program block, which encloses the program's body. public static void main(String[ ] args) { public class Welcome { public static void main(String[ ] args) { System.out.printin(“Welcome to Java world”) ; } //End main method } // End class Welcome e main is the name of the method being defined, just as Welcome is the name of the class being defined. e parenthesized string following main forms the parameter list for the main method, which are local variables used to transmit information to the method from the outside world; (String[ ] args). e It states that this method has one parameter, its name is args and it is an array of string objects. e The implication of the args parameter is that all data that will be read into the main method are all string array by default. public class Welcome { public static void main(String[ ] args) { System.out.printin(“Welcome to Java world”) ; } //End main method } // End class Welcome e That is why parsing of data read into necessary types is needed when we read the data via keyboard into Java programs. e For instance we write : » int x = input.nextInt( ); // The nextInt( ) converts of parse data read //into integer type int x = Integer.parseInt(y); // The parseInt( ) converts or parse y // into integer type and assign it to variable x public class Welcome { public static void main(String[ ] args) { System.out.printin(“Welcome to Java world”) ; } //End main method } // End class Welcome The third line contains the single executable statement. System.out.println(“welcome to Java world’) ; ™ The message put in quotes would be printed out as they are written. e word println is the name of the method that tells the system how to do the printing, which means, after the message is printed, the cursor should move to the next line. Note the parenthesis and the semi colon usage. ™ The semi colon is a separator for each executable line. This means that you can stack two or more executable lines of codes on a single line. Semi colons are used to separate them. The two closing braces, } mark the end of the program. The first closes the main method and the other closes the class. a How the outputs will be generated from the program: ® For Line 1, a (2) and b (4) will be printed on a single line and the blinking cursor will remain at the end of that line, waiting for another printing action. ® In Line 2, c (6) will be printed after 4 on the same line with the previous printing. ®™ In Line 3, the cursor moves to next line without printing any value, since no data was given. ® In Line 4, d (8) would be printed in the second line where the cursor was before in Line 3 and after the printing, it moves to next line. ® The println( ) is a post-action function. The final output will look like below: 2 4 6 8 Inserting Comments into Your Program = Comments are very good in programs. = They enhance easy comprehension/readability of the codes, section by section and are veritable tools for future program maintenance. = Anybody can pick the code in the future and with the help of the comment lines, modifies, upgrades or corrects the program for some errors. Java embraces both C and C++ styles of comments. The C Comment’s Style = The C comment style is a multi-line style. It is used when we have several lines of comments to be inserted into programs. Take for example, /* Program written by .... Matric No... Version 1.0 Date _....... */ ™ One major problem of the C comment style is that we must ensure that the closing symbol (*/) is inserted at the end of the entire comment lines; else the compiler will assume that all other lines below the opening symbol (/*) are all comments! Note: m The Scanner has to be imported into your program, similar to #include in C or C++ language. This is done in Line 2. ® In line 5, an object of the Scanner class (input) is created. The variable/object input is user-defined. You can give any other meaningful identifier name for this object. This will serve as the anchor for receiving data from the keyboard buffer as you are entering data via the keyboard. ™ Each data type has its own format for receiving it in the program. For int data, we use input.nextint( ), for long data, use input.Long( }, for float use input.nextFloat( ), for double, use input.nextDouble( ) and for string data, use input.next( ) or input.nextLine(). ® The input.next( ) is only for one string at a time. To read many words making a string on one line, Use input.nextLine( ). The use of swing’s facility in java 1. import javax.swing.*; 2. // program to add two numbers together 3. public class Addition { 4, public static void main(String args[ ]) { 5. 6. /# Declaring your variables .. 7. String firstNumber, secondNumber; a. int numberl, number?, sum; ao. 16. f/f Reading the data... 11. firstNumber = JOptionPane.showInputDialog("Enter first Number"); 12. secondNumber = JOptionPane.showInputDialog("Enter second Number" ); 13. 14. /f Converting the data into int types 15. numberl = Integer.parseInt(firstNumber); 16. number? = Integer. parseInt({secondNumber); 17. 18. sum = numberl + number2; // Computing the sum 19. 28. JOptionPane.showessageDialog(null,"The sum is " + sum, “Result”, 21. JOptionPane.PLAIN MESSAGE); 22. system.exit(@); 23. } //end main method soo 24. } J/fend class Addition = The JOptionPane is a subclass of the swing class and has some methods or functions associated with if. One of which is the showlnputDialog used above. =The purpose of this method is to draw an input textbox, in which the user will type in his / her ata. What is typed in double quote as an argument in the method will serve as a prompt for the user to know what he is to do with the textbox when it comes onto the screen. ® As java is highly case sensitive, note that int against number! to declare it is with small i, while all the |’s on right hand side of the assignment statement are all capitals. Other variations are float a = Float.parseFloat(JOptionPane.showlnputDialog( “” )); double b = Double.parseDouble(JOptionPane.showlnputDialog( “ ” )); long c = Long.parseLong(JOptionPane.showlnputDialog( * ” )); = <) Good Programming Practice: Always make your programs compact (iii) The showMessageDialog method has four parameters to be passed into it: null, user’s output, title of the message dialog and the type of icon to be attached to the message box whether error, information or any other. Each of these parameters is separated by commas. Check this with the example above. he first argument, null helos the Java application etermine where to position the dialog box. The value null indicates that the dialog should appear in the center of the computer screen. The first argument can also be used to specify that the dialog should appear centered over a particular window (Find out later). » With the second paramefter, all the output that the user wants the message box to print out including prompting messages are specified in the user's output parameter. » The prompting messages are doubly quoted along with the variable values to be printed out. ¢ The title given to the message box as the third parameter must be typed in double quotes and should be relevant to the output be brought out. ¢ The last parameter is the icon to be attached to the message box. ® This time, we used the JOptionPane.PLAIN_MESSAGE, meaning that no icon will snow. We can also use JOptionPane.INFORMATION_MESSAGE or JOptionPane.ERROR_MESSAGE. Note the use of the underscore. Java Variables and Objects ™ Variables or objects hold data in Java. = A variable has a type and holds a single value. ™An object is an instance of a class and may contain many variables, the composite of whose values is called the “state” the object. m™Whereas every variable has a unique name, on being declared, objects have references instead of names, and they need not be unique. Java Objects = An object is created by using the “new” operator to invoke a “Constructor” and it dies when it has no references. ™ E.g. in the Circle program above, r and area are the 2 variables while reader, input, text, x and System.out are the five objects in the program. ™ These objects are instances of the classes inputStreamReader, BufferedReader, String, Double and PrintStream respectively. Java Variables and Objects Rules of Formation 1. It must be a legal identifier. An identifier is an unlimited series of Unicode characters that begins with a letter. 2. It must not be a keyword, a boolean literal (true or false), or the reserved word null. 3. lt must be unique within its scope. A variable may have the same name as a variable whose declaration appears in a different scope. . Insome situations, a variable may share the same name as another variable if it is declared within a nested block of code. (We will cover this in the next section on Scope.) Scope of Variables ... The location of the variable declaration within a program establishes its scope and places it into one of these four categories: member variable local variable method parameter exception-handler parameter Member Variable Scope al Method Parameter —_] Scope Local Variable class MyClass { nember variable declarations public void aMethod{ wethod parameters } { Hh Tecal variable declarations Scope Exception- handler Parameter Scope * catch ( exception handler parameters ) { rT } Scope of Variables ... A member variable (or global variable) is aq member of a class or an object. m It is declared within a class but outside of any method or constructor. A member variable's scope is the entire declaration of the class. m However, the declaration of a member needs to appear before it is Used when the use is in a member initialization expression. Local variables are declared within a block of code. ® In general, the scope of a local variable extends from its declaration to the end of the code block in which if was declared. Scope of Variables ... = Parameters are formal arguments fo methods or constructors and are used fo pass values info methods and constructors. = The scope of a parameter is the entire method or constructor for which it is a parameter. = Exception-handler parameters are similar to parameters but are arguments to an exception handler rather than to a method or a constructor. » The scope of an exception-handler parameter is the code block between the braces,{ and } that follow a catch statement. We shall deal with this topic later. Final Variables / Java Constants ® A final local variable that has been declared but not yet initialized is called a blank final. m Again, once a final local variable has been initialized, it cannot be set, and any later attempt fo assign a value to blankfinal is an error. Final variables or constants in programming are very useful when we need to set a variable value at once, especially when the variable is used extensively in various sections of a program. » if the value of the variable is to be changed, we don't need to go to all the sections of the program where it used and start changing the values one by one. Data Types ® Every variable must have a data type. m A variable’s data type determines the values that the variable can contain and the operations that can be performed on if. ™ For example, declaring a variable to be int var means that var is an integer data type. Integers can contain only integral (whole umbers) values (both positive and negative) and we can perform arithmetic operations, such as addition, on integer variables. m® Java programming has two categories of data types: primitive and reference. mA variable of primitive type contains a single value of the appropriate size and format for its type: a number, a character, or a Boolean value Java Primitive Types Keyword |Description Size/Format (Integers: numbers without decimal places, eg. 45, 456) byte |Byte-length integer 8-bit two's complement short |Short integer 16-bit two's complement int Integer 32-bit two's complement long _|Long integer 64-bit two's complement (Real numbers: numbers with decimal places, e.g. 3.21) float _|Single-precision floating point 32-bit IEEE 754 double |Double-precision floating point 64-bit IEEE 754 (other types) char |A single character 16-bit Unicode character boolean |A boolean value (true or false) true or false Java Primitive Types ... m Arrays, Classes and interfaces are reference data types. = The value of a reference type variable, in contrast to that of primitive type, is a reference to (an address of) the value or set of values represented by the variable. reference is called a pointer, or a memory address in other languages. = The java programming does not support the explicit use of addresses like other languages do. We use the variable’s name instead. Java Operators ™ An operator performs a function on one, two, or three operands. An operator that requires one operand (Op) is called a unary operator. ™ For example, ++ is a unary operator that increments the value of its operand by 1. = An operator that requires two operands is a binary operator. For example, = is a binary operator that assigns the value from its right hand operand to its left-hand operand. = And finally, a ternary operator is one that requires three operands. = The Java programming language has one ternary operator, ?:, which is a short-hand if— else statement. Java Operators ... ™ In addition to performing the operation, an operator returns a value. ™ The return value and its type depend on the operator and the type of its operand. ™For example, the arithmetic operators, which perform basic ithmetic operations such as addition and subtraction, return numbers — the result of the arithmetic operation. ™ The data type returned by an arithmetic operator depends on the type of its operands: if we add two integers, we get an integer back. ™ An operation is said to evaluate to its result. Below are the java- supported operators. Returned Types after Coercion : Data Type of Data T f Result ata Type of Operands Neither operand is a float or a double (integer long . . . arithmetic); at least one operand is a long. . Neither operand is a float or a double (integer int . . . ; arithmetic); neither operand is a long. double At least one operand is a double. float At least one operand is a float; neither operand is a double. Assignment Operators ™ We use the basic assignment operator, =, to assign one value to another. = In ordinary arithmetic, we are permitted to write a + b = c —d, but this is not allowed in programming. ™ The expression at the left hand side (a + b) is regarded as a memory ocation to which we are assigning the result computed at the right hand side to. ™ Java also provides several short-cut assignment operators that allow us to perform arithmetic, shift, or bitwise operation and an assignment operation, all with one operator. Assignment Operators > Example Oper Use Equivalent to ator += op1 += op2 op1 = op1 + op2 a=at+tb =a+=b -= opl -= op2 op! = op! - op2 a=a-b=a-=b a opl *= op2 op! = op! * op2 a=a*b =a*=b /= op! /= op2 opl = op! / op2 a=a/b =a/=b %= |opl %= op2 opl = op1 % op2 a=a%b = ah=b &= op! &= op2 opl = opl & op2 IF _|op! F op2 op! = op! | op2 We shall study A= op! A= op2 op! = opl * op2 these operators in the latter <<= opl <<= op2 op! = op! << op2 sections >>= Jopl >>= op2 op! = op1 >> op2 >>>= Jopl >>>= op2 opl = opl >>> op2