Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
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/ Agenda – Thursday June 1 • Today Motivation for Studying Computer Science Opportunities at UAB CIS The Need for Good Engineering of Software Begin Chapter 1 • Next Tuesday First Lab in the Morning Finish Chapter 1 • Next Thursday Begin Chapter 2 Tour of Supercomputer and Visualization Room • Be on Time for Class! Exciting New Additions This Summer Sudoku Homework Sequence RoboCode Labs Motivation for Studying CS Software is Everywhere • Think of some of the things that entertain and enrich your daily life • All of the above are driven by software • Software developers equipped with a computer science degree have opportunities to work on exciting and cutting-edge projects Software is Everywhere • 98% of all microprocessors control devices other than desktop computers Automobiles, airplanes, televisions, copiers, razors… > 1M SLOC 15-20Kb 1-1.5Mb >10Mb embedded software • These devices also need software and often require strong technical skills to develop The Demand for Computer Scientists • 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. • College graduates in the 21st 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. The Demand for Computer Scientists Offshore hysteria: Many companies with high paying jobs within the US are unable to fill positions with computer scientists. Source: http://money.cnn.com/magazines/moneymag/bestjobs/top50/index.html The Demand for Computer Scientists • According to Business 2.0 magazine, 5 of the top-10 growing jobs have a computer science focus Source: http://money.cnn.com/magazines/business2/nextjobboom/ The Demand for Computer Scientists • National Job Outlook $50,500 is the expected starting salary for computer science degrees in the class of 2006 (among top 5 highest starting salaries) 1000s of openings each at Microsoft Game Studios, Electronic Arts, Epic Games, Google Epic Games President: “We do not hire anyone under $100k” The Demand for Computer Scientists • Local Job Outlook In Birmingham, a large financial software company recently had a need for 200 Java programmers; exceeded university’s ability to deliver employees CTS hiring several new developers each month Summary of recent openings in Birmingham: • • • • • • • • • • JAVA/J2EE/EJB ($60/hr) Peoplesoft (Technical - $85/hr) (Functional - $95/hr) SAP Technical ($85/hr), SAP Functional ($95/hr) Corba ($55/hr) Oracle DBA ($70/hr) DB2 DBA ($70/hr) Sybase DBA ($75/hr) .Net,vb.net,C#,asp.net ($60/hr) C/C++ ($55/hr) Cobol ($55/hr) The Potential for Alabama Source: Entrepreneur magazine Myth of Computer Science • According to the Alabama Learning Exchange (ALEX)1, computing is equated to learning Microsoft Word and various mechanical tasks; this is not Computer Science! 1 http://alex.state.al.us/standardAll.php?grade=9&subject=TC&summary=2 High School Outreach at UAB CIS Mentoring for Science Fair Competitions • Weekly mentoring at UAB throughout academic year; students treated like a PhD student with office space www.cis.uab.edu/gray/Pubs/jerrod-sutton.pdf Computer Graphics Camp • Week-long summer camp in computer graphics • Students use C++ and OpenGL to create projects focused on geometric modeling, algorithm visualization, and motion design www.cis.uab.edu/cscamp/ Summer Robotics Internship • Seven-week internship • Students taught Java through series of robotics projects www.cis.uab.edu/heritage High School Programming Contest • May 13, 2006 • 46 students from 12 schools (Huntsville to Mobile) • 6 problems in 3 hours • Prizes: Xbox, software, books, gift certificates www.cis.uab.edu/progams/hspc Opportunities at UAB CIS Reasons to Consider UAB CIS • Scholarship Availability For outstanding high school students, UAB offers several scholarships to incoming freshmen (from $2000-$8000 per year) 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. • Outstanding Faculty 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. Reasons to Consider UAB CIS • Excellence in Research and Service 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. 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). Reasons to Consider UAB CIS • Outstanding Facilities Fastest computer in the state of Alabama! 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. New visualization wall UAB CIS recently acquired a 13 megapixel, nine tile visualization wall that measures approximately 10' wide by 8' high. Reasons to Consider UAB CIS • Undergraduate Research Opportunities 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. 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. Possible Honors Mentoring Ideas • LEGO will release the brand new NXT robot over the summer Exciting new capabilities include wireless communication and vision • At UAB, we will have 5 of these robots for experimentation purposes (July 2006) Possible Mentoring Ideas • Target Recognition in a Rescue Mission A group of coordinated robots will work together to conduct a search/rescue mission • Sniper Identification A group of autonomous robots will be used to isolate the location of sniper fire in a military application (using triangulation) • Speech and Vision Recognition Voice controlled commands to a robot that also can use the vision camera to avoid colliding with objects • Game Playing Robot Tic-tac-toe; Othello 2-on-2 soccer • YOUR IDEA HERE! Of course, we encourage creativity if you have new ideas! Reasons to Consider UAB CIS • Undergraduate Research Opportunities 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. 3 First Place Winners: UAB CIS students received first place in all categories (Undergrad, Masters, PhD) amid students from 7 states. Reasons to Consider UAB CIS • Programming Contest Team 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. In 2005, the UAB programming team placed among the top 25 out of 64 universities and had the highest score among Alabama Universities. The Need for Software Engineering • Programming “In the Large” vs “In the Small” 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!. 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 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. 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 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 ti 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 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 lau 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 continue 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 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. 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 Two Techniques for Controlling Structure • Decomposition Technique for dividing systems into modules Well-structured program is one with minimal interconnections between its modules (low-coupling) More to be said in later lectures • Precise Specification “precisely describing the assumptions that the designers of one module are permitted to make about other modules” More also to be said on this later • Some examples of why it is easier in other “engineering” endeavours… Decomposition and Simple Specification The prong and receptacle parts of a Lego™ block have been unchanged since 1932 [Lego, 2002]. 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]. Even building a dog house takes some engineering From http://www.ttyler.8m.com/Dog%20House.htm Initially started as a "basic" 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. Let’s Get Started!!!!!! Introduction Chapter 5TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights reserved 1 Focus of the Course • Object-Oriented Software Development problem solving program design, implementation, and testing object-oriented concepts • • • • • classes objects encapsulation inheritance polymorphism graphical user interfaces the Java programming language Introduction • We first need to explore the fundamentals of computer processing • Chapter 1 focuses on: components of a computer how those components interact how computers store and manipulate information computer networks the Internet and the World Wide Web programming and programming languages an introduction to Java an overview of object-oriented concepts Outline Computer Processing Hardware Components Networks The Java Programming Language Program Development Object-Oriented Programming Hardware and Software • Hardware the physical, tangible parts of a computer keyboard, monitor, disks, wires, chips, etc. • Software programs and data a program is a series of instructions • A computer requires both hardware and software • Each is essentially useless without the other CPU and Main Memory Central Processing Unit Primary storage area for programs and data that are in active use Synonymous with RAM Main Memory Chip that executes program commands Intel Pentium 4 Sun ultraSPARC III Secondary Memory Devices Secondary memory devices provide long-term storage Hard disks Floppy disks ZIP disks Writable CDs Writable DVDs Tapes Central Processing Unit Information is moved between main memory and secondary memory as needed Hard Disk Main Memory Floppy Disk Input / Output Devices Monitor Keyboard Monitor screen Keyboard Mouse Joystick Bar code scanner Touch screen Central Processing Unit I/O devices facilitate user interaction Hard Disk Main Memory Floppy Disk Software Categories • Operating System controls all machine activities provides the user interface to the computer manages resources such as the CPU and memory Windows XP, Unix, Linux, Mac OS • Application program generic term for any other kind of software word processors, missile control systems, games • Most operating systems and application programs have a graphical user interface (GUI) Analog vs. Digital • There are two basic ways to store and manage data: • Analog continuous, in direct proportion to the data represented music on a record album - a needle rides on ridges in the grooves that are directly proportional to the voltages sent to the speaker • Digital the information is broken down into pieces, and each piece is represented separately music on a compact disc - the disc stores numbers representing specific voltage levels sampled at specific times Digital Information • Computers store all information digitally: numbers text graphics and images video audio program instructions • In some way, all information is digitized - broken down into pieces and represented as numbers Representing Text Digitally • For example, every character is stored as a number, including spaces, digits, and punctuation • Corresponding upper and lower case letters are separate characters Hi, Heather. 72 105 44 32 72 101 97 116 104 101 114 46 Binary Numbers • Once information is digitized, it is represented and stored in memory using the binary number system • A single binary digit (0 or 1) is called a bit • Devices that store and move information are cheaper and more reliable if they have to represent only two states • A single bit can represent two possible states, like a light bulb that is either on (1) or off (0) • Permutations of bits are used to store values Bit Permutations 1 bit 0 1 2 bits 00 01 10 11 3 bits 000 001 010 011 100 101 110 111 4 bits 0000 1000 0001 1001 0010 1010 0011 1011 0100 1100 0101 1101 0110 1110 0111 1111 Each additional bit doubles the number of possible permutations Bit Permutations • Each permutation can represent a particular item • There are 2N permutations of N bits • Therefore, N bits are needed to represent 2N unique items 1 bit ? 21 = 2 items How many items can be represented by 2 2 bits ? 2 = 4 items 3 bits ? 23 = 8 items 4 bits ? 24 = 16 items 5 bits ? 25 = 32 items Outline Computer Processing Hardware Components Networks The Java Programming Language Program Development Object-Oriented Programming A Computer Specification • Consider the following specification for a personal computer: 2.8 GHz Pentium 4 Processor 512 MB RAM 80 GB Hard Disk 48x CD-RW / DVD-ROM Combo Drive 17” Video Display with 1280 x 1024 resolution 56 Kb/s Modem • What does it all mean? Memory 9278 9279 9280 9281 9282 9283 9284 9285 9286 Main memory is divided into many memory locations (or cells) Each memory cell has a numeric address, which uniquely identifies it Storing Information 9278 9279 9280 9281 9282 9283 9284 9285 9286 10011010 Each memory cell stores a set number of bits (usually 8 bits, or one byte) Large values are stored in consecutive memory locations Storage Capacity • Every memory device has a storage capacity, indicating the number of bytes it can hold • Capacities are expressed in various units: Unit Symbol Number of Bytes kilobyte KB 210 = 1024 megabyte MB 220 (over 1 million) gigabyte GB 230 (over 1 billion) terabyte TB 240 (over 1 trillion) Memory • Main memory is volatile - stored information is lost if the electric power is removed • Secondary memory devices are nonvolatile • Main memory and disks are direct access devices - information can be reached directly • The terms direct access and random access often are used interchangeably • 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 RAM vs. ROM • RAM - Random Access Memory (direct access) • ROM - Read-Only Memory • The terms RAM and main memory are basically interchangeable • ROM could be a set of memory chips, or a separate device, such as a CD ROM • Both RAM and ROM are random (direct) access devices! • RAM probably should be called Read-Write Memory Compact Discs • A CD-ROM is portable read-only memory • A microscopic pit on a CD represents a binary 1 and a smooth area represents a binary 0 • A low-intensity laser reflects strongly from a smooth area and weakly from a pit • A CD-Recordable (CD-R) drive can be used to write information to a CD once • A CD-Rewritable (CD-RW) can be erased and reused • The speed of a CD drive indicates how fast (max) it can read and write information to a CD DVDs • A DVD is the same size as a CD, but can store much more information • The format of a DVD stores more bits per square inch • A CD can store 650 MB, while a standard DVD can store 4.7 GB A double sided DVD can store 9.4 GB Other advanced techniques can bring the capacity up to 17.0 GB • Like CDs, there are DVD-R and DVD-RW discs The Central Processing Unit • A CPU is on a chip called a microprocessor • It continuously follows the fetch-decode-execute cycle: Retrieve an instruction from main memory fetch execute Carry out the instruction decode Determine what the instruction is The Central Processing Unit • The CPU contains: Arithmetic / Logic Unit Control Unit Registers Performs calculations and makes decisions Coordinates processing steps Small storage areas The Central Processing Unit • The speed of a CPU is controlled by the system clock • The system clock generates an electronic pulse at regular intervals • The pulses coordinate the activities of the CPU • The speed is usually measured in gigahertz (GHz) Monitor • The size of a monitor (17") is measured diagonally, like a television screen • Most monitors these days have multimedia capabilities: text, graphics, video, etc. • A monitor has a certain maximum resolution , indicating the number of picture elements, called pixels, that it can display (such as 1280 by 1024) • High resolution (more pixels) produces sharper pictures Modem • Data transfer devices allow information to be sent and received between computers • Many computers include a modulator-demodulator or modem, which allows information to be moved across a telephone line • A data transfer device has a maximum data transfer rate • A modem, for instance, may have a data transfer rate of 56,000 bits per second (bps) Agenda – Thursday June 6 • Summary from Last Lecture Motivation for studying CS and UAB opportunities Analog vs Digital Binary Numbers Hardware Categories • Today Textbook Issue First Lab in the Morning Finish Chapter 1 • Thursday Begin Chapter 2 Tour of Supercomputer and Visualization Room • Be on Time for Class! Review of Binary Numbers: Converting Binary to Decimal • Consider what the decimal number “1,234” means: 1234 = 1000 + 200 + 30 + 4 = 1*1000 + 2*100 + 3*10 + 4 * 1 = 1*103 + 2*102 + 3*101 + 4*100 • In general, na…n1n0 represented in base “b” is: na…n1n0 = na*ba + … + n1*b1 + n0*b0 • Apply this to generalization to binary “01101100” (b=2) 01101100 = 0*27 + 1*26 + 1*25 + 0*24 + 1*23 + 1*22 + 0*21 + 0*20 = 0*128 + 1*64 + 1*32 + 0*16 + 1*8 + 1*4 + 0*2 + 0*1 =0 + 64 + 32 + 0 +8 +4 +0 +0 = 64 + 32 + 8 + 4 = 108 Review of Binary Numbers: Converting Decimal to Binary Step 1: See if the number is divisible by 2. • If it is divisible by 2, write ‘0’ and divide by 2 to get the next number. • 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. 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. Step 3: You should always check your answer to make sure that your conversion is correct. Review of Binary Numbers: Converting Decimal to Binary Lets convert the decimal number 241 to binary 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 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 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 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 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 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 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 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 Review of Binary Numbers • Some helpful references (thanks to Adam Dane) Cartoon • http://static.instructables.com/data/uuid/EB/9C7EE0/7C8710 28A786001143E7E506/EB9C7EE07C871028A786001143E7E5 06.pdf Binary game • http://forums.cisco.com/CertCom/game/binary_game_page. htm?site=celc Outline Computer Processing Hardware Components Networks The Java Programming Language Program Development Object-Oriented Programming Networks • A network is two or more computers that are connected so that data and resources can be shared • Most computers are connected to some kind of network • Each computer has its own network address, which uniquely identifies it among the others • 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) Network Connections • Each computer in a network could be directly connected to every other computer in the network • These are called point-to-point connections Adding a computer requires a new communication line for each computer already in the network This technique is not practical for more than a few close machines – why? Network Connections • Most networks share a single communication line • Adding a new computer to the network is relatively easy 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 Local-Area Networks A Local-Area Network (LAN) covers a small distance and a small number of computers LAN A LAN often connects the machines in a single room or building Wide-Area Networks A Wide-Area Network (WAN) connects two or more LANs, often over long distances LAN LAN A LAN usually is owned by one organization, but a WAN often connects groups in different countries The Internet • The Internet is a WAN which spans the entire planet • The word Internet comes from the term internetworking • It started as a United States government project, sponsored by the Advanced Research Projects Agency (ARPA) - originally it was called the ARPANET • The Internet grew quickly throughout the 1980s and 90s TCP/IP • A protocol is a set of rules that determine how things communicate with each other • The software which manages Internet communication follows a suite of protocols called TCP/IP • The Internet Protocol (IP) determines the format of the information as it is transferred • The Transmission Control Protocol (TCP) dictates how messages are reassembled and handles lost information IP and Internet Addresses • Each computer on the Internet has a unique IP address, such as: 204.192.116.2 • Most computers also have a unique Internet name, which also is referred to as an Internet address: spencer.villanova.edu kant.gestalt-llc.com • The first part indicates a particular computer (spencer) • The rest is the domain name, indicating the organization (villanova.edu) Domain Names • The last part of a domain name, called a top-level domain (TLD), indicates the type of organization: edu com org net - educational institution commercial entity non-profit organization network-based organization Sometimes the suffix indicates the country: uk au ca se - United Kingdom Australia Canada Sweden New TLDs have recently been added: biz, info, tv, name Domain Names • A domain name can have several parts • When used, an Internet address is translated to an IP address by software called the Domain Name System (DNS) • There is no one-to-one correspondence between the sections of an IP address and the sections of an Internet address • Looking up the owner of a domain name: `Who-IS: http://www.internic.net/whois.html The World Wide Web • The World Wide Web allows many different types of information to be accessed using a common interface • A browser is a program which accesses and presents information text, graphics, video, sound, audio, executable programs • A Web document usually contains links to other Web documents, creating a hypermedia environment • The term Web comes from the fact that information is not organized in a linear fashion The World Wide Web • Web documents are often defined using the HyperText Markup Language (HTML) • Information on the Web is found using a Uniform Resource Locator (URL): http://www.lycos.com http://www.villanova.edu/webinfo/domains.html ftp://java.sun.com/applets/animation.zip • A URL indicates a protocol (http), a domain, and possibly specific documents Outline Computer Processing Hardware Components Networks The Java Programming Language Program Development Object-Oriented Programming Java • A programming language specifies the words and symbols that we can use to write a program • A programming language employs a set of rules that dictate how the words and symbols can be put together to form valid program statements • The Java programming language was created by Sun Microsystems, Inc. • It was introduced in 1995 and it's popularity has grown quickly since Java Program Structure • In the Java programming language: A program is made up of one or more classes A class contains one or more methods A method contains program statements Similar to how a book is broken into chapters, paragraphs, sentences, and words. This serves as an organizational structuring mechanism. • These terms will be explored in detail throughout the course • A Java application always contains a method called main • See Lincoln.java (page 27) Java Program Structure // comments about the class public class MyProgram { class header class body Comments can be placed almost anywhere } Java Program Structure // comments about the class public class MyProgram { // comments about the method public static void main (String[] args) { method body } } method header Comments • Comments in a program are called inline documentation • They should be included to explain the purpose of the program and describe processing steps • They do not affect how a program works • Java comments can take three forms: // 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 */ */ Identifiers • Identifiers are the words a programmer uses in a program • An identifier can be made up of letters, digits, the underscore character ( _ ), and the dollar sign • Identifiers cannot begin with a digit • Java is case sensitive - Total, total, and TOTAL are different identifiers • By convention, programmers use different case styles for different types of identifiers, such as title case for class names - Lincoln upper case for constants - MAXIMUM Identifiers • Sometimes we choose identifiers ourselves when writing a program (such as Lincoln) • Sometimes we are using another programmer's code, so we use the identifiers that he or she chose (such as println) • 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 • A reserved word cannot be used in any other way Reserved Words • The Java reserved words: 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 White Space • Spaces, blank lines, and tabs are called white space • White space is used to separate words and symbols in a program • Extra white space is ignored • A valid Java program can be formatted many ways • Programs should be formatted to enhance readability, using consistent indentation • See Lincoln2.java (page 33) • See Lincoln3.java (page 34) Outline Computer Processing Hardware Components Networks The Java Programming Language Program Development Object-Oriented Programming Program Development • The mechanics of developing a program include several activities writing the program in a specific programming language (such as Java) translating the program into a form that the computer can execute investigating and fixing various types of errors that can occur • Software tools can be used to help with all parts of this process • Integrated Development Environments (IDEs) like Eclipse combine all of these activites Language Levels • There are four programming language levels: machine language assembly language high-level language fourth-generation language • Each type of CPU has its own specific machine language • The other levels were created to make it easier for a human to read and write programs Programming Languages • Each type of CPU executes only a particular machine language • A program must be translated into machine language before it can be executed • A compiler is a software tool which translates source code into a specific target language • Often, that target language is the machine language for a particular CPU type • The Java approach is somewhat different Java Translation • The Java compiler translates Java source code into a special representation called bytecode • Java bytecode is not the machine language for any traditional CPU • Another software tool, called an interpreter, translates bytecode into machine language and executes it • Therefore, the Java compiler is not tied to any particular machine • Java is considered to be architecture-neutral Java Translation Java source code Java compiler Java bytecode Bytecode interpreter Bytecode compiler Machine code Development Environments • There are many programs that support the development of Java software, including: Sun Java Development Kit (JDK) Sun NetBeans IBM Eclipse Borland JBuilder MetroWerks CodeWarrior BlueJ jGRASP • Though the details of these environments differ, the basic compilation and execution process is essentially the same Syntax and Semantics • The syntax rules of a language define how we can put together symbols, reserved words, and identifiers to make a valid program • The semantics of a program statement define what that statement means (its purpose or role in a program) • A program that is syntactically correct is not necessarily logically (semantically) correct • A program will always do what we tell it to do, not what we meant to tell it to do Errors • A program can have three types of errors • The compiler will find syntax errors and other basic problems (compile-time errors) If compile-time errors exist, an executable version of the program is not created • A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors) • A program may run, but produce incorrect results, perhaps using an incorrect formula (logical errors) Basic Program Development Edit and save program errors errors Compile program Execute program and evaluate results Outline Computer Processing Hardware Components Networks The Java Programming Language Program Development Object-Oriented Programming Problem Solving • The purpose of writing a program is to solve a problem • Solving a problem consists of multiple activities: Understand the problem Design a solution Consider alternatives and refine the solution Implement the solution Test the solution • These activities are not purely linear – they overlap and interact Problem Solving • The key to designing a solution is breaking it down into manageable pieces • When writing software, we design separate pieces that are responsible for certain parts of the solution • An object-oriented approach lends itself to this kind of solution decomposition • We will dissect our solutions into pieces called objects and classes Object-Oriented Programming • Java is an object-oriented programming language • As the term implies, an object is a fundamental entity in a Java program • Objects can be used effectively to represent realworld entities • For instance, an object might represent a particular employee in a company • Each employee object handles the processing and data management related to that employee Objects • An object has: state - descriptive characteristics behaviors - what it can do (or what can be done to it) • The state of a bank account includes its account number and its current balance • The behaviors associated with a bank account include the ability to make deposits and withdrawals • Note that the behavior of an object might change its state Classes • An object is defined by a class • A class is the blueprint of an object • The class uses methods to define the behaviors of the object • The class that contains the main method of a Java program represents the entire program • A class represents a concept, and an object represents the embodiment of that concept • Multiple objects can be created from the same class Objects and Classes A class (the concept) An object (the realization) Bank Account John’s Bank Account Balance: $5,257 Multiple objects from the same class Bill’s Bank Account Balance: $1,245,069 Mary’s Bank Account Balance: $16,833 Inheritance • One class can be used to derive another via inheritance • Classes can be organized into hierarchies Account Charge Account Bank Account Savings Account Checking Account Summary • Chapter 1 focused on: components of a computer how those components interact how computers store and manipulate information computer networks the Internet and the World Wide Web programming and programming languages an introduction to Java an overview of object-oriented concepts