Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 1 An Introduction to Computer, Programming and Java 1.

Similar presentations


Presentation on theme: "Lecture 1 An Introduction to Computer, Programming and Java 1."— Presentation transcript:

1 Lecture 1 An Introduction to Computer, Programming and Java 1

2 What is a Computer? 2 A computer is a machine that performs computations, logical operations, or more generally, data manipulation according to some prescribed sequence of instructions called a computer program. The physical components of a computer are termed hardware and the programs software.

3 The Hardware 3 The major hardware components:  The central processing unit (CPU) ‏  Primary or random access memory (RAM) ‏  Secondary or long term memory  Input and output devices (I/O devices) ‏

4 The Central Processing Unit 4 The CPU does:  the computing  the processing  the majority of the work Important components of the CPU:  arithmetic and logic unit (ALU) ‏  control unit (CU) ‏  clock

5 The Central Processing Unit 5  The ALU performs calculations, billions per second  The CU controls or coordinates which calculations the ALU performs  The CPU clock determines how frequently the computer hardware executes instructions.  A system’s hardware components are synchronized with the clock. Every time the clock ticks, another hardware action occurs.

6 Primary or Random Access Memory 6 How Data is Stored  binary format  a sequence of 0’s and 1's called bits. ASCII encoding:  ‘a’ is represented by 01100001  ‘b’ is encoded as 01100010 A sequence of eight bits is called a byte.

7 Where Data is Stored 7  When the CPU executes a program, the program instructions, along with relevant data, are stored in primary memory.  Primary memory is also known as random access memory (RAM) because data may be retrieved or accessed in random, rather than sequential, order.

8 Where Data Is Stored 8  You can conceptualize RAM as a collection of storage cells or boxes, each capable of holding just a single byte of information.  A unique number, or memory address, identifies each such storage cell.

9 Secondary Memory 9  Long term  Permanent storage Secondary memory devices:  hard disks  tapes  CDs  flash memory sticks.

10 Secondary Memory 10  The programs that you use every day such as word processors, spreadsheets, and games are permanently stored on secondary storage devices.  Compared to RAM, secondary memory is, in general, cheaper (per bit), slower, larger, electromechanical rather than electronic, and persistent: secondary memory devices do not lose their values when you turn off the computer.

11 Input/Output Devices 11 Standard input devices:  keyboards  mouses  joysticks  stylus pens  cameras  microphones Output devices:  monitors  printers  speakers

12 The Software 12  The programs that run on a computer are collectively known as software. Word processors, internet browsers, editors, database management systems, computer games, and spreadsheets are all part of your computer's software library.  When you turn on or boot your computer, a program called the operating system automatically runs. This special program provides an interface between you and your computer.

13 Programming Languages 13 Machine Language  Assembly Language  High-Level Language Machine language is a set of primitive instructions built into every computer. The instructions are in the form of binary code, so you have to enter binary codes for various instructions. Program with native machine language is a tedious process. Moreover the programs are highly difficult to read and modify. For example, to add two numbers, you might write an instruction in binary like this: 1101101010011010

14 Programming Languages 14 Assembly languages were developed to make programming easy. Since the computer cannot understand assembly language, however, a program called assembler is used to convert assembly language programs into machine code. For example, to add two numbers, you might write an instruction in assembly code like this: ADDF3 R1, R2, R3

15 Programming Languages 15 The high-level languages are English-like and easy to learn and program. For example, the following is a high-level language statement that adds two numbers: total = 3 + 4;

16 Popular High-Level Languages 16  COBOL (COmmon Business Oriented Language)  FORTRAN (FORmula TRANslation)  BASIC (Beginner All-purpose Symbolic Instructional Code)  Pascal (named for Blaise Pascal)  Ada (named for Ada Lovelace)  C (whose developer designed B first)  Visual Basic (Basic-like visual language developed by Microsoft)  Delphi (Pascal-like visual language developed by Borland)  C++ (an object-oriented language, based on C)  C# (a Java-like language developed by Microsoft)  Java (We use it in the book)

17 Programming and Algorithms 17  An algorithm is a finite, step-by-step procedure for accomplishing some task or solving a problem.  The study of algorithms is a basis of computer science.  A programming language is your tool, a tool that you can use to investigate and implement algorithms.

18 Compiling Source Code 18 A program written in a high-level language is called a source program. A computer cannot understand a source program. Program called a compiler is used to translate the source program into a machine language program called an object program. The object program is often then linked with other supporting library code before the object can be executed on the machine.

19 The Compiler  The program must be translated into the machine language of that computer.  Accepts a program written in a high-level language and produces a translation into the target machine language.

20 Java 20  General-purpose language developed by Sun Microsystems in the early 1990s, which became part of Oracle Corporation in 2010. Three main goals for their new language:  Platform Independence - Java programs should be capable of running on any computer.  Security - Java programs should not be susceptible/open to hackers' code and dangerous viruses.  Reliability - Java programs should not "crash.”

21 The Java Virtual Machine 21  In order to make Java a cross-platform programming language, Java's creative team designed an abstract computer implemented in software called the Java Virtual Machine (JVM). You install software on your computer that simulates a JVM computer. The machine language of the JVM is called bytecode. Java programs are first compiled into bytecode, and then executed.

22 The Java Virtual Machine  The Java interpreter, which is part of the JVM, executes each bytecode instruction, one by one. Once a Java program is translated into bytecode, the bytecode can run on any computer that has installed the JVM. A Java program needs to be compiled into bytecode just once.

23 Java, Web, and Beyond 23  Java can be used to develop any applications.  Java Applets  Java Web Applications  Java can also be used to develop applications for hand-held devices such as Palm, cell phones, PC Tablets, etc.

24 PDA and Cell Phone 24

25 Java’s History 25  James Gosling and Sun Microsystems  Oak  HotJava  The first Java-enabled Web browser  Bought by Oracle Corporation in January 2010  Java History Website: http://en.wikipedia.org/wiki/Java_(programming_language)

26 Characteristics of Java 26  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture-Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic http://www.cs.armstrong.edu/liang/intro8e/JavaCharacteristics.pdf

27 Characteristics of Java 27  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture-Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic Java is partially modeled on C++, but greatly simplified and improved. Some people refer to Java as "C++--" because it is like C++ but with more functionality and fewer negative aspects.

28 Characteristics of Java 28  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture-Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic Java is inherently object-oriented. Although many object-oriented languages began strictly as procedural languages, Java was designed from the start to be object-oriented. Object-oriented programming (OOP) is a popular programming approach that is replacing traditional procedural programming techniques. One of the central issues in software development is how to reuse code. Object- oriented programming provides great flexibility, modularity, clarity, and reusability through encapsulation, inheritance, and polymorphism.

29 Characteristics of Java 29  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture-Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic Distributed computing involves several computers working together on a network. Java is designed to make distributed computing easy. Since networking capability is inherently integrated into Java, writing network programs is like sending and receiving data to and from a file.

30 Characteristics of Java 30  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture-Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic You need an interpreter to run Java programs. The programs are compiled into the Java Virtual Machine code called bytecode. The bytecode is machine- independent and can run on any machine that has a Java interpreter, which is part of the Java Virtual Machine (JVM).

31 Characteristics of Java 31  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture-Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic Java compilers can detect many problems that would first show up at execution time in other languages. Java has eliminated certain types of error- prone programming constructs found in other languages. Java has a runtime exception-handling feature to provide programming support for robustness.

32 Characteristics of Java 32  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture-Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic Java implements several security mechanisms to protect your system against harm caused by stray programs.

33 Characteristics of Java 33  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture-Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic Write once, run anywhere With a Java Virtual Machine (JVM), you can write one program that will run on any platform.

34 Characteristics of Java 34  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture-Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic Because Java is architecture neutral, Java programs are portable. They can be run on any platform without being recompiled.

35 Characteristics of Java 35  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture-Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic Because Java is interpreted, the bytecode is not directly executed by the system, but is run through the interpreter. However, its speed is more than adequate for most interactive applications, where the CPU is often idle, waiting for input or for data from other sources.

36 Characteristics of Java 36  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture-Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic Multithread programming is smoothly integrated in Java, whereas in other languages you have to call procedures specific to the operating system to enable multithreading.

37 Characteristics of Java 37  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture-Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic Java was designed to adapt to an evolving environment. New code can be loaded on the fly without recompilation. There is no need for developers to create, and for users to install, major new software versions. New features can be incorporated transparently as needed.

38 JDK Versions 38  JDK 1.02 (1995)  JDK 1.1 (1996)  JDK 1.2 (1998)  JDK 1.3 (2000)  JDK 1.4 (2002)  JDK 1.5 (2004) a. k. a. JDK 5 or Java 5  JDK 1.6 (2006) a. k. a. JDK 6 or Java 6  JDK 1.7 (2010) a. k. a. JDK 7 or Java 7 http://www.oracle.com/technetwork/java

39 JDK Editions 39  Java Standard Edition (J2SE)  J2SE can be used to develop client-side standalone applications or applets.  Java Enterprise Edition (J2EE)  J2EE can be used to develop server-side applications such as Java servlets and Java ServerPages.  Java Micro Edition (J2ME).  J2ME can be used to develop applications for mobile devices such as cell phones.

40 A Simple Java Program 40 //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } Listing 1.1

41 Creating and Editing Using NotePad 41 To use NotePad, type notepad Welcome.java from the command prompt.

42 Creating and Editing Using WordPad 42 To use WordPad, type write Welcome.java from the command prompt.

43 Creating, Compiling, and Running Programs 43

44 Compiling and Running Java from the Command Window 44  Set path to JDK bin directory  set path=c:\Program Files\java\jdk1.7.0\bin  Set classpath to include the current directory  set classpath=.  Compile  javac Welcome.java  Run  java Welcome

45 Acknowledgement 45  The lecture notes for this course include slides from:  Daniel Liang – Introduction to Java Programming, 2011  Antonio Martinez – Java Programming: From the Ground Up, 2010


Download ppt "Lecture 1 An Introduction to Computer, Programming and Java 1."

Similar presentations


Ads by Google