DOC PREVIEW
OSU CSE 1223 - 01ComputerBasics

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSE 1223 Introduction to Computer Programming in Java Chapter 1 Computer Basics 1 Computer Basics Computer system hardware software Hardware the physical components Software the instructions that tell the hardware what to do 2 Common Hardware Components Processor CPU Memory main auxiliary mouse keyboard etc Output device s main auxiliary holds data and instructions Input device s Standard Hardware Organization Memory Central Processing Unit Interprets and executes the instructions video display printer etc CPU and memory are physically housed together Input Devices such as mouse and keyboard Processor CPU Output Devices such as video display or printer 3 Running a Program Program a set of instructions for a computer to follow Program Data input for the program Computer Output 4 Programming Languages Needed to write software High level languages e g Java relatively easy for people to write and understand not directly understood by computers Low level languages machine language directly understood by computer computer dependent 5 The Compiler A program written in a high level language know as the source code cannot be executed directly by the computer A compiler is a program that translates source code into machine code that does the same thing known as the object code 6 Java Program Translation and Execution Input to Java Program Java Source Code Java Compiler Java Byte Code Java Virtual Machine Output of Java Program 7 Java Translation Execution cont Java byte code is portable hardwareindependent The Java Virtual Machine JVM executes Java byte code on a real machine The java compiler is called javac The JVM emulator is called java 8 Algorithmic Thinking Algorithm a set of instructions steps for solving a problem must be precise must be complete can be written in an arbitrary notation e g natural language programming language diagram mix etc Algorithmic thinking is fundamental to computer science and programming 9 Example of an Algorithm Algorithm that determines the total cost of a list of items 1 Write the number 0 on the blackboard 2 Do the following for each item on the list a Add the cost of the item to the number on the blackboard b Replace the old number on the board by this sum 3 Announce that the answer is the number written on the board 10 First Java Program public class FirstProgram public static void main String args System out println Hello out there System out println How s it going System out println Hope you are having a good day System out println Good bye 11 Language Syntax Syntax of a language is a set of grammar rules that describe the correct way to write sentences programs in the language Programming languages have a very precise syntax If you break the rules you ll get one or more errors 12 Structure of a Java Program import needed libraries public class ProgramName public static void main String args statements go here to describe actions to be taken by the program 13 A Java Statement System out println some message here Outputs the message in quotes to the screen without the quotes 14 What Does FirstProgram Do Take a look at the program and see if you can figure out what the program does It outputs the following Hello out there How s it going Hope you are having a good day Good bye 15 Programming Errors Syntax errors violation of language s syntax rules e g misspelling a word forgetting a etc Caught by the compiler Runtime errors execution errors e g division by zero Logical errors the program compiles and runs without runtime errors but it does not do what it is supposed to 16 Second Java Program import java util Scanner public class EggBasket public static void main String args int numberOfBaskets eggsPerBasket totalEggs Scanner keyboard new Scanner System in System out print Enter the number of eggs in each basket eggsPerBasket keyboard nextInt System out print Enter the number of baskets numberOfBaskets keyboard nextInt totalEggs numberOfBaskets eggsPerBasket System out println eggsPerBasket eggs per basket System out println numberOfBaskets baskets System out println Total number of eggs is totalEggs 17 What Does EggBasket Do Take a look at the program and see if you can figure out what it does 18


View Full Document

OSU CSE 1223 - 01ComputerBasics

Documents in this Course
Load more
Download 01ComputerBasics
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view 01ComputerBasics and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view 01ComputerBasics and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?