John Woodward A Simple Program – Hello world

Slides:



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

IT151: Introduction to Programming
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.
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.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
CHAPTER 1 INTRODUCTION GOALS  To understand the activity of programming  To learn about the architecture of computers  To learn about machine code and.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
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,
01 Introduction1June Introduction CE : Fundamental Programming Techniques.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
1 Building Java Programs Chapter 1: Introduction to Java Programming These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may.
IB Computer Science II Paul Bui
Week 1 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
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.
Introduction to Computers and Java Chapter 1.3. A Sip of Java: Outline History of the Java Language Applets A First Java Program Compiling a Java Program.
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.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter 1 – Introduction.
ICOM 4015: Advanced Programming Lecture 1 Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Reading: Chapter One: Introduction.
Board Activity Find your seat on the seating chart Login – Remember your login is your first initial your last name and the last three numbers of your.
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.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
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.
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To learn about the architecture of computers To learn about machine code.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Introduction to programming in java
Computer Programming Your First Java Program: HelloWorld.java.
Slides by Evan Gallagher
Chapter 1 – Introduction
Dept of Computer Science University of Maryland College Park
Introduction To recognize compile-time and run-time errors
GC101 Introduction to computer and program
Chapter 3 GC 101 Java Fundamentals.
Chapter Goals To learn about computers and programming
Chapter 2 First Java Programs
Chapter 1 – Introduction
Java programming lecture one
Intro to Java.
Slides by Donald W. Smith
and Executing Programs
Chapter Three - Implementing Classes
Writing Methods.
Java Intro.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
IB Computer Science II Paul Bui
Use a variable to store a value that you want to use at a later time
Chapter 5 – Decisions Big Java by Cay Horstmann
Each object belongs to a class
1.7 Errors Compile-time error: A violation of the programming language rules that is detected by the compiler Example: System.ou.println("Hello, World!);
Computer Programming-1 CSC 111
6.2 for Loops Example: for ( int i = 1; i
Parameter: an input to a method
How to Run a Java Program
Presentation transcript:

John Woodward A Simple Program – Hello world Lecture 1 John Woodward A Simple Program – Hello world

ch01/hello/HelloPrinter.java – what errors can we get 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! Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.

The Structure of a Simple Program: Statements 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 Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.

The Structure of a Simple Program: Method Call System.out.println("Hello, World!"); is a method call A method call requires: The object that you want to use (in this case, System.out) The name of the method you want to use (in this case, println) Parameters enclosed in parentheses (()) containing any other information the method needs (in this case, "Hello, World!") Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.

Syntax 1.1 Method Call Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.

Errors 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 Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.

Program Development Process   Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.

What does the following set of statements print? Self Check 1.12 What does the following set of statements print? System.out.print("My lucky number is"); System.out.println(3 + 4 + 5); Answer: The printout is My lucky number is12 It would be a good idea to add a space after the is. Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.

Can you use a word processor for writing Java programs? Self Check 1.13 Can you use a word processor for writing Java programs? Answer: Yes, but you must remember to save your file as “plain text”. Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.

Self Check 1.14 What do you expect to see when you load a class file into your text editor? Answer: A sequence of random characters, some funny looking. Class files contain virtual machine instructions that are encoded as binary numbers. Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.

Self Check 1.16 When you used your computer, you may have experienced a program that “crashed” (quit spontaneously) or “hung” (failed to respond to your input). Is that behavior a compile-time error or a run-time error? Answer: It is a run-time error. After all, the program had been compiled in order for you to run it. Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.

Self Check 1.17 Why can't you test a program for run-time errors when it has compiler errors? Answer: When a program has compiler errors, no class file is produced, and there is nothing to run. Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.