270 likes | 373 Views
Hardware, Software and Java in Nutshell. Computer systems consist of hardware as well as software . Hardware includes the tangible parts of computer systems . Software includes programs (sets of instructions) for the computer to follow.
E N D
Computer systems consist of hardwareas well as software. Hardware includes the tangible parts of computer systems. Software includes programs(sets of instructions) for the computer to follow. Familiarity with hardware basics helps us to understand software. Hardware and Software
Most modern computers have similar components including Input devices (keyboard, mouse, etc.) Output devices (display screen, printer, etc.) Processor (computer’s brain) Two kinds of memory (main and auxiliary memories). Hardware
Also called CPU (central processing unit) or the chip (e.g., Pentium processor) The CPU processes a program’s instructions. The power of computing comes from speed and program complexity. Memory holds programs, data to be processed, and the results of intermediate processing. Processor and Memory
Main: it’s the working memory The current program The data that the program is using The results of intermediate calculations Usually measured in gigabytes; 8 GB of RAM Auxiliary: it’s more or less permanent Disk drives, CDs, DVDs, flash drives, etc. Usually measured in gigabytes; 100 GB of Hard Disk Main Memory and Auxiliary Memory
Bit is a digit with a value of either 0 / 1. Byte is a quantity of memory consisting of 8 bits. gigabytes = 109 b Each byte in main memory resides at a numbered location called its address. Main Memory
Data of all kinds (numbers, letters, strings, audio, video) are encoded and stored using 1s and 0s. When more than a single byte is required, several adjacent bytes are used and the address of the first byte is the address of the unit of bytes. Large groups of bytes in auxiliary memory are called files. Java programs are stored in files. Files are organized into directories or folders. Storing Data and Files
A computer program is a set of instructions for a computer to follow. We use programs almost daily, e.g., email, word processors, video games, bank ATMs, etc. Following the instructions is called running or executing the program. Program files are copied from auxiliary memory into main memory in order to be run/executed. Programs
A computer receives two kinds of input: The program The data needed by the program. The output is the result produced by following the instructions in the program. Input and Output
The operating system is a supervisory program that oversees the operation of the computer. It’s an interface between human and machine, e.g., Microsoft Windows, Apple’s Mac OS, Linux, etc. The OS retrieves and starts program for you. OS and hardware do not understand high-level languages such as Java, C++, Python, etc. So, a program in a high-level language must be translated into a low-level language (machine lang.) Operating System and Programs
A compiler translates a program from a high-level language to a low-level language (machine or assembly language) that the computer can run. You compile a program by running the compiler on the high-level-language version of the program called the source code, e.g., Java code. Most high-level languages need a differentcompiler for each type of computer and for each operating system. Compilers
The Java compiler does not translate a Java program into assembly language or machine language for a particular computer. It translates a Java program into byte-code which is the machine language for a hypothetical computer or interpreter, called Java Virtual Machine (JVM). A byte-code program is interpreted into machine language very fast on any platform, that is, independent of the hardware and operating system. Java Byte-Code
Use the compiler to compilethe Java program into byte-code (done using the javaccommand). Use the Java Virtual Machine for your computer To interpret each byte-code instruction into machine-language and To runthe resulting machine-language instructions (done using thejavacommand). Compiling, Interpreting, Running
Compiling, Interpreting, Running fileName.java fileName.class
After compiling a Java program into byte-code: Byte-code can be used on any computer with the interpreter and without a need to recompile. Byte-code can be sent over the Internet and used anywhere in the world. This makes Java independent of the hardware/OS and suitable for Internet applications. Benefit of Java: Portability
An instruction to the computer is called a statement. Grammar rule of a programming language is called syntax. Java programs consist of many pieces called classes. Each class consists of attributes (state) and methods(behavior). Attributes show the state of a class, a.k.a, variables or data. Methods (args) define the behavior of a class, a.k.a, procedures or functions. The arguments are the required data for the method. In a program, class loader or linkerconnects all classes together. Packageis a library of classes that have been predefined. Some Terminology
System.out is an object for sending output to the screen to be printed. println is a method to print whatever is in parentheses to the screen. The object performs an action when you invoke or call one of its methods. Simple Statement: Printing to the Screen System.out.println(“Whatever you want to print”); objectName.methodName(argumentsTheMethodNeeds);
We have two kinds of java programs: Applications Regular programs Meant to be run on your computer Applets Little applications Meant to be sent to another location on the internet Applications and Applets
Importing the required predefined classes Beginning of your program Every “application” has a “main” method Instantiate an object,(named “keyboard”) from the class “Scanner” The “keyboard” object is also connected to the “System.in” object Call the method “nextInt()” through the object “keyboard” Note that “nextInt()” method belongs to the class “Scanner”
Importing “Japplet” and “Graphics” classes from “swing” and “awt” packages Beginning of your program Extra commands to define an “applet” You do not need a “main” method for an “applet” Instead, each applet needs one or more of init(), start() or paint() method. It may also have stop() and destroy() methods Instantiate an object,(named “canvas”) from the class “Graphics” Call methods “drawOval()”,“fillOval() and“drawArc()” through the object “canvas” Note that these methods belong to the class “Graphics” drawOval(x, y, width, height) fillOval(x, y, width, height) draArc(x, y,width, height, starting degree, degree) <HTML> <BODY> <APPLET CODE=HappyFace.class WIDTH=500 HEIGHT=500> </APPLET> </BODY> </HTML>
The x-coordinate is the number of pixels from the left. The y-coordinate is the number of pixels from the top (not from the bottom). In a Java applet, size and position of figures are given in pixels. The display surface is like a two-dimensional grid of individual pixels. Screen Coordinate System
canvas.drawOval(100, 50, 90, 50) Drawing Ovals and Circles
There are two ways to run an applet: Embed the applet in a Web page and run it, as shown in slide 20. Use an applet viewerin the Integrated Development Environment. There are two ways to end an applet: If you are running the applet from a web site, close the page or navigate away from the page. If you are using an applet viewer in the IDE, use the mouse to click the close-window button. Running and Closing an Applet