Chapter 1 Introduction to Computers, Programs, and Java

Slides:



Advertisements
Similar presentations
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Advertisements

Chapter 2 Elementary Programming
IT151: Introduction to Programming
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects.
Chapter 1: Introduction
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Chapter 2 Primitive.
LESSON 3 - Identifiers JAVA PROGRAMMING. Identifiers All the Java components —classes, variables, and methods— need names. In Java these names are called.
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example F Identifiers, Variables, and Constants F Primitive Data Types –byte,
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
Excerpts from Introduction to Java Programming, 4E Author: Y. Daniel Liang (Copyright by Prentice Hall)
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Java Overview CS2336: Computer Science II1. First Program public class HelloWorld { public static void main(String args[]) { System.out.println("Hello.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Chapter 1 Introduction to Computers, Programs, and Java
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Chapter 2 Elementary Programming 1. Introducing Programming with an Example Listing 2.1 Computing the Area of a Circle This program computes the area.
Primitive Data Types and Operations Identifiers, Variables, and Constants Primitive Data Types Byte, short, int, long, float, double, char, boolean Casting.
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
Programming Style and Documentation Objective(s) F To become familiar with Java Style and Documentation Guidelines.
1 Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
Comments are for people Header comments supply basic information about the artifact.
VARIABLES Introduction to Computer Science 1- COMP 1005, 1405 Instructor : Behnam Hajian
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
The Java Programming Language
Chapter 1 Introduction to Computers, Programs, and Java 1.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Introduction to programming in the Java programming language.
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
Documentation and Style. Documentation and Comments  Programs should be self-documenting.  Use meaningful variable names.  Use indentation and white.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Java FilesOops - Mistake Java lingoSyntax
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects 1. How is a class different from an object?
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.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use simple Output statements Understand the different types and uses of comments.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Elementary Programming.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction.
Primitive Data Types and Operations F Introduce Programming with an Example F Identifiers, Variables, and Constants F Primitive Data Types –byte, short,
The Essentials of a Java Program JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,
1.  Algorithm: 1. Read in the radius 2. Compute the area using the following formula: area = radius x radius x PI 3. Display the area 2.
Chapter 1 Introduction to Computers, Programs, and Java
Computer Programming Your First Java Program: HelloWorld.java.
Chapter 1 Introduction to Computers, Programs, and Java
GC101 Introduction to computer and program
Lecture 3: Operators, Expressions and Type Conversion
Introduction to Programming
Chapter 1 Introduction to Computers, Programs, and Java
Statements, Comments & Simple Arithmetic
Chapter 1 Introduction to Computers, Programs, and Java
Programming Vocabulary.
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 3 Classes and Objects
Chapter 1: Computer Systems
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 1 Introduction to Computers, Programs, and Java
elementary programming
Documentation and Style
Anatomy of a Java Program
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 2 Primitive Data Types and Operations
Introduction to Computers, Programs, and Java
Presentation transcript:

Chapter 1 Introduction to Computers, Programs, and Java

Anatomy of a Java Program Class name Main method Statements Statement terminator Reserved words Comments Blocks

Class Name Every Java program must have at least one class. Each class has a name. By convention, class names start with an uppercase letter. In this example, the class name is Welcome. // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

Main Method Line 2 defines the main method. In order to run a class, the class must contain a method named main. The program is executed from the main method. // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

Statement A statement represents an action or a sequence of actions. The statement System.out.println("Welcome to Java!") in the program in Listing 1.1 is a statement to display the greeting "Welcome to Java!“. // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

Statement Terminator Every statement in Java ends with a semicolon (;). // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

Reserved words Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. For example, when the compiler sees the word class, it understands that the word after class is the name for the class. // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

Blocks A pair of braces in a program forms a block that groups components of a program.

Special Symbols

{ … } // This program prints Welcome to Java! public class Welcome { { … } // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

( … ) // This program prints Welcome to Java! public class Welcome { ( … ) // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

; // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

// … // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

" … " // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

Programming Style and Documentation Appropriate Comments Naming Conventions Proper Indentation and Spacing Lines Block Styles

Appropriate Comments Include a summary at the beginning of the program to explain what the program does, its key features, its supporting data structures, and any unique techniques it uses. Include your name, class section, instructor, date, and a brief description at the beginning of the program.

Naming Conventions Choose meaningful and descriptive names. Class names: Capitalize the first letter of each word in the name. For example, the class name ComputeExpression.

Proper Indentation and Spacing Indent two spaces. Spacing Use blank line to separate segments of the code.

Block Styles Use end-of-line style for braces.  

Programming Errors Syntax Errors Runtime Errors Logic Errors Detected by the compiler Runtime Errors Causes the program to abort Logic Errors Produces incorrect result

Syntax Errors public class ShowSyntaxErrors { public static main(String[] args) { System.out.println("Welcome to Java); } ShowSyntaxErrors Run

Syntax Errors public class ShowSyntaxErrors { public static main(String[] args) { System.out.println("Welcome to Java") } ShowSyntaxErrors Run

Syntax Errors public class ShowSyntaxErrors { public static main(String[] args) { system.out.println("Welcome to Java"); } " ShowSyntaxErrors Run

Runtime Errors public class ShowRuntimeErrors { public static void main(String[] args) { System.out.println(1 / 0); } ShowRuntimeErrors Run

Logic Errors Run ShowLogicErrors public class ShowLogicErrors { public static void main(String[] args) { System.out.println("Celsius 35 is Fahrenheit degree "); System.out.println((9 / 5) * 35 + 32); } ShowLogicErrors Run

Compute Perimeter Area // page 31 #1.8 public class Circle{ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("perimeter: "); System.out.println(2 * 5.5 * 3.14159); System.out.println("area: "); System.out.println( 5.5 * 5.5 * 3.14159); } ShowLogicErrors Run