Published on

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

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Introduction to Java Programming Y. Daniel Liang
  2. 2. Introduction <ul><li>What is a computer? </li></ul><ul><ul><li>Electronic devices that stores and process data </li></ul></ul><ul><ul><li>Includes both hardware and software </li></ul></ul><ul><li>Hardware – physical aspects that you can see </li></ul><ul><ul><li>Central Processing Unit (CPU) </li></ul></ul><ul><ul><li>Memory (main memory) </li></ul></ul><ul><ul><li>Storage Devices (hard disk, floppy disk, CDs, tapes) </li></ul></ul><ul><ul><li>Input and Output Devices (monitors, keyboards, mice, printers) </li></ul></ul><ul><ul><li>Communication Devices (modems and network interface cards) </li></ul></ul>
  3. 3. Hardware <ul><li>Central Processing Unit (CPU) </li></ul><ul><ul><li>Brain of a computer </li></ul></ul><ul><ul><li>Retrieves instructions from memory and executes them </li></ul></ul><ul><ul><li>2 components: </li></ul></ul><ul><ul><ul><li>control unit </li></ul></ul></ul><ul><ul><ul><ul><li>controls and coordinates the actions of the other components </li></ul></ul></ul></ul><ul><ul><ul><li>arithmetic/logic unit </li></ul></ul></ul><ul><ul><ul><ul><li>perform numeric operations (addition, subtraction, multiplication, division) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Perform logic operations (comparison) </li></ul></ul></ul></ul><ul><ul><ul><li>Built on semiconductor chip with millions of transistors </li></ul></ul></ul>
  4. 4. Hardware <ul><li>Memory (main memory) </li></ul><ul><ul><li>Data are encoded as a series of bits. </li></ul></ul><ul><ul><li>Bit – b inary dig it : zero and one </li></ul></ul><ul><ul><li>Stores data and program instructions for CPU to execute </li></ul></ul><ul><ul><li>A memory unit is an ordered sequence of bytes, each holding 8 bits </li></ul></ul><ul><ul><li>Encoding scheme: ASCII </li></ul></ul>
  5. 5. Hardware <ul><li>Memory (main memory) </li></ul><ul><ul><li>A program and its data must be brought to memory before they can be executed </li></ul></ul><ul><ul><li>The content of memory is lost when new infor is placed in it. </li></ul></ul><ul><ul><li>Each byte has a unique address, used to locate the byte. </li></ul></ul><ul><ul><li>Can be accessed in any order, thus is called RAM (Random-access memory) </li></ul></ul><ul><ul><li>1 Megabyte (MB) is about 1 million bytes. </li></ul></ul><ul><ul><li>Also built on silicon semiconductor ships containing thousands of transistors, but less complicated. </li></ul></ul><ul><ul><li>Memory is volatile, the content is lost when the power is turned off. </li></ul></ul>
  6. 6. Hardware <ul><li>Storage Devices (hard disk, floppy disk, CDs, tapes) </li></ul><ul><ul><li>Programs and data are stored permanently on storage devices and moved to memory when computer actually uses them. </li></ul></ul><ul><ul><li>4 main types of storage devices: </li></ul></ul><ul><ul><ul><li>Disk drives (hard disks, floppy disks) </li></ul></ul></ul><ul><ul><ul><li>CD drives (CD-R, CD-RW, DVD). DVD stands for Digital versatile disc. </li></ul></ul></ul><ul><ul><ul><li>Tape drives </li></ul></ul></ul><ul><ul><ul><li>USB flash drives </li></ul></ul></ul>
  7. 7. Hardware <ul><li>Input and Output Devices (monitors, keyboards, mice, printers) </li></ul><ul><ul><li>Allows user to communicate with the computer </li></ul></ul><ul><ul><li>Common input devices: keyboards, mice </li></ul></ul><ul><ul><li>Common output devices: monitors, printers. </li></ul></ul>
  8. 8. Hardware <ul><li>Communication Devices (modems and network interface cards) </li></ul><ul><ul><li>To create network of computers </li></ul></ul>
  9. 9. Software <ul><li>Software/computer program </li></ul><ul><ul><li>invisible instructions that control the hardware and make it perform specific tasks. </li></ul></ul><ul><ul><li>Tell computer what to do in computer/machine language </li></ul></ul>
  10. 10. Software <ul><li>Computer languages </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>
  11. 11. Software <ul><li>Machine language </li></ul><ul><ul><li>a set of primitive instructions built into every computer </li></ul></ul><ul><ul><li>Different for different types of computers. </li></ul></ul><ul><ul><li>The instructions are in the form of binary code, e.g. to add 2 numbers (very tedious): </li></ul></ul><ul><ul><ul><li>1101101010011010 </li></ul></ul></ul>
  12. 12. Software <ul><li>Assembly language </li></ul><ul><ul><li>Low-level programming language which uses mnemonic to represent machine-language instructions </li></ul></ul><ul><ul><li>E.g.: ADDF3 R1, R2, R3 </li></ul></ul><ul><ul><li>Assembly code need to be converted into machine code by using an assembler </li></ul></ul><ul><ul><li>Assembly program </li></ul></ul><ul><ul><ul><li>is platform dependent </li></ul></ul></ul><ul><ul><ul><li>Combination of mnemonic and machine instruction </li></ul></ul></ul>
  13. 13. Software <ul><li>High-level language </li></ul><ul><ul><li>English-like and easy to learn and program. </li></ul></ul><ul><ul><li>E.g.: </li></ul></ul><ul><ul><ul><li>Area = 5 * 5 * 3.1415; </li></ul></ul></ul><ul><ul><li>COBOL, FORTRAN, BASIC, Pascal, Ada, C, Visual Basic, Delphi, C++, C#, Java </li></ul></ul><ul><ul><li>Source program is compiled into machine code by a compiler and linked to supporting library code by a linker to form an executable file. Fig. 1.4 </li></ul></ul>
  14. 14. Software <ul><li>High-level language (continue) </li></ul><ul><ul><li>Can port/move a source program to any machine with appropriate compilers but the source program must be recompiled </li></ul></ul><ul><ul><li>Java program, compiled it once into intermediate machine code known as bytecode. Bring the bytecode to any computer with a JVM (Java Virtual Machine). JVM interprets the bytecode into the machine codes and execute them. </li></ul></ul>
  15. 15. An overview of the java development process. Source: http://java.sun.com/docs/books/tutorial/getStarted/intro/definition.html
  16. 16. Through the Java VM, the same application is capable of running on multiple platforms. Source: http://java.sun.com/docs/books/tutorial/getStarted/intro/definition.html
  17. 17. Software <ul><li>Compiling versus interpreting </li></ul><ul><ul><li>Compiling translates the high-level code into a target language code as a single unit </li></ul></ul><ul><ul><li>Interpreting translates the individual steps in the high level code one at a time. Each step is execute immediately after it is translated. </li></ul></ul>
  18. 18. Software <ul><li>Operating system (OS) </li></ul><ul><ul><li>Software that controls and manages the systems </li></ul></ul><ul><ul><li>Fig. 1.6, page 36. </li></ul></ul><ul><ul><li>E.g.: Windows (98, NT, XP, ME), MacOS, Linux etc. </li></ul></ul><ul><ul><li>Major tasks </li></ul></ul><ul><ul><ul><li>Controlling and monitoring system activities (security, input, output, file directories, make sure programs running together do not interfere with each other) </li></ul></ul></ul><ul><ul><ul><li>Allocating and assigning system resources to program </li></ul></ul></ul><ul><ul><ul><li>Scheduling operations </li></ul></ul></ul><ul><ul><ul><ul><li>Multiprogramming – multiple programs to run simultaneously by sharing CPU </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Multithreading – allows concurrency within a program; it subunits can run at the same time (e.g. editing and saving at the same time) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Multiprocessing/parallel processing – use 2 or more processors together to perform a task. </li></ul></ul></ul></ul>
  19. 19. What Is Java? <ul><li>History </li></ul><ul><li>Characteristics of Java </li></ul>
  20. 20. History <ul><li>James Gosling </li></ul><ul><li>Oak – 1991, for embedded consumer electronic appliances </li></ul><ul><li>Renamed Java, 1995, for developing Internet applications </li></ul><ul><li>HotJava </li></ul><ul><ul><li>The first Java-enabled Web browser </li></ul></ul><ul><li>Java applets – java programs that run from a Web browser </li></ul><ul><ul><li>http://javaboutique.internet.com/movingtree/ </li></ul></ul>
  21. 21. Characteristics of Java <ul><li>Java is simple </li></ul><ul><li>Java is object-oriented </li></ul><ul><li>Java is distributed </li></ul><ul><li>Java is interpreted </li></ul><ul><li>Java is robust </li></ul><ul><li>Java is secure </li></ul><ul><li>Java is architecture-neutral </li></ul><ul><li>Java is portable </li></ul><ul><li>Java’s performance </li></ul><ul><li>Java is multithreaded </li></ul><ul><li>Java is dynamic </li></ul>
  22. 22. Java IDE Tools <ul><li>Inprise JBuilder </li></ul><ul><li>Microsoft Visual J++ </li></ul><ul><li>Symantec Café </li></ul><ul><li>Forte by Sun MicroSystems </li></ul><ul><li>IBM Visual Age for Java </li></ul><ul><li>NetBeans 6.0 (free, open-source IDE, runs on Windows, Linux, Solaris, and the MacOS) </li></ul><ul><li>JCreator LE 4.0 (free) by Xinox Software </li></ul>
  23. 23. Java Language Specification, API, JDK and IDE <ul><li>Java Language Specification </li></ul><ul><ul><li>Technical definition of the language which includes the syntax and semantics of the Java Programming language (java.sun.com/docs/books/jls) </li></ul></ul><ul><li>API </li></ul><ul><ul><li>Contains predefined classes and interfaces for developing Java programs. </li></ul></ul><ul><ul><li>3 editions of Java API </li></ul></ul><ul><ul><ul><li>J2SE - version Java SE 6.0 (jdk1.6.0_02) </li></ul></ul></ul><ul><ul><ul><li>J2EE </li></ul></ul></ul><ul><ul><ul><li>J2ME </li></ul></ul></ul>
  24. 24. Java Language Specification, API, JDK and IDE <ul><li>JDK </li></ul><ul><ul><li>A set of programs for developing and testing Java program, each of which is invoked from a command line. </li></ul></ul><ul><li>IDE (integrated development environment) </li></ul><ul><ul><li>Software that provides integrated development environment (editing, compiling, building, debugging and online help) for rapidly developing Java program </li></ul></ul>
  25. 25. Getting Started with Java Programming <ul><li>A Simple Java Application </li></ul><ul><li>Compiling Programs </li></ul><ul><li>Executing Applications </li></ul>
  26. 26. A Simple Application <ul><li>Example 1.1 </li></ul><ul><li>//This application program prints Welcome </li></ul><ul><li>//to Java! </li></ul><ul><li>public class Welcome </li></ul><ul><li>{ </li></ul><ul><li>public static void main(String[] args) </li></ul><ul><li>{ </li></ul><ul><li>System.out.println(&quot;Welcome to Java!&quot;); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Run Source
  27. 27. Creating, compiling and executing a Java Programs <ul><li>Fig. 1.11, page: 44. </li></ul>
  28. 28. Compiling Programs <ul><li>On command line </li></ul><ul><ul><li>javac file.java </li></ul></ul>
  29. 29. Executing Applications <ul><li>On command line </li></ul><ul><ul><li>java classname </li></ul></ul>
  30. 30. Example <ul><li>javac Welcome.java </li></ul><ul><li>java Welcome </li></ul><ul><li>output:... </li></ul>
  31. 31. Anatomy of a Java program <ul><li>Comments </li></ul><ul><li>Reserved words </li></ul><ul><li>Modifier </li></ul><ul><li>Statement </li></ul><ul><li>Block </li></ul><ul><li>Class </li></ul><ul><li>Method </li></ul><ul><li>The main method </li></ul>
  32. 32. Anatomy of a Java program <ul><li>Comments </li></ul><ul><ul><li>Documents the program for understanding purpose </li></ul></ul><ul><ul><li>Ignored by compiler </li></ul></ul><ul><ul><li>// </li></ul></ul><ul><ul><li>/* */ </li></ul></ul><ul><li>Reserved words or keywords </li></ul><ul><ul><li>Words that have specific meaning to the compiler and cannot be used for other purposes in the program </li></ul></ul><ul><ul><li>E.g: public, static, class, void </li></ul></ul>
  33. 33. Anatomy of a Java program <ul><li>Modifier </li></ul><ul><ul><li>Certain reserved words are modifiers that specify the properties of the data, methods and class and how they can be used. </li></ul></ul><ul><ul><li>E.g: public, private, static, final, abstract, protected. </li></ul></ul><ul><li>Statement </li></ul><ul><ul><li>Represents an action or a sequence of actions </li></ul></ul><ul><ul><li>Ends with semicolon (;) </li></ul></ul><ul><li>Block </li></ul><ul><ul><li>Groups the components of the program </li></ul></ul><ul><ul><li>Begins with opening brace { and ends with a closing brace } </li></ul></ul><ul><ul><li>Class block, method block </li></ul></ul>
  34. 34. Anatomy of a Java program <ul><li>Class </li></ul><ul><ul><li>Program is defined by using one or more class </li></ul></ul><ul><ul><li>Will be covered in more details later. </li></ul></ul><ul><li>Method </li></ul><ul><ul><li>A collection of statements that perform a sequence of operations. </li></ul></ul><ul><ul><li>Can be used without fully understanding how it works. </li></ul></ul><ul><ul><li>Invoke by calling the method name with the requirement argument </li></ul></ul><ul><li>The main method </li></ul><ul><ul><li>A special method where the program execution begins. </li></ul></ul><ul><ul><li>JVM invokes the main method to execute an application. </li></ul></ul>
  35. 35. Summary
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.