1 / 26

Introduction to Computer Systems and the Java Programming Language

Learn about computer components, memory, binary representation, programming languages, Java programs, and Java Virtual Machine. Get insights into processors, memory types, bit patterns, and high-level programming languages.

goll
Download Presentation

Introduction to Computer Systems and the Java Programming Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Computer Systems and the Java Programming Language

  2. Computer systems • A computer is a system made up of components • Two categories of components: • hardware: electronic and mechanical parts • software: programs and data • Main hardware components of a computer system • Processor (CPU) • Main memory • Secondary memory • Input devices (keyboard, mouse) • Output devices (monitor, printer)

  3. Processor • Central processing unit (CPU), processor chip • “Brain” of the computer • Contains the logic circuitry controlling the interpretation and execution of machine instructions • programmed instructions • arithmetic and logical operations on data • controls input/output functions • Instructions • electronic operations • executed one at a time • millions per second • collection of instructions  executable program

  4. Computer memory • Holds data and programs • Main memory • temporary memory • stores programs and data when the processor is actively using them • random access memory (RAM) • Secondary memory • permanent • stores (saves) programs and data on a long-term basis • hard disk, floppy disks

  5. Binary • In both main and secondary memory, information is stored as patterns of bits • Binary  “Two states” • 1 and 0 • true and false • on and off • Binary devices • can be in just one of two possible states at a time • A single binary value is called a bit • binary digit

  6. Example • A light switch is a binary device • holds one bit of information • can be in one of two states: on or off • can not be in any other possible state • A light dimmer is not a binary device • can be on, off, or some state in-between • difficult to characterize in-between states • how to turn a light exactly 50% or “half” on? • how to tell “how much” a light is on?

  7. Binary representation • Bits can be used to represent patterns • Specifically, any system or set of symbols can be translated into bit patterns • patterns of ones and zeros • 10100001101 • Example: characters from any language alphabet • Require enough bits so that all symbols have a unique bit pattern to represent them • How many bits are needed to represent the English alphabet? • Require set of symbols is finite

  8. Bits and Bytes • Bit • single binary or 0/1 value • One bit of information is so little that usually computer memory is organized into groups of eight bits • Byte: group of eight bits • kilobyte (KB): 210 = 1024 bytes • megabyte (MB): 220 = 1,048,576bytes • 1MB = 210KB • gigabyte (GB): 230 = 1,073,741,824 bytes • 1GB = 210 MB

  9. High-level programming languages • Most programs are created using a high level programming language • closer to human language than machine language (low-level) • Java, C, C++, Pascal, FORTRAN • easier to read, write, and maintain • Source programs are translated to executable (machine language) programs by a compiler • Different programming languages require different compilers • Language can have many compilers • computer type, software package

  10. Source program  Executable program • Create source program using a text editor • written (typed) instructions in a high-level language • Save source program on disk • Compile source program • compiler translates source program to executable program • source program remains unchanged • a new executable program is created • executable program is saved on disk • Run executable program • copied into main memory and run by processor

  11. HelloWorld.java import java.awt.*; public class HelloWorld extends java.applet.Applet { TextField t; public void init() { t = new TextField(50); t.setText(“Hello World!"); add(t); } }

  12. Java programs • Java programs are created as text files using a text editor (like emacs!) • Save to disk with.java file extension HelloWorld.java • The file contains characters (stored as bytes) • file can be printed, displayed on monitor, or edited • file cannot be directly executed (run) by the computer system • Java must first translate the program into bytecodes before it can be run

  13. Bytecodes • Java bytecode • machine instruction for the Java processor • Java compiler javac translates the source program into bytecodes • Bytecode file has same name as the source program with a with.class file extension HelloWorld.class HelloWorld.java javac HelloWorld.class Javacompiler source program Java bytecodes

  14. Java Virtual Machine (JVM) • Bytecode (class) file will contain exactly the same bytecodes no matter what computer system is used • Bytecode file is executed by a Java bytecode interpreter • processor specific executable program • Each type of computer system has its own Java interpreter that can run on that system. • Any computer system can execute Java bytecode programs if it has a Java interpreter • Computers with Java interpreters are called Java Virtual Machines • a “computer” with a Java processor that can run Java bytecodes

  15. Java applets • An applet is a Java bytecode program that runs on a Web browser • Most newer Web browsers have Java interpreters • Web pages on the Internet contain instructions that send Java bytecodes to your computer • Web browser runs the Java applet with its built-in interpreter

  16. Data Types • Computer memory stores arbitrary bit patterns • Meaning of a bit pattern depends its use • The particular pattern used for a particular string of bits is a data type. • uses bits to represent values • values are any kind of data a computer can process • all values are represented using some data type • Example: What does the following pattern of 16 bits represent? 0000000001100111 • No way to know without more information • If data type is short (a Java type) it represents 103

  17. Java data types • Primitive • types of data that are so fundamental ways to represent them are built into Java • Reference • reference to (an address of) the value or set of values represented by the variable

  18. Primitive data types • Primitive data values use fixed number of bytes • There are exactly eight primitive data types: byte, short, int, long, float, double, char, boolean • A programmer can not create new primitive data types • Any data type you invent will be a type of object

  19. Java primitive data types

  20. Declaration and initialization • Declaration: type <variable-name>; type <variable-name> = <value>; • Variable names • any combination of letters, numbers, and the underscore character • may not start with number • may not be reserved word (int, return) • may not be same as method name • case-sensitive (num and Num are different)

  21. Examples • int x, y, z; • int sum = 0; • float f; • double pi = 3.14; • char first = ‘T’, middle = ‘L’, last = ‘B’; • char first = ‘T’; char middle = ‘L’; char last = ‘B’;

  22. Basic operators

  23. Conditional statements • if-else if( expression ){… statements …}else{… statements …}

  24. Conditional statements • while while( expression ){… statements …} • for for( initialization; test; update ){… statements …}

  25. Java methods int sum_between(int x, int y) { int k, sum = 0; for(k = x; k <= y; k++) { sum = sum+k; } return sum; }

More Related