Object Oriented Programming


Published on

Published in: Education, Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Object Oriented Programming

  1. 1. CS 201 Introduction to Object-Oriented Programming Dr. Jeff Gray gray (at) cis.uab.edu http://www.cis.uab.edu/gray Tue/Thu: 3pm-5pm Course web page: http://www.cis.uab.edu/gray/cs201/
  2. 2. Agenda – Thursday June 1 <ul><li>Today </li></ul><ul><ul><li>Motivation for Studying Computer Science </li></ul></ul><ul><ul><li>Opportunities at UAB CIS </li></ul></ul><ul><ul><li>The Need for Good Engineering of Software </li></ul></ul><ul><ul><li>Begin Chapter 1 </li></ul></ul><ul><li>Next Tuesday </li></ul><ul><ul><li>First Lab in the Morning </li></ul></ul><ul><ul><li>Finish Chapter 1 </li></ul></ul><ul><li>Next Thursday </li></ul><ul><ul><li>Begin Chapter 2 </li></ul></ul><ul><ul><li>Tour of Supercomputer and Visualization Room </li></ul></ul><ul><ul><ul><li>Be on Time for Class! </li></ul></ul></ul>
  3. 3. Exciting New Additions This Summer Sudoku Homework Sequence RoboCode Labs
  4. 4. Motivation for Studying CS
  5. 5. Software is Everywhere <ul><li>Think of some of the things that entertain and enrich your daily life </li></ul><ul><li>All of the above are driven by software </li></ul><ul><li>Software developers equipped with a computer science degree have opportunities to work on exciting and cutting-edge projects </li></ul>
  6. 6. Software is Everywhere <ul><li>98% of all microprocessors control devices other than desktop computers </li></ul><ul><ul><li>Automobiles, airplanes, televisions, copiers, razors… </li></ul></ul><ul><li>These devices also need software and often require strong technical skills to develop </li></ul>>10Mb embedded software 15-20Kb 1-1.5Mb > 1M SLOC
  7. 7. The Demand for Computer Scientists <ul><li>Computing will continue to be a dominant science on which every other science, engineering, and business discipline will increasingly rely. Almost all major technology breakthroughs in the future will involve computing. </li></ul><ul><li>College graduates in the 21 st century cannot afford to be ignorant of Computer Science principles. This is important for Alabama, which is one of the major developing technology centers in our nation. Having a technology literate workforce will be necessary for continued economic growth. </li></ul>
  8. 8. The Demand for Computer Scientists <ul><li>Offshore hysteria : Many companies with high paying jobs within the US are unable to fill positions with computer scientists. </li></ul>Source: http://money.cnn.com/magazines/moneymag/bestjobs/top50/index.html
  9. 9. The Demand for Computer Scientists <ul><li>According to Business 2.0 magazine, 5 of the top-10 growing jobs have a computer science focus </li></ul>Source: http://money.cnn.com/magazines/business2/nextjobboom/
  10. 10. The Demand for Computer Scientists <ul><li>National Job Outlook </li></ul><ul><ul><li>$50,500 is the expected starting salary for computer science degrees in the class of 2006 (among top 5 highest starting salaries) </li></ul></ul><ul><ul><li>1000s of openings each at Microsoft Game Studios, Electronic Arts, Epic Games, Google </li></ul></ul><ul><ul><li>Epic Games President: “We do not hire anyone under $100k” </li></ul></ul>
  11. 11. The Demand for Computer Scientists <ul><li>Local Job Outlook </li></ul><ul><ul><li>In Birmingham, a large financial software company recently had a need for 200 Java programmers; exceeded university’s ability to deliver employees </li></ul></ul><ul><ul><li>CTS hiring several new developers each month </li></ul></ul><ul><ul><li>Summary of recent openings in Birmingham: </li></ul></ul><ul><ul><ul><li>JAVA/J2EE/EJB ($60/hr) </li></ul></ul></ul><ul><ul><ul><li>Peoplesoft (Technical - $85/hr) (Functional - $95/hr) </li></ul></ul></ul><ul><ul><ul><li>SAP Technical ($85/hr), SAP Functional ($95/hr) </li></ul></ul></ul><ul><ul><ul><li>Corba ($55/hr) </li></ul></ul></ul><ul><ul><ul><li>Oracle DBA ($70/hr) </li></ul></ul></ul><ul><ul><ul><li>DB2 DBA ($70/hr) </li></ul></ul></ul><ul><ul><ul><li>Sybase DBA ($75/hr) </li></ul></ul></ul><ul><ul><ul><li>.Net,vb.net,C#,asp.net ($60/hr) </li></ul></ul></ul><ul><ul><ul><li>C/C++ ($55/hr) </li></ul></ul></ul><ul><ul><ul><li>Cobol ($55/hr) </li></ul></ul></ul>
  12. 12. The Potential for Alabama Source: Entrepreneur magazine
  13. 13. Myth of Computer Science <ul><li>According to the Alabama Learning Exchange (ALEX) 1 , computing is equated to learning Microsoft Word and various mechanical tasks; this is not Computer Science! </li></ul>1 http://alex.state.al.us/standardAll.php?grade=9&subject=TC&summary=2
  14. 14. High School Outreach at UAB CIS Mentoring for Science Fair Competitions Summer Robotics Internship <ul><li>Weekly mentoring at UAB throughout academic year; students treated like a PhD student with office space </li></ul>www.cis.uab.edu/gray/Pubs/jerrod-sutton.pdf Computer Graphics Camp www.cis.uab.edu/heritage www.cis.uab.edu/progams/hspc www.cis.uab.edu/cscamp/ <ul><li>Week-long summer camp in computer graphics </li></ul><ul><li>Students use C++ and OpenGL to create projects focused on geometric modeling, algorithm visualization, and motion design </li></ul>High School Programming Contest <ul><li>Seven-week internship </li></ul><ul><li>Students taught Java through series of robotics projects </li></ul><ul><li>May 13, 2006 </li></ul><ul><li>46 students from 12 schools (Huntsville to Mobile) </li></ul><ul><li>6 problems in 3 hours </li></ul><ul><li>Prizes: Xbox, software, books, gift certificates </li></ul>
  15. 15. Opportunities at UAB CIS
  16. 16. Reasons to Consider UAB CIS <ul><li>Scholarship Availability </li></ul><ul><ul><li>For outstanding high school students, UAB offers several scholarships to incoming freshmen (from $2000-$8000 per year) </li></ul></ul><ul><ul><li>The CIS Department offers the Fontana Scholarship each year to two CIS students (typically awarded to Junior and Senior students). This scholarship provides $4,000 over the academic year. </li></ul></ul><ul><li>Outstanding Faculty </li></ul><ul><ul><li>The 11 professors and instructors in the CIS Department obtained their degrees from the top schools in the country (e.g., Cal Tech, Cornell, Northwestern, Pennsylvania, and Vanderbilt). In addition to being leaders in their fields, our professors are dedicated to spending time with students. </li></ul></ul>
  17. 17. Reasons to Consider UAB CIS <ul><li>Excellence in Research and Service </li></ul><ul><ul><li>UAB is the largest employer in the state of Alabama and is the only school in Alabama with the highest research rating (“RU/VH”), which is based on grant funding and PhD production. The University has over $500M in external funding this year, which is several times that of all other universities in Alabama combined . </li></ul></ul><ul><ul><li>Research in the CIS department is funded by the Army Research Office (ARO), Defense Advanced Research Projects Agency (DARPA), International Business Machines (IBM), National Science Foundation (NSF), National Institutes of Health (NIH), and the Office of Naval Research (ONR). </li></ul></ul>
  18. 18. Reasons to Consider UAB CIS <ul><li>Outstanding Facilities </li></ul><ul><ul><li>Fastest computer in the state of Alabama! </li></ul></ul><ul><ul><li>New visualization wall </li></ul></ul>UAB CIS recently acquired a 128 node compute cluster which has been benchmarked at 1.41 teraflops per second. Fastest in Alabama and one of the fastest in the whole Southeast. UAB CIS recently acquired a 13 megapixel, nine tile visualization wall that measures approximately 10' wide by 8' high.
  19. 19. Reasons to Consider UAB CIS <ul><li>Undergraduate Research Opportunities </li></ul><ul><ul><li>For undergraduate students with a high GPA, there is an opportunity to do Honors research with faculty members. There is a special course available that allows a student to be mentored by a faculty member in a manner that provides the student a taste of the graduate school experience. Students participating in CIS Honors receive a special designation on their diploma at graduation. </li></ul></ul><ul><ul><li>During Fall 2005, the CIS department created an Undergraduate Honors Research Lab to host those students participating in Honors research. The students in this special lab will have exclusive access to high-end computers, with accommodations similar to those of doctoral students. </li></ul></ul>
  20. 20. Possible Honors Mentoring Ideas <ul><li>LEGO will release the brand new NXT robot over the summer </li></ul><ul><ul><li>Exciting new capabilities include wireless communication and vision </li></ul></ul><ul><li>At UAB, we will have 5 of these robots for experimentation purposes (July 2006) </li></ul>
  21. 21. Possible Mentoring Ideas <ul><li>Target Recognition in a Rescue Mission </li></ul><ul><ul><li>A group of coordinated robots will work together to conduct a search/rescue mission </li></ul></ul><ul><li>Sniper Identification </li></ul><ul><ul><li>A group of autonomous robots will be used to isolate the location of sniper fire in a military application (using triangulation) </li></ul></ul><ul><li>Speech and Vision Recognition </li></ul><ul><ul><li>Voice controlled commands to a robot that also can use the vision camera to avoid colliding with objects </li></ul></ul><ul><li>Game Playing Robot </li></ul><ul><ul><li>Tic-tac-toe; Othello </li></ul></ul><ul><ul><li>2-on-2 soccer </li></ul></ul><ul><li>YOUR IDEA HERE! </li></ul><ul><ul><li>Of course, we encourage creativity if you have new ideas! </li></ul></ul>
  22. 22. Reasons to Consider UAB CIS <ul><li>Undergraduate Research Opportunities </li></ul><ul><ul><li>CIS undergraduates are awarded summer internships to participate in special research programs sponsored by the National Science Foundation. The students participating in these opportunities continue their research throughout the academic year and prepare research talks and papers that are published at regional conferences. Over the past two years, CIS students placed in the top 3 at the ACM Mid-southeast conference in Gatlinburg, Tennessee. </li></ul></ul>3 First Place Winners: UAB CIS students received first place in all categories (Undergrad, Masters, PhD) amid students from 7 states.
  23. 23. Reasons to Consider UAB CIS <ul><li>Programming Contest Team </li></ul><ul><ul><li>Each year, the CIS department sends our top 9 students to compete in the annual ACM programming contest (held the last few years in Melbourne, Florida). To prepare students for this competition, a new course has been introduced in the curriculum that teaches students problem solving techniques not typically covered in core courses. </li></ul></ul><ul><ul><li>In 2005, the UAB programming team placed among the top 25 out of 64 universities and had the highest score among Alabama Universities. </li></ul></ul>
  24. 24. The Need for Software Engineering <ul><li>Programming “In the Large” vs “In the Small” </li></ul>
  25. 25. Poor Engineering leads to ad-hoc structure! The result of continuous building without any thought toward design. Result: Stairs leading to ceiling; Windows in the middle of room; Doors opening to wall; Non-intuitive floor plan!.
  26. 26. Poor Engineering Has Disastrous Consequences! Aerodynamic phenomena in suspension bridges were not adequately understood in the profession nor had they been addressed in this design. New research was necessary to understand and predict these forces. The remains, located on the bottom of the Sound, are a permanent record of man's capacity to build structures without fully understanding the implications of the design . http://www.nwrain.net/~newtsuit/recoveries/narrows/narrows.htm
  27. 27. Poor Engineering Has Disastrous Consequences! $7 Billion Fire Works – One Bug, One Crash On 4 June 1996, the maiden flight of the Ariane 5 launcher ended in a failure. Only about 40 seconds after initiation of the flight sequence, at an altitude of about 3700 m, the launcher veered off its flight path, broke up and exploded. The failure of the Ariane 501 was caused by the complete loss of guidance and attitude information 37 seconds after start of the main engine ignition sequence (30 seconds after lift- off). This loss of information was due to specification and design errors in the software of the inertial reference system . http://java.sun.com/people/jag/Ariane5.html http://www.around.com/ariane.html http://archive.eiffel.com/doc/manuals/technology/contract/ariane/page.htm l The launcher started to disintegrate at about H0 + 39 seconds because of high aerodynamic loads due to an angle of attack of more than 20 degrees that led to separation of the boosters from the main stage, in turn triggering the self-destruct system of the launcher. This angle of attack was caused by full nozzle deflections of the solid boosters and the Vulcain main engine. These nozzle deflections were commanded by the On-Board Computer (OBC) software on the basis of data transmitted by the active Inertial Reference System (SRI 2). Part of these data at that time did not contain proper flight data, but showed a diagnostic bit pattern of the computer of the SRI 2, which was interpreted as flight data. The reason why the active SRI 2 did not send correct attitude data was that the unit had declared a failure due to a software exception. The OBC could not switch to the back-up SRI 1 because that unit had already ceased to function during the previous data cycle (72 milliseconds period) for the same reason as SRI 2. The internal SRI software exception was caused during execution of a data conversion from 64-bit floating point to 16-bit signed integer value. The floating point number which was converted had a value greater than what could be represented by a 16-bit signed integer. This resulted in an Operand Error. The data conversion instructions (in Ada code) were not protected from causing an Operand Error, although other conversions of comparable variables in the same place in the code were protected. The error occurred in a part of the software that only performs alignment of the strap-down inertial platform. This software module computes meaningful results only before lift-off. As soon as the launcher lifts off, this function serves no purpose. The alignment function is operative for 50 seconds after starting of the Flight Mode of the SRIs which occurs at H0 - 3 seconds for Ariane 5. Consequently, when lift-off occurs, the function continues for approx. 40 seconds of flight. This time sequence is based on a requirement of Ariane 4 and is not required for Ariane 5. The Operand Error occurred due to an unexpected high value of an internal alignment function result called BH, Horizontal Bias, related to the horizontal velocity sensed by the platform. This value is calculated as an indicator for alignment precision over time. The value of BH was much higher than expected because the early part of the trajectory of Ariane 5 differs from that of Ariane 4 and results in considerably higher horizontal velocity values.
  28. 28. Two Techniques for Controlling Structure <ul><li>Decomposition </li></ul><ul><ul><li>Technique for dividing systems into modules </li></ul></ul><ul><ul><li>Well-structured program is one with minimal interconnections between its modules (low-coupling) </li></ul></ul><ul><ul><li>More to be said in later lectures </li></ul></ul><ul><li>Precise Specification </li></ul><ul><ul><li>“ precisely describing the assumptions that the designers of one module are permitted to make about other modules” </li></ul></ul><ul><ul><li>More also to be said on this later </li></ul></ul><ul><li>Some examples of why it is easier in other “engineering” endeavours… </li></ul>
  29. 29. Decomposition and Simple Specification The prong and receptacle parts of a Lego™ block have been unchanged since 1932 [Lego, 2002].
  30. 30. Simple Interface Specification Since around 1850, the standard dimensions for an “air cell” masonry brick in the United States has been 2.5 x 3.75 x 8 inches [Chrysler and Escobar, 2000].
  31. 31. Even building a dog house takes some engineering From http://www.ttyler.8m.com/Dog%20House.htm Initially started as a &quot;basic&quot; dog house but soon turned into a masterpiece of quality workmanship.  Total time spent was 8 hours at a cost of $110 US.  Start with a piece of paper and a idea:   Design your dog house to the size and quantity of your dogs.  A perfectly built home is worthless if its to small to properly accommodate your dog.     Framing:   The framing process should be constructed with 2x4's or rip them in half for smaller homes.  A removable roof should be incorporated in assisting the future cleaning and maintenance.   Wall Covering:   Should be tong & grove for a tight fit, no warping, and to cut down on cross drafts.  For large homes, plywood is a economical material that can be used.     Roof:   30 year home shingles cut down to the proper size.  As for this house, an oriental piece was constructed then topped of with a copper fence post top.  An additional hours work and $15 cost was needed   Trim & Finishing Touches:  Trim can add a lot to the astidics of your dog house.  Trim can be bought  with may different variations or with some craftsmanshipcan can be made with the use of a router.   Sanding & Paint:   Sink all nails below the surface and cover with wood filler.  Prepare surface for painting by sanding wood filler, rough spots, and blemishes.
  32. 32. Let’s Get Started!!!!!!
  33. 33. 1 Introduction 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights reserved
  34. 34. Focus of the Course <ul><li>Object-Oriented Software Development </li></ul><ul><ul><li>problem solving </li></ul></ul><ul><ul><li>program design, implementation, and testing </li></ul></ul><ul><ul><li>object-oriented concepts </li></ul></ul><ul><ul><ul><li>classes </li></ul></ul></ul><ul><ul><ul><li>objects </li></ul></ul></ul><ul><ul><ul><li>encapsulation </li></ul></ul></ul><ul><ul><ul><li>inheritance </li></ul></ul></ul><ul><ul><ul><li>polymorphism </li></ul></ul></ul><ul><ul><li>graphical user interfaces </li></ul></ul><ul><ul><li>the Java programming language </li></ul></ul>
  35. 35. Introduction <ul><li>We first need to explore the fundamentals of computer processing </li></ul><ul><li>Chapter 1 focuses on: </li></ul><ul><ul><li>components of a computer </li></ul></ul><ul><ul><li>how those components interact </li></ul></ul><ul><ul><li>how computers store and manipulate information </li></ul></ul><ul><ul><li>computer networks </li></ul></ul><ul><ul><li>the Internet and the World Wide Web </li></ul></ul><ul><ul><li>programming and programming languages </li></ul></ul><ul><ul><li>an introduction to Java </li></ul></ul><ul><ul><li>an overview of object-oriented concepts </li></ul></ul>
  36. 36. Outline Computer Processing Hardware Components Networks The Java Programming Language Program Development Object-Oriented Programming
  37. 37. Hardware and Software <ul><li>Hardware </li></ul><ul><ul><li>the physical, tangible parts of a computer </li></ul></ul><ul><ul><li>keyboard, monitor, disks, wires, chips, etc. </li></ul></ul><ul><li>Software </li></ul><ul><ul><li>programs and data </li></ul></ul><ul><ul><li>a program is a series of instructions </li></ul></ul><ul><li>A computer requires both hardware and software </li></ul><ul><li>Each is essentially useless without the other </li></ul>
  38. 38. CPU and Main Memory Central Processing Unit Chip that executes program commands Intel Pentium 4 Sun ultraSPARC III Primary storage area for programs and data that are in active use Synonymous with RAM Main Memory
  39. 39. Secondary Memory Devices Central Processing Unit Secondary memory devices provide long-term storage Information is moved between main memory and secondary memory as needed Hard disks Floppy disks ZIP disks Writable CDs Writable DVDs Tapes Main Memory Floppy Disk Hard Disk
  40. 40. Input / Output Devices Central Processing Unit I/O devices facilitate user interaction Monitor screen Keyboard Mouse Joystick Bar code scanner Touch screen Main Memory Floppy Disk Hard Disk Monitor Keyboard
  41. 41. Software Categories <ul><li>Operating System </li></ul><ul><ul><li>controls all machine activities </li></ul></ul><ul><ul><li>provides the user interface to the computer </li></ul></ul><ul><ul><li>manages resources such as the CPU and memory </li></ul></ul><ul><ul><li>Windows XP, Unix, Linux, Mac OS </li></ul></ul><ul><li>Application program </li></ul><ul><ul><li>generic term for any other kind of software </li></ul></ul><ul><ul><li>word processors, missile control systems, games </li></ul></ul><ul><li>Most operating systems and application programs have a graphical user interface (GUI) </li></ul>
  42. 42. Analog vs. Digital <ul><li>There are two basic ways to store and manage data: </li></ul><ul><li>Analog </li></ul><ul><ul><li>continuous, in direct proportion to the data represented </li></ul></ul><ul><ul><li>music on a record album - a needle rides on ridges in the grooves that are directly proportional to the voltages sent to the speaker </li></ul></ul><ul><li>Digital </li></ul><ul><ul><li>the information is broken down into pieces, and each piece is represented separately </li></ul></ul><ul><ul><li>music on a compact disc - the disc stores numbers representing specific voltage levels sampled at specific times </li></ul></ul>
  43. 43. Digital Information <ul><li>Computers store all information digitally: </li></ul><ul><ul><li>numbers </li></ul></ul><ul><ul><li>text </li></ul></ul><ul><ul><li>graphics and images </li></ul></ul><ul><ul><li>video </li></ul></ul><ul><ul><li>audio </li></ul></ul><ul><ul><li>program instructions </li></ul></ul><ul><li>In some way, all information is digitized - broken down into pieces and represented as numbers </li></ul>
  44. 44. Representing Text Digitally <ul><li>For example, every character is stored as a number, including spaces, digits, and punctuation </li></ul><ul><li>Corresponding upper and lower case letters are separate characters </li></ul>H i , H e a t h e r . 72 105 44 32 72 101 97 116 104 101 114 46
  45. 45. Binary Numbers <ul><li>Once information is digitized, it is represented and stored in memory using the binary number system </li></ul><ul><li>A single binary digit (0 or 1) is called a bit </li></ul><ul><li>Devices that store and move information are cheaper and more reliable if they have to represent only two states </li></ul><ul><li>A single bit can represent two possible states, like a light bulb that is either on (1) or off (0) </li></ul><ul><li>Permutations of bits are used to store values </li></ul>
  46. 46. Bit Permutations Each additional bit doubles the number of possible permutations 1 bit 0 1 2 bits 00 01 10 11 3 bits 000 001 010 011 100 101 110 111 4 bits 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
  47. 47. Bit Permutations <ul><li>Each permutation can represent a particular item </li></ul><ul><li>There are 2 N permutations of N bits </li></ul><ul><li>Therefore, N bits are needed to represent 2 N unique items </li></ul>2 1 = 2 items 2 2 = 4 items 2 3 = 8 items 2 4 = 16 items 2 5 = 32 items 1 bit ? 2 bits ? 3 bits ? 4 bits ? 5 bits ? How many items can be represented by
  48. 48. Outline Computer Processing Hardware Components Networks The Java Programming Language Program Development Object-Oriented Programming
  49. 49. A Computer Specification <ul><li>Consider the following specification for a personal computer: </li></ul><ul><ul><li>2.8 GHz Pentium 4 Processor </li></ul></ul><ul><ul><li>512 MB RAM </li></ul></ul><ul><ul><li>80 GB Hard Disk </li></ul></ul><ul><ul><li>48x CD-RW / DVD-ROM Combo Drive </li></ul></ul><ul><ul><li>17” Video Display with 1280 x 1024 resolution </li></ul></ul><ul><ul><li>56 Kb/s Modem </li></ul></ul><ul><li>What does it all mean? </li></ul>
  50. 50. Memory Main memory is divided into many memory locations (or cells ) 9278 9279 9280 9281 9282 9283 9284 9285 9286 Each memory cell has a numeric address , which uniquely identifies it
  51. 51. Storing Information 9278 9279 9280 9281 9282 9283 9284 9285 9286 10011010 Large values are stored in consecutive memory locations Each memory cell stores a set number of bits (usually 8 bits, or one byte )
  52. 52. Storage Capacity <ul><li>Every memory device has a storage capacity , indicating the number of bytes it can hold </li></ul><ul><li>Capacities are expressed in various units: </li></ul>KB 2 10 = 1024 MB 2 20 (over 1 million) GB 2 30 (over 1 billion) TB 2 40 (over 1 trillion) Unit Symbol Number of Bytes kilobyte megabyte gigabyte terabyte
  53. 53. Memory <ul><li>Main memory is volatile - stored information is lost if the electric power is removed </li></ul><ul><li>Secondary memory devices are nonvolatile </li></ul><ul><li>Main memory and disks are direct access devices - information can be reached directly </li></ul><ul><li>The terms direct access and random access often are used interchangeably </li></ul><ul><li>A magnetic tape is a sequential access device since its data is arranged in a linear order - you must get by the intervening data in order to access other information </li></ul>
  54. 54. RAM vs. ROM <ul><li>RAM - Random Access Memory (direct access) </li></ul><ul><li>ROM - Read-Only Memory </li></ul><ul><li>The terms RAM and main memory are basically interchangeable </li></ul><ul><li>ROM could be a set of memory chips, or a separate device, such as a CD ROM </li></ul><ul><li>Both RAM and ROM are random (direct) access devices! </li></ul><ul><li>RAM probably should be called Read-Write Memory </li></ul>
  55. 55. Compact Discs <ul><li>A CD-ROM is portable read-only memory </li></ul><ul><li>A microscopic pit on a CD represents a binary 1 and a smooth area represents a binary 0 </li></ul><ul><li>A low-intensity laser reflects strongly from a smooth area and weakly from a pit </li></ul><ul><li>A CD-Recordable (CD-R) drive can be used to write information to a CD once </li></ul><ul><li>A CD-Rewritable (CD-RW) can be erased and reused </li></ul><ul><li>The speed of a CD drive indicates how fast (max) it can read and write information to a CD </li></ul>
  56. 56. DVDs <ul><li>A DVD is the same size as a CD, but can store much more information </li></ul><ul><li>The format of a DVD stores more bits per square inch </li></ul><ul><li>A CD can store 650 MB, while a standard DVD can store 4.7 GB </li></ul><ul><ul><li>A double sided DVD can store 9.4 GB </li></ul></ul><ul><ul><li>Other advanced techniques can bring the capacity up to 17.0 GB </li></ul></ul><ul><li>Like CDs, there are DVD-R and DVD-RW discs </li></ul>
  57. 57. The Central Processing Unit <ul><li>A CPU is on a chip called a microprocessor </li></ul><ul><li>It continuously follows the fetch-decode-execute cycle: </li></ul>fetch Retrieve an instruction from main memory decode Determine what the instruction is execute Carry out the instruction
  58. 58. The Central Processing Unit <ul><li>The CPU contains: </li></ul>Arithmetic / Logic Unit Registers Control Unit Small storage areas Performs calculations and makes decisions Coordinates processing steps
  59. 59. The Central Processing Unit <ul><li>The speed of a CPU is controlled by the system clock </li></ul><ul><li>The system clock generates an electronic pulse at regular intervals </li></ul><ul><li>The pulses coordinate the activities of the CPU </li></ul><ul><li>The speed is usually measured in gigahertz (GHz) </li></ul>
  60. 60. Monitor <ul><li>The size of a monitor (17&quot;) is measured diagonally, like a television screen </li></ul><ul><li>Most monitors these days have multimedia capabilities: text, graphics, video, etc. </li></ul><ul><li>A monitor has a certain maximum resolution , indicating the number of picture elements, called pixels , that it can display (such as 1280 by 1024) </li></ul><ul><li>High resolution (more pixels) produces sharper pictures </li></ul>
  61. 61. Modem <ul><li>Data transfer devices allow information to be sent and received between computers </li></ul><ul><li>Many computers include a modulator-demodulator or modem , which allows information to be moved across a telephone line </li></ul><ul><li>A data transfer device has a maximum data transfer rate </li></ul><ul><li>A modem, for instance, may have a data transfer rate of 56,000 bits per second (bps) </li></ul>
  62. 62. Agenda – Thursday June 6 <ul><li>Summary from Last Lecture </li></ul><ul><ul><li>Motivation for studying CS and UAB opportunities </li></ul></ul><ul><ul><li>Analog vs Digital </li></ul></ul><ul><ul><li>Binary Numbers </li></ul></ul><ul><ul><li>Hardware Categories </li></ul></ul><ul><li>Today </li></ul><ul><ul><li>Textbook Issue </li></ul></ul><ul><ul><li>First Lab in the Morning </li></ul></ul><ul><ul><li>Finish Chapter 1 </li></ul></ul><ul><li>Thursday </li></ul><ul><ul><li>Begin Chapter 2 </li></ul></ul><ul><ul><li>Tour of Supercomputer and Visualization Room </li></ul></ul><ul><ul><ul><li>Be on Time for Class! </li></ul></ul></ul>
  63. 63. Review of Binary Numbers: Converting Binary to Decimal <ul><li>Consider what the decimal number “1,234” means: </li></ul><ul><ul><li>1234 = 1000 + 200 + 30 + 4 </li></ul></ul><ul><ul><li>= 1* 1000 + 2* 100 + 3* 10 + 4 * 1 </li></ul></ul><ul><ul><li>= 1*10 3 + 2*10 2 + 3*10 1 + 4*10 0 </li></ul></ul><ul><li>In general, n a …n 1 n 0 represented in base “b” is: </li></ul><ul><ul><li>n a …n 1 n 0 = n a *b a + … + n 1 *b 1 + n 0 *b 0 </li></ul></ul><ul><li>Apply this to generalization to binary “01101100” (b=2) </li></ul><ul><ul><li>01101100 = 0*2 7 + 1*2 6 + 1*2 5 + 0*2 4 + 1*2 3 + 1*2 2 + 0*2 1 + 0*2 0 </li></ul></ul><ul><ul><li>= 0*128 + 1*64 + 1*32 + 0*16 + 1*8 + 1*4 + 0*2 + 0*1 </li></ul></ul><ul><ul><li>= 0 + 64 + 32 + 0 + 8 + 4 + 0 + 0 </li></ul></ul><ul><ul><li>= 64 + 32 + 8 + 4 </li></ul></ul><ul><ul><li>= 108 </li></ul></ul>
  64. 64. Review of Binary Numbers: Converting Decimal to Binary <ul><ul><li>Step 1: See if the number is divisible by 2. </li></ul></ul><ul><ul><ul><li>If it is divisible by 2, write ‘0’ and divide by 2 to get the next number. </li></ul></ul></ul><ul><ul><ul><li>If the number, on the other hand, is indivisible by 2, write a ‘1’, then subtract 1 from the number and divide by two to get the next number. </li></ul></ul></ul><ul><ul><li>Step 2: Continue this process, writing each ‘1’ or ‘0’ to the left of the previous 1 or 0, until the number which we are left to divide by is 0. </li></ul></ul><ul><ul><li>Step 3: You should always check your answer to make sure that your conversion is correct. </li></ul></ul>
  65. 65. Review of Binary Numbers: Converting Decimal to Binary <ul><ul><li>Lets convert the decimal number 241 to binary </li></ul></ul><ul><ul><li>Step 1: Divide by two. Since 241 is indivisible, we write a 1. Then we subtract 1 from 241 to get 240 and divide by two to get 120. Result: 1 </li></ul></ul><ul><ul><li>Step 2: Divide by two. Since 120 is divisible, we write a 0 to the left of the previous number and divide by two to get 60. Result: 01 </li></ul></ul><ul><ul><li>Step 3: Divide by two. Since 60 is divisible, we write a 0 to the left of the previous number and divide by two to get 30. Result: 001 </li></ul></ul><ul><ul><li>Step 4: Divide by two. Since 30 is divisible, we write a 0 to the left of the previous number and divide by two to get 15. Result: 0001 </li></ul></ul><ul><ul><li>Step 5: Divide by two. Since 15 is indivisible, we write a 1 to the left of the previous number. Then we subtract 1 from 15 to get 14 and when we divide we get 7. Result: 10001 </li></ul></ul><ul><ul><li>Step 6: Divide by two. Since 7 is indivisible, we write a 1 to the left of the previous numbers. Then we subtract 1 from 7 to get 6 and when we divide we get 3. Result: 110001 </li></ul></ul><ul><ul><li>Step 7: Divide by two. Since 3 is indivisible, we write a 1 to the left of the previous numbers. Then we subtract 1 from 3 to get 2 and when we divide we get 1. Result: 1110001 </li></ul></ul><ul><ul><li>Step 8: Divide by two. Since 1 is indivisible, we write a 1 to the left of the previous numbers. Then we subtract 1 from 1 to get 0, which means we are finished. Result: 11110001 </li></ul></ul>
  66. 66. Review of Binary Numbers <ul><li>Some helpful references (thanks to Adam Dane) </li></ul><ul><ul><li>Cartoon </li></ul></ul><ul><ul><ul><li>http://static.instructables.com/data/uuid/EB/9C7EE0/7C871028A786001143E7E506/EB9C7EE07C871028A786001143E7E506.pdf </li></ul></ul></ul><ul><ul><li>Binary game </li></ul></ul><ul><ul><ul><li>http:// forums.cisco.com/CertCom/game/binary_game_page.htm?site = celc </li></ul></ul></ul>
  67. 67. Outline Computer Processing Hardware Components Networks The Java Programming Language Program Development Object-Oriented Programming
  68. 68. Networks <ul><li>A network is two or more computers that are connected so that data and resources can be shared </li></ul><ul><li>Most computers are connected to some kind of network </li></ul><ul><li>Each computer has its own network address , which uniquely identifies it among the others </li></ul><ul><li>A file server is a network computer dedicated to storing programs and data that are shared among network users (similar for web server and print server) </li></ul>
  69. 69. Network Connections <ul><li>Each computer in a network could be directly connected to every other computer in the network </li></ul><ul><li>These are called point-to-point connections </li></ul>This technique is not practical for more than a few close machines – why? Adding a computer requires a new communication line for each computer already in the network
  70. 70. Network Connections <ul><li>Most networks share a single communication line </li></ul><ul><li>Adding a new computer to the network is relatively easy </li></ul>Network traffic must take turns using the line, which introduces delays Often information is broken down in parts, called packets , which are sent to the receiving machine and then reassembled
  71. 71. Local-Area Networks A Local-Area Network (LAN) covers a small distance and a small number of computers A LAN often connects the machines in a single room or building LAN
  72. 72. Wide-Area Networks A Wide-Area Network (WAN) connects two or more LANs, often over long distances A LAN usually is owned by one organization, but a WAN often connects groups in different countries LAN LAN
  73. 73. The Internet <ul><li>The Internet is a WAN which spans the entire planet </li></ul><ul><li>The word Internet comes from the term internetworking </li></ul><ul><li>It started as a United States government project, sponsored by the Advanced Research Projects Agency (ARPA) - originally it was called the ARPANET </li></ul><ul><li>The Internet grew quickly throughout the 1980s and 90s </li></ul>
  74. 74. TCP/IP <ul><li>A protocol is a set of rules that determine how things communicate with each other </li></ul><ul><li>The software which manages Internet communication follows a suite of protocols called TCP/IP </li></ul><ul><li>The Internet Protocol (IP) determines the format of the information as it is transferred </li></ul><ul><li>The Transmission Control Protocol (TCP) dictates how messages are reassembled and handles lost information </li></ul>
  75. 75. IP and Internet Addresses <ul><li>Each computer on the Internet has a unique IP address , such as: </li></ul><ul><li> </li></ul><ul><li>Most computers also have a unique Internet name, which also is referred to as an Internet address : </li></ul><ul><ul><li>spencer.villanova.edu </li></ul></ul><ul><ul><li>kant.gestalt-llc.com </li></ul></ul><ul><li>The first part indicates a particular computer ( spencer ) </li></ul><ul><li>The rest is the domain name , indicating the organization ( villanova.edu ) </li></ul>
  76. 76. Domain Names <ul><li>The last part of a domain name, called a top-level domain (TLD), indicates the type of organization: </li></ul>edu com org net - educational institution - commercial entity - non-profit organization - network-based organization Sometimes the suffix indicates the country: New TLDs have recently been added: biz, info, tv, name uk au ca se - United Kingdom - Australia - Canada - Sweden
  77. 77. Domain Names <ul><li>A domain name can have several parts </li></ul><ul><li>When used, an Internet address is translated to an IP address by software called the Domain Name System (DNS) </li></ul><ul><li>There is no one-to-one correspondence between the sections of an IP address and the sections of an Internet address </li></ul><ul><li>Looking up the owner of a domain name: </li></ul><ul><ul><li>`Who-IS: http://www.internic.net/whois.html </li></ul></ul>
  78. 78. The World Wide Web <ul><li>The World Wide Web allows many different types of information to be accessed using a common interface </li></ul><ul><li>A browser is a program which accesses and presents information </li></ul><ul><ul><li>text, graphics, video, sound, audio, executable programs </li></ul></ul><ul><li>A Web document usually contains links to other Web documents, creating a hypermedia environment </li></ul><ul><li>The term Web comes from the fact that information is not organized in a linear fashion </li></ul>
  79. 79. The World Wide Web <ul><li>Web documents are often defined using the HyperText Markup Language (HTML) </li></ul><ul><li>Information on the Web is found using a Uniform Resource Locator (URL): </li></ul><ul><li>http://www.lycos.com </li></ul><ul><li>http://www.villanova.edu/webinfo/domains.html </li></ul><ul><li>ftp://java.sun.com/applets/animation.zip </li></ul><ul><li>A URL indicates a protocol (http), a domain, and possibly specific documents </li></ul>
  80. 80. Outline Computer Processing Hardware Components Networks The Java Programming Language Program Development Object-Oriented Programming
  81. 81. Java <ul><li>A programming language specifies the words and symbols that we can use to write a program </li></ul><ul><li>A programming language employs a set of rules that dictate how the words and symbols can be put together to form valid program statements </li></ul><ul><li>The Java programming language was created by Sun Microsystems, Inc. </li></ul><ul><li>It was introduced in 1995 and it's popularity has grown quickly since </li></ul>
  82. 82. Java Program Structure <ul><li>In the Java programming language: </li></ul><ul><ul><li>A program is made up of one or more classes </li></ul></ul><ul><ul><li>A class contains one or more methods </li></ul></ul><ul><ul><li>A method contains program statements </li></ul></ul><ul><ul><li>Similar to how a book is broken into chapters, paragraphs, sentences, and words. This serves as an organizational structuring mechanism. </li></ul></ul><ul><li>These terms will be explored in detail throughout the course </li></ul><ul><li>A Java application always contains a method called main </li></ul><ul><li>See Lincoln.java (page 27) </li></ul>
  83. 83. Java Program Structure public class MyProgram { } // comments about the class class header class body Comments can be placed almost anywhere
  84. 84. Java Program Structure public class MyProgram { } // comments about the class public static void main (String[] args) { } // comments about the method method header method body
  85. 85. Comments <ul><li>Comments in a program are called inline documentation </li></ul><ul><li>They should be included to explain the purpose of the program and describe processing steps </li></ul><ul><li>They do not affect how a program works </li></ul><ul><li>Java comments can take three forms: </li></ul>// this comment runs to the end of the line /* this comment runs to the terminating symbol, even across line breaks */ /** this is a javadoc comment */
  86. 86. Identifiers <ul><li>Identifiers are the words a programmer uses in a program </li></ul><ul><li>An identifier can be made up of letters, digits, the underscore character ( _ ), and the dollar sign </li></ul><ul><li>Identifiers cannot begin with a digit </li></ul><ul><li>Java is case sensitive - Total, total, and TOTAL are different identifiers </li></ul><ul><li>By convention, programmers use different case styles for different types of identifiers, such as </li></ul><ul><ul><li>title case for class names - Lincoln </li></ul></ul><ul><ul><li>upper case for constants - MAXIMUM </li></ul></ul>
  87. 87. Identifiers <ul><li>Sometimes we choose identifiers ourselves when writing a program (such as Lincoln ) </li></ul><ul><li>Sometimes we are using another programmer's code, so we use the identifiers that he or she chose (such as println ) </li></ul><ul><li>Often we use special identifiers called reserved words that already have a predefined meaning in the language; a reserved represents the core of the Java language </li></ul><ul><li>A reserved word cannot be used in any other way </li></ul>
  88. 88. Reserved Words <ul><li>The Java reserved words: </li></ul>abstract assert boolean break byte case catch char class const continue default do double else enum extends false final finally float for goto if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while
  89. 89. White Space <ul><li>Spaces, blank lines, and tabs are called white space </li></ul><ul><li>White space is used to separate words and symbols in a program </li></ul><ul><li>Extra white space is ignored </li></ul><ul><li>A valid Java program can be formatted many ways </li></ul><ul><li>Programs should be formatted to enhance readability, using consistent indentation </li></ul><ul><li>See Lincoln2.java (page 33) </li></ul><ul><li>See Lincoln3.java (page 34) </li></ul>
  90. 90. Outline Computer Processing Hardware Components Networks The Java Programming Language Program Development Object-Oriented Programming
  91. 91. Program Development <ul><li>The mechanics of developing a program include several activities </li></ul><ul><ul><li>writing the program in a specific programming language (such as Java) </li></ul></ul><ul><ul><li>translating the program into a form that the computer can execute </li></ul></ul><ul><ul><li>investigating and fixing various types of errors that can occur </li></ul></ul><ul><li>Software tools can be used to help with all parts of this process </li></ul><ul><li>Integrated Development Environments (IDEs) like Eclipse combine all of these activites </li></ul>
  92. 92. Language Levels <ul><li>There are four programming language levels: </li></ul><ul><ul><li>machine language </li></ul></ul><ul><ul><li>assembly language </li></ul></ul><ul><ul><li>high-level language </li></ul></ul><ul><ul><li>fourth-generation language </li></ul></ul><ul><li>Each type of CPU has its own specific machine language </li></ul><ul><li>The other levels were created to make it easier for a human to read and write programs </li></ul>
  93. 93. Programming Languages <ul><li>Each type of CPU executes only a particular machine language </li></ul><ul><li>A program must be translated into machine language before it can be executed </li></ul><ul><li>A compiler is a software tool which translates source code into a specific target language </li></ul><ul><li>Often, that target language is the machine language for a particular CPU type </li></ul><ul><li>The Java approach is somewhat different </li></ul>
  94. 94. Java Translation <ul><li>The Java compiler translates Java source code into a special representation called bytecode </li></ul><ul><li>Java bytecode is not the machine language for any traditional CPU </li></ul><ul><li>Another software tool, called an interpreter , translates bytecode into machine language and executes it </li></ul><ul><li>Therefore, the Java compiler is not tied to any particular machine </li></ul><ul><li>Java is considered to be architecture-neutral </li></ul>
  95. 95. Java Translation Java source code Machine code Java bytecode Bytecode interpreter Bytecode compiler Java compiler
  96. 96. Development Environments <ul><li>There are many programs that support the development of Java software, including: </li></ul><ul><ul><li>Sun Java Development Kit (JDK) </li></ul></ul><ul><ul><li>Sun NetBeans </li></ul></ul><ul><ul><li>IBM Eclipse </li></ul></ul><ul><ul><li>Borland JBuilder </li></ul></ul><ul><ul><li>MetroWerks CodeWarrior </li></ul></ul><ul><ul><li>BlueJ </li></ul></ul><ul><ul><li>jGRASP </li></ul></ul><ul><li>Though the details of these environments differ, the basic compilation and execution process is essentially the same </li></ul>
  97. 97. Syntax and Semantics <ul><li>The syntax rules of a language define how we can put together symbols, reserved words, and identifiers to make a valid program </li></ul><ul><li>The semantics of a program statement define what that statement means (its purpose or role in a program) </li></ul><ul><li>A program that is syntactically correct is not necessarily logically (semantically) correct </li></ul><ul><li>A program will always do what we tell it to do, not what we meant to tell it to do </li></ul>
  98. 98. Errors <ul><li>A program can have three types of errors </li></ul><ul><li>The compiler will find syntax errors and other basic problems ( compile-time errors ) </li></ul><ul><ul><li>If compile-time errors exist, an executable version of the program is not created </li></ul></ul><ul><li>A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally ( run-time errors ) </li></ul><ul><li>A program may run, but produce incorrect results, perhaps using an incorrect formula ( logical errors ) </li></ul>
  99. 99. Basic Program Development Edit and save program Compile program Execute program and evaluate results errors errors
  100. 100. Outline Computer Processing Hardware Components Networks The Java Programming Language Program Development Object-Oriented Programming
  101. 101. Problem Solving <ul><li>The purpose of writing a program is to solve a problem </li></ul><ul><li>Solving a problem consists of multiple activities: </li></ul><ul><ul><li>Understand the problem </li></ul></ul><ul><ul><li>Design a solution </li></ul></ul><ul><ul><li>Consider alternatives and refine the solution </li></ul></ul><ul><ul><li>Implement the solution </li></ul></ul><ul><ul><li>Test the solution </li></ul></ul><ul><li>These activities are not purely linear – they overlap and interact </li></ul>
  102. 102. Problem Solving <ul><li>The key to designing a solution is breaking it down into manageable pieces </li></ul><ul><li>When writing software, we design separate pieces that are responsible for certain parts of the solution </li></ul><ul><li>An object-oriented approach lends itself to this kind of solution decomposition </li></ul><ul><li>We will dissect our solutions into pieces called objects and classes </li></ul>
  103. 103. Object-Oriented Programming <ul><li>Java is an object-oriented programming language </li></ul><ul><li>As the term implies, an object is a fundamental entity in a Java program </li></ul><ul><li>Objects can be used effectively to represent real-world entities </li></ul><ul><li>For instance, an object might represent a particular employee in a company </li></ul><ul><li>Each employee object handles the processing and data management related to that employee </li></ul>
  104. 104. Objects <ul><li>An object has: </li></ul><ul><ul><li>state - descriptive characteristics </li></ul></ul><ul><ul><li>behaviors - what it can do (or what can be done to it) </li></ul></ul><ul><li>The state of a bank account includes its account number and its current balance </li></ul><ul><li>The behaviors associated with a bank account include the ability to make deposits and withdrawals </li></ul><ul><li>Note that the behavior of an object might change its state </li></ul>
  105. 105. Classes <ul><li>An object is defined by a class </li></ul><ul><li>A class is the blueprint of an object </li></ul><ul><li>The class uses methods to define the behaviors of the object </li></ul><ul><li>The class that contains the main method of a Java program represents the entire program </li></ul><ul><li>A class represents a concept, and an object represents the embodiment of that concept </li></ul><ul><li>Multiple objects can be created from the same class </li></ul>
  106. 106. Objects and Classes Bank Account A class (the concept) John’s Bank Account Balance: $5,257 An object (the realization) Bill’s Bank Account Balance: $1,245,069 Mary’s Bank Account Balance: $16,833 Multiple objects from the same class
  107. 107. Inheritance <ul><li>One class can be used to derive another via inheritance </li></ul><ul><li>Classes can be organized into hierarchies </li></ul>Bank Account Account Charge Account Savings Account Checking Account
  108. 108. Summary <ul><li>Chapter 1 focused on: </li></ul><ul><ul><li>components of a computer </li></ul></ul><ul><ul><li>how those components interact </li></ul></ul><ul><ul><li>how computers store and manipulate information </li></ul></ul><ul><ul><li>computer networks </li></ul></ul><ul><ul><li>the Internet and the World Wide Web </li></ul></ul><ul><ul><li>programming and programming languages </li></ul></ul><ul><ul><li>an introduction to Java </li></ul></ul><ul><ul><li>an overview of object-oriented concepts </li></ul></ul>