🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Week 1 Introduction to Programming.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

Software Development Introduction to programming in Java 1 Contact Details • Email: [email protected] 2 Reading Material • Java in Two Semesters - Quentin Charatan & Aaron Kans – Publisher: McGraw Hill • Java The First Semester (older edition) 3 Reading Material • Big Java Early Objects...

Software Development Introduction to programming in Java 1 Contact Details • Email: [email protected] 2 Reading Material • Java in Two Semesters - Quentin Charatan & Aaron Kans – Publisher: McGraw Hill • Java The First Semester (older edition) 3 Reading Material • Big Java Early Objects 5th Ed – Publisher: Horstmann 4 Module • 100% CA • This will consist of 2 assignments and • 2 Blackboard quizzes to test your knowledge • See module handout for details on CA 5 Key Principles • Learning to program is difficult and it is unlikely that it will come naturally to you. There is no substitute for hard work. • Do your best to complete all practical exercises. • Plan every program on paper. Break a large problem down into smaller, manageable problems. 6 What is programming? • Computer can perform a number of very different tasks – Type documents, send emails, play a game, browse the web • A computer must be programmed to perform tasks • Different tasks require different programs • A computer program executes a sequence of very basic operations in rapid succession • A computer has no intelligence – it simply 7 executes instruction sequences that have A computer is composed of :1. Hardware - The actual computer - the machine itself, the tangible part 2. Software - is run on the machine. This includes all computer packages that you will use, Windows 7/XP,8,10,11, Microsoft Office, etc. 8 Software – a set of instructions given to a computer is called a program; – software is the name given to a single program or a set of programs. 9 Computers and Software • A computer is simply a piece of hardware -on its own it can do nothing. • It is the software that is run on the computer that makes the computer such a powerful machine. • Once you turn on a computer, software is run and it is this software that the user uses to carry out the required tasks 10 Examples of Software Some examples of Software:• Windows 10/11 • Microsoft Word • A payroll system • A flight booking system • A patient system in a hospital - used for keeping track of patients. • Computer game – MineCraft, Roblox 11 Computer Program • A computer program is a set of instructions that tell a computer exactly what to do. Just as: – A recipe is a set of instructions for a cook – musical notes are a set of instructions for a musician. • The computer follows your instructions exactly and in the process does something useful like balancing a cash book or displaying a game on the screen or implementing a word processor. 12 Computer Programs • Learning to program is learning how to explain to the computer what you want it to do. • The computer carries out tasks by executing instructions. • These instructions are written as a series of steps in a Computer Program. • Over this block we will be learning how to write these programs. 13 Program and Programmer • Program - a sequence of instructions given to a computer. • Programmer - the person who writes the sequence of instructions. 14 Programming Language • Essentially, a program is a communication - a set of instructions. Its purpose is to communicate a description of a process from the programmer, who has written it, to the processor, which has to execute it. • In everyday life, successful communication is achieved by using a language that is understood by both parties. 15 Programming Languages • Communication between a programmer and a computer is achieved by means of a language - a programming language. 16 Programming Language • A programming language is an englishlike language that is used to write computer programs. • You have to learn a computer language in order to write a computer program. 17 Programming Languages • A program is written by a developer in a special computer language. For example • • • • • • C++ Java C# Python Ruby It is then translated by a special program (a compiler) into: • machine code or • Java byte code 18 History of programming languages • Assembly language (low-level language) • High-level languages (third generation languages or 3GLs) Examples – – – – C COBOL BASIC Pascal • Object-oriented programming languages Examples – C++ – Java – C# 19 Types of Computer Languages • Programmers write instructions in various programming languages. • Some of these are directly understandable by computers. • Others require intermediate translation steps. 20 Types of Computer Languages • Computer languages may be divided into three general types: – Machine languages – Assembly languages – High level languages 21 Machine Languages • Any computer can understand only its own machine language. • Defined by the hardware design of that computer. • Strings of numbers that instruct the computers to perform simple operations one at a time. 22 Machine Languages • Machine dependent. • Very cumbersome for humans. • For example, a program to add two numbers might look like the following: +1300042774 +1400523861 +7220014829 23 Assembly Languages • Assembly languages use English-like abbreviations to represent operations. • Translator programs called assemblers then convert assembly language programs to machine language. • The code is clearer to humans but must be translated to machine language for the 24 computer. Assembly Languages • For example the following program might be used to calculate wages: LOAD ADD STORE BASEPAY OVERPAY GROSS PAY • These languages still require many instructions to accomplish even the simplest tasks. 25 High Level Languages • In high level languages, single statements can accomplish substantial tasks. • Programs are converted into machine language by a compiler. • Programmers can write instructions that look like everyday English and contain mathematical notations. • A payroll program might contain an instruction like this: 26 grossPay = basePay + How programs are created • Programmers write instructions in a high level language. • The programmer must obey the rules of the language. • The instructions are saved as source code in a text file. • A compiler is used to translate the source code into a form that the computer can understand. 27 How programs are created • The compiler will flag any errors which prevent the program from being compiled. • The programmer will debug the program to remove any errors, and the program will be re-compiled. • Conventional compilers will create an executable program containing the machine language to be executed by the computer. • This executable file will work on one type 28 of computer only. How programs are created Source Code Compiler Executable Program Running Program 29 Java • Java is a high level programming language developed by Sun Microsystems. • Programs written in Java are platform independent. • A platform independent program is one that can be run in exactly the same way, regardless of whether the computer is a PC, a MAC, a mobile phone etc. 30 How Java works • Programmers write instructions in a high level language. • The programmer must obey the rules of the language. • The instructions are saved as source code in a text file. • Instead of producing an executable file, the compiler will produce java bytecode. 31 How Java works • Java bytecode is an intermediate format which will be interpreted by a program on the computer which runs the program. • Java bytecode is not specific to any computer platform • The program which interprets the java bytecode is known as the Java Virtual Machine (JVM). • Thus, Java programs are platform 32 independent. How Java programs are created Source Code Compiler Running Program Java Bytecode Java Virtual Machine 33 Compiling & Running programs Hello.java //Hello file public class Hello…. Hello.class Java compiler { If no : errors __________ ____________ } Reads source code & checks for syntax errors Java bytecode Java Source Code 34 Compiling & Running programs • If there are no errors in the source code, the Java compiler writes a Java byte code file that is named with a .class extension • Once the byte code file is produced we are ready to run our Java program • The byte code is read by the Java Virtual Machine (JVM) • The JVM is a separate program that reads the byte code found in the class file and translates commands into “native” instructions for the computer’s processors 35 What is needed to write Java • The Java Software Development Kit (JDK) must be installed on your computer • The JDK includes the java compiler (javac), and the Java Runtime Environment (JRE) • You will need a common text editor such as notepad to write your programs 36 The IDE • An Integrated Development Environment (IDE) is a program that allows the programmer to: – Write code – Compile code – Make changes in response to error messages • It is not essential to have an IDE, but it makes the process a little more programmer friendly. • We will use jGrasp as IDE 37 Java IDE 38 Summary • Computers are excellent tools, but they must be given clear instructions. • Programmers use high level languages to write instructions for computers to follow. • A compiler is used to translate programs into a language which computers understand. • Java is a high level language which allows us to produce platform independent programs. 39

Use Quizgecko on...
Browser
Browser