Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Computer Systems and the Java Programming Language.

Similar presentations


Presentation on theme: "Introduction to Computer Systems and the Java Programming Language."— 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): 2 10 = 1024 bytes –megabyte (MB): 2 20 = 1,048,576 bytes 1MB = 2 10 KB –gigabyte (GB): 2 30 = 1,073,741,824 bytes 1GB = 2 10 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

12 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); }

13 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

14 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.javajavacHelloWorld.class source program Java compiler Java bytecodes

15 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

16 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

17 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

18 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

19 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

20 Java primitive data types Primitive TypeDescriptionRange byte 8-bit integer-128 to 127 short 16-bit integer-32768 to 32767 int 32-bit integer-2147483648 to 2147483647 long 64-bit integer-2 63 to 2 63 -1 float 32-bit floating point10 -46 to 10 38 double 64-bit floating point10 -324 to 10 308 char Unicode character boolean Boolean variable false and true

21 Declaration and initialization  Declaration: type ; type = ;  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)

22 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’;

23 Basic operators OperatorJavaDescription Assignment = assigns rhs to lhs Arithmetic +,-,*,/,% addition, subtraction, multiplication, division, remainder Unary -,++,-- negative, auto increment, auto decrement Equality ==, != equals to, not equals to Relational,>= less than, less than or equals to, greater than, greater than or equals to Logical &&,||,! AND, OR, NOT

24 Conditional statements  if-else if ( expression ) { … statements … } else { … statements … }

25 Conditional statements  while while ( expression ) { … statements … }  for for ( initialization ; test ; update ) { … statements … }

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


Download ppt "Introduction to Computer Systems and the Java Programming Language."

Similar presentations


Ads by Google