Introduction to Java Chapter 1 Prof Nick Diaz

  • Slides: 22
Download presentation
Introduction to Java Chapter 1 Prof. Nick Diaz

Introduction to Java Chapter 1 Prof. Nick Diaz

Prerequisites

Prerequisites

Objectives: • • To review computer basics, programs, and operating systems. • • •

Objectives: • • To review computer basics, programs, and operating systems. • • • To distinguish the terms API, IDE, and JDK. To understand the relationship between Java and the World Wide Web). To write a simple Java program. To create, compile, and run Java programs. To know the basic syntax of a Java program. To display output in a dialog box.

Introduction You use word processors to write documents, Web browsers to explore the Internet,

Introduction You use word processors to write documents, Web browsers to explore the Internet, and email programs to send email over the Internet. Word processors, browsers, and email programs are all examples of software that runs on computers. Software is developed using programming languages. There are many programming languages. So why Java? The answer is that Java enables users to develop and deploy applications on the Internet for servers, desktop computers, and small hand-held devices. The future of computing is being profoundly influenced by the Internet, and Java promises to remain a big part of that future. Java is the Internet programming language.

What is a Computer? A computer is an electronic device that stores and processes

What is a Computer? A computer is an electronic device that stores and processes data. A computer includes both hardware and software. In general, hardware is the physical aspect of the computer that can be seen, and software is the invisible instructions that control the hardware and make it perform specific tasks. Computer programming consists of writing instructions for computers to perform. You can learn a programming language without knowing computer hardware, but you will be better able to understand the effect of the instructions in the program if you do. Computer hardware components and their functionality.

Central Processing Unit The central processing unit (CPU) is the brain of a computer.

Central Processing Unit The central processing unit (CPU) is the brain of a computer. It retrieves instructions from memory and executes them. The CPU usually has two components: a control unit and an arithmetic/logic unit. The control unit controls and coordinates the actions of the other components. The arithmetic and logic unit performs numeric operations (addition, subtraction, multiplication, division) and logical operations (comparisons). Today's CPU is built on a small silicon semiconductor chip with millions of transistors. The speed of the CPU is mainly determined by clock speed. Every computer has an internal clock. The faster the clock speed, the more instructions are executed in a given period of time. The clock emits electronic pulses at a constant rate, and these are used to control and synchronize the pace of operations. The unit of measurement is called a hertz (Hz), with 1 hertz equaling 1 pulse per second. The clock speed of computers is usually measured in megahertz (MHz) (1 MHz is 1 million Hz). The speed of the CPU has been improved continuously. If you buy a PC now, you can get an Intel Pentium 4 Processor at 3 gigahertz (GHz) (1 GHz is 1000 MHz).

Memory Computers use zeros and ones because digital devices have two stable states, referred

Memory Computers use zeros and ones because digital devices have two stable states, referred to as zero and one by convention. Data of various kinds, such as numbers, characters, and strings, are encoded as a series of bits (binary digits: zeros and ones). Memory stores data and program instructions for the CPU to execute. A memory unit is an ordered sequence of bytes, each holding eight bits

Memory The programmer need not be concerned about the encoding and decoding of data,

Memory The programmer need not be concerned about the encoding and decoding of data, which is performed automatically by the system based on the encoding scheme. The encoding scheme varies. For example, character 'J' is represented by 01001010 in one byte in the popular ASCII encoding. A small number such as 3 can be stored in a single byte. If a computer needs to store a large number that cannot fit into a single byte, it uses several adjacent bytes. No two data items can share or split the same byte. A byte is the minimum storage unit. A program and its data must be brought to memory before they can be executed. A memory byte is never empty, but its initial content may be meaningless to your program. The current content of a memory byte is lost whenever new information is placed in it. Every byte has a unique address. The address is used to locate the byte for storing and retrieving data. Since the bytes can be accessed in any order, the memory is also referred to as RAM (random-access memory). Today's personal computers usually have at least 128 megabytes of RAM. A megabyte (abbreviated MB) is about 1 million bytes. Like the CPU, memory is built on silicon semiconductor chips containing thousands of transistors embedded on their surface. Compared to the CPU chips, memory chips are less complicated, slower, and less expensive.

Storage Devices Memory is volatile, because information is lost when the power is turned

Storage Devices Memory is volatile, because information is lost when the power is turned off. Programs and data are permanently stored on storage devices and are moved to memory when the computer actually uses them. The reason for this is that memory is much faster than storage devices. Disks There are two kinds of disks: hard disks and floppy disks. Personal computers usually have a 3. 5 -inch floppy disk drive and a hard drive. A floppy disk has a fixed capacity of about 1. 44 MB. Hard disk capacities vary. The capacity of the hard disks of the latest PCs is in the range of 30 gigabytes to 160 gigabytes. Hard disks provide much faster performance and larger capacity than floppy disks. Both disk drives are often encased inside the computer. A floppy disk is removable. A hard disk is mounted inside the case of the computer. Removable hard disks are also available.

Storage Devices CDs and DVDs CD stands for compact disc. There are two types

Storage Devices CDs and DVDs CD stands for compact disc. There are two types of CD drives: CD-R and CDRW. A CD-R is for read-only permanent storage, and the user cannot modify its contents once they are recorded. A CD-RW can be used like a floppy disk, and thus can be read and rewritten. A single CD can hold up to 700 MB. Most software is distributed through CD-ROMs. Most new PCs are equipped with a CD-RW drive that can work with both CD -R and CD-RW. DVD stands for digital versatile disc. DVDs and CDs look alike. You can store data using a CD or DVD. A DVD can hold more information than a CD. A standard DVD storage is 4. 7 GB in capacity. Tapes are mainly used for backup of data and programs. Unlike disks and CDs, tapes store information sequentially. The computer must retrieve information in the order it was stored. Tapes are very slow. It would take one to two hours to back up a 1 gigabyte hard disk.

Storage Devices USB Flash Drives USB flash drives are popular new devices for storing

Storage Devices USB Flash Drives USB flash drives are popular new devices for storing and transporting data. They are small—about the size of a package of gum. They act like a portable hard disk that can be plugged into the USB port of your computer. USB flash drives are currently available with up to 2 GB storage capacity.

Input and Output Devices Keyboard Mouse Monitor

Input and Output Devices Keyboard Mouse Monitor

Communication Devices Computers can be networked through communication devices. Commonly used communication devices are

Communication Devices Computers can be networked through communication devices. Commonly used communication devices are the dialup modem, DSL, cable modem, and network interface card. A dialup modem uses a phone line and can transfer data at a speed up to 56, 000 bps (bits per second). A DSL (digital subscriber line) also uses a phone line and can transfer data at a speed 20 times faster than a dialup modem. A cable modem uses the TV cable line maintained by the cable company. A cable modem is as fast as DSL. A network interface card (NIC) is a device that connects a computer to a local area network (LAN). The LAN is commonly used in business, universities, and government organizations. A typical NIC called 10 Base. T can transfer data at 10 mbps (million bits per second).

Programs Computer programs, known as software, are instructions to the computer. You tell a

Programs Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs. Without programs, a computer is an empty machine. Computers do not understand human languages, so you need to use computer languages to communicate with them. The language a computer speaks is the computer's native language or machine language. The machine language is a set of primitive instructions built into every computer. Machine languages are different for different type of computers. The instructions are in the form of binary code, so you have to enter binary codes for various instructions. Programming using a 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 have to write an instruction in binary like this: 1101101010011010

Programs Assembly language is a low-level programming language in which a mnemonic is used

Programs Assembly language is a low-level programming language in which a mnemonic is used to represent each of the machine-language instructions. For example, to add two numbers, you might write an instruction in assembly code like this: ADDF 3 R 1, R 2, R 3 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, as shown in Figure

Programs Since assembly language is machine-dependent, an assembly program can only be executed on

Programs Since assembly language is machine-dependent, an assembly program can only be executed on a particular machine. Assembly programs are written in terms of machine instructions with easy-to-remember mnemonic names. The high-level languages were developed in order to overcome the platform-specific problem and make programming easier. The high-level languages are English-like and easy to learn and program. Here, for example, is a high-level language statement that computes the area of a circle with radius 5: area = 5 * 3. 1415;

Programs There are over one hundred high-level languages. The popular languages used today are:

Programs There are over one hundred high-level languages. The popular languages used today are: • • • 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

Programs Each of these languages was designed for a specific purpose. COBOL was designed

Programs Each of these languages was designed for a specific purpose. COBOL was designed for business applications and now is used primarily for business data processing. FORTRAN was designed for mathematical computations and is used mainly for numeric computations. BASIC, as its name suggests, was designed to be learned and used easily. Ada was developed for the Department of Defense and is mainly used in defense projects. C combines the power of an assembly language with the ease of use and portability of a high-level language. Visual Basic and Delphi are used in developing graphical user interfaces and in rapid application development. C++ is popular for system software projects like writing compilers and operating systems. The Microsoft Windows operating system was coded using C++.

Program A program written in a high-level language is called a source program. Since

Program A program written in a high-level language is called a source program. Since a computer cannot understand a source program, a program called a compiler is used to translate the source program into a machine-language program. The machine-language program is often then linked with other supporting library code to form an executable file. The executable file can be executed on the machine, as shown in Figure 1. 4. On Windows, executable files have extension. exe.

Program You can port (i. e. , move) a source program to any machine

Program You can port (i. e. , move) a source program to any machine with appropriate compilers. The source program must be recompiled, however, because the machine-language program can only run on a specific machine. Nowadays computers are networked to work together. Java was designed to run on any platform. With Java, you write the program once and compile the source program into a special type of machine-language code known as bytecode. The bytecode can then run on any computer with a Java Virtual Machine (JVM), as shown in Figure 1. 5. The Java Virtual Machine is software that interprets Java bytecode is Interpreted. The difference between compiling and interpreting is as follows. Compiling translates the high-level code into a target language code as a single unit. Interpreting translates the individual steps in a high-level program one at a time rather than the whole program as a single unit. Each step is executed immediately after it is translated.