Chapter 1 CSIS-120: Java Intro. What is Programming?  A: It is what makes computer so useful.  The flexibility of a computer is amazing  Write a term.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. OBJECTIVES FOR THIS UNIT Upon completion of this unit, you should be able to: Explain the Java virtual machine.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. GCOC – A.P. Computer Science A College Board Computer Science A Topics Covered Program Design - Read and understand.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Your First Java Program: HelloWorld.java
Chapter 1: Introduction
Chapter 1 These slides for CSE 110 Sections are based in part on the textbook-authors’ slides, which are copyright by the authors. The authors state that.
CHAPTER 1 INTRODUCTION GOALS  To understand the activity of programming  To learn about the architecture of computers  To learn about machine code and.
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Getting Started with Java
Chapter 1 - Introduction. Ch 1Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
1 Building Java Programs Chapter 1: Introduction to Java Programming These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may.
Chapter 2 First Java Programs
Week 1 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
 Java Programming Environment  Creating Simple Java Application  Lexical Issues  Java Class Library.
Copyright © 2013 by John Wiley & Sons. All rights reserved. INTRODUCTION CHAPTER Slides by Donald W. Smith TechNeTrain.com Final Draft Oct. 15,
1 Chapter 2 First Java Programs Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter One: Introduction.
Week 1 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Chapter 1 Introduction. Goal to learn about computers and programming to compile and run your first Java program to recognize compile-time and run-time.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter 1 – Introduction.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Chapter 1: Introduction to Programs, and Java 1. Objectives To review programs (§ ). To understand the relationship between Java and the World Wide.
ICOM 4015: Advanced Programming Lecture 1 Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Reading: Chapter One: Introduction.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter One: Introduction.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter 1 – Introduction ( ปรับปรุง )
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 1 - Introduction.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture.
Fall 2006Slides adapted from Java Concepts companion slides1 Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition D.S. Malik D.S. Malik.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
Chapter 1 Introduction. Chapter Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Creating a Java Application and Applet
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To learn about the architecture of computers To learn about machine code.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Overview of Programming.
Chapter 1 - Introduction. Announcements Info Sheet Web Site: Lab Hours NotecardsPictures.
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
ITP 109 Week 2 Trina Gregory Introduction to Java.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Chapter 2 First Java Programs Fundamentals of Java.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Computer Programming Your First Java Program: HelloWorld.java.
Chapter 1 – Introduction
Department of Computer Science,
Introduction To recognize compile-time and run-time errors
John Woodward A Simple Program – Hello world
Chapter Goals To learn about computers and programming
Chapter 1 – Introduction
Java programming lecture one
Goals To learn about computers and programming
Slides by Donald W. Smith
String Output ICS 111: Introduction to Computer Science I
Java Intro.
Computer Programming-1 CSC 111
Presentation transcript:

Chapter 1 CSIS-120: Java Intro

What is Programming?  A: It is what makes computer so useful.  The flexibility of a computer is amazing  Write a term paper (Word processing program)  Balance checkbook (Accounting program)  Play a game (Games are programs)  Post on Facebook (Facebook is program)  Programming  Computer Programs

What is a Computer Scientist?  Somebody who can write programs to solve lots of different problems.  You don’t need to program to use programs  But, often times you need to program to solve an array of different problems.

Computer Hardware  Hasn’t changed as much as you would think.  See Diagram on page 6  Programming has improved just as much as the hardware.

Evolution of programming  Early 60’s  Specify instructions in binary   Late 60’s to 70’s  Machine language  Instruction codes and value in hexidecimal  2F 4A0  56 C13

Evolution of programming  70’s to Today  Assembly language (more general, more human readable – get translated into machine language)  SET r1, 10 ; r1 will take the place of i SET r2, 1 ; r2 will hold the value to subtract each time LOOP1TOP : SUB r1, r1, r2 ; subtract one from r1 CMP r1, r0 JMP NEQ, LOOP1TOP ;  Late 70’s to Today  High level language  Designed for humans to “easily” read/write  C++, Java, etc.

Evolution of programming  90’s to Today  Graphical languages  makes it even “easier” to program  Alice, Labview, etc.  But in the end it all get compiled to binary  High Level Language  Assembly Code  Machine Instructions  Binary

Compilation  High-level languages are compiled into machine language.  A compiler itself is a program that simply translates from high-level lanaguage to low-level.  Most compilers create machine language for a specific type of operating system/computer (called a platform)  PC Platform  Mac Platform  Unix Platform

Compilation & Java  A Java compiler creates “machine language” (Java Byte Code) that can be run on any type of computer.  The computer just needs a Java Virtual Machine (JVM)  The JVM is just a program that can execute Java Byte code for a specific computer.  In theory, your compiled program can run on any computer.

Traditional Compilation (C++)  The compiler eventually creates machine language for a specific operating system/computer platform (Windows, Mac, Linux, etc.)  If you wish to run you program on a PC and a Mac, you need two compilers and need to compile two different running programs.  In contrast, a Java program just needs to be compiled once.  But, the PC and Mac will both need installed JVMs (Java Virtual Machines)

Java is still very popular  Platform independence: Compiled programs can run on any device with a JVM installed.  Java Enterprise Edition EE  Java works well with the Internet & WWW  Rather than run programs on your computer, Java allows you to easily create programs that can run on a web server.  Java Server Pages (JSP) can “call” Java programs.  Thus, complex programs can be run from web-enabled devices (iPhone, Droid Phone, etc.) without actually “executing” the program locally  programs execute on the server.

Let’s start with a most basic program  Traditionally, the ‘hello world’ program is the first one taught in most classes/texts.

1 public class HelloPrinter 2 { 3 public static void main(String[] args) 4 { 5 // Display a greeting in the console window 6 7 System.out.println("Hello, World!"); 8 } 9 } Program Run: Hello, World! HelloPrinter.java

Classes are the fundamental building blocks of Java programs: public class HelloPrinter starts a new class A class defines a “reusable” programming object. In a computer game, the classes might include things like public class Zombie public class RocketLauncher The Structure of a Simple Program: Class Declaration

Each class goes in a.java file Every source file can contain at most one public class The name of the public class must match the name of the file containing the class: Class HelloPrinter must be contained in a file named HelloPrinter.java

Every Java application contains a class with a main method When the application starts, the instructions in the main method are executed public static void main(String[] args) {... } declares a main method The Structure of a Simple Program: main Method

The first line inside the main method is a comment: // Display a greeting in the console window Compiler ignores any text enclosed between // and end of the line Use comments to help human readers understand your program The Structure of a Simple Program: Comments

The body of the main method contains statements inside the curly brackets ( {} ) Each statement ends in a semicolon ( ; ) Statements are executed one by one Our method has a single statement: System.out.println("Hello, World!"); which prints a line of text: Hello, World The Structure of a Simple Program: Statements

System.out.println("Hello, World!"); is a method call A method call requires: 1.The object that you want to use (in this case, System.out ) 2.The name of the method you want to use (in this case, println ) 3.Parameters enclosed in parentheses ( () ) containing any other information the method needs (in this case, "Hello, World!" ) The Structure of a Simple Program: Method Call

Syntax 1.1 Method Call

String: a sequence of characters enclosed in double quotation marks: "Hello, World!" The Structure of a Simple Program: Strings

How would you modify the HelloPrinter program to print the words "Hello," and "World!" on two lines? Answer: System.out.println("Hello,"); System.out.println("World!"); Self Check 1.10

What does the following set of statements print? System.out.print("My lucky number is"); System.out.println( ); Self Check 1.12

Use an editor to enter and modify the program text Java is case-sensitive Be careful to distinguish between upper- and lowercase letters Lay out your programs so that they are easy to read Editing a Java Program

The Java compiler translates source code into class files that contain instructions for the Java virtual machine A class file has extension.class The compiler does not produce a class file if it has found errors in your program The Java virtual machine loads instructions from the program's class file, starts the program, and loads the necessary library files as they are required Compiling and Running a Java Program

HelloPrinter in a Console Window

HelloPrinter in an IDE

From Source Code to Running Program

What do you expect to see when you load a class file into your text editor? Self Check 1.14

Compile-time error: A violation of the programming language rules that is detected by the compiler Example : System.ou.println("Hello, World!); Syntax error Run-time error: Causes the program to take an action that the programmer did not intend Examples: System.out.println("Hello, Word!"); System.out.println(1/0); Logic error Errors

Algorithm: A sequence of steps that is: unambiguous executable terminating Algorithm for deciding which car to buy, based on total costs: For each car, compute the total cost as follows: annual fuel consumed = annual miles driven / fuel efficiency annual fuel cost = price per gallon x annual fuel consumed operating cost = 10 x annual fuel cost total cost = purchase price + operating cost If total cost1 < total cost2 Choose car1 Else Choose car2 Algorithms

Pseudocode: An informal description of an algorithm: Describe how a value is set or changed: total cost = purchase price + operating cost Describe decisions and repetitions: For each car operating cost = 10 x annual fuel cost total cost = purchase price + operating cost Use indentation to indicate which statements should be selected or repeated Indicate results: Choose car1 Pseudocode

Program Development Process