Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.

Slides:



Advertisements
Similar presentations
Chapter 1: Computer Systems
Advertisements

Programming Languages
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
1 Kursusform  13 uger med: Undervisning i klassen 1,5-2 timer Opgave ”regning” i databar (løsninger på hjemmeside) En midtvejsopgave der afleveres og.
The Java Programming Language
Outline Java program structure Basic program elements
Chapter 1 Introduction. © 2004 Pearson Addison-Wesley. All rights reserved1-2 Outline Computer Processing Hardware Components Networks The Java Programming.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Chapter 1 Introduction.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Java: Chapter 1 Computer Systems Computer Programming II Aug
Chapter 1 Introduction.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
Chapter 1 Programming Languages. Application Development: Top 10 Programming Languages to Keep You Employed 1. Java 2. C# 3. C++ 4. JavaScript 5. Visual.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley John Lewis, Peter DePasquale, and Joseph Chase Chapter 1: Introduction.
© 2006 Pearson Education Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
Introduction. Objectives An overview of object-oriented concepts. Programming and programming languages An introduction to Java 1-2.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 2: Java Fundamentals
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
Chapter 1: Introduction Java Programming Language How the Java Virtual Machine Works (compiling, etc…) Update by: Dan Fleck Coming up: The Java Programming.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Lecture 2 Software Concepts Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
1 Problem Solving b The purpose of writing a program is to solve a problem b The general steps in problem solving are: Understand the problemUnderstand.
White Space Spaces, blank lines, and tabs are collectively called white space and are used to separate words and symbols in a program Extra white space.
ZObject-Oriented Software Development yproblem solving yprogram design and implementation yobject-oriented concepts xobjects xclasses xinterfaces xinheritance.
Intro to Programming  Chapter 1 Part 2  Problem Solving.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Chapter 1 Introduction. 2 Focus of the Course Object-Oriented Software Development problem solving program design, implementation, and testing object-oriented.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Working with Java.
Lecture 2: Data Types, Variables, Operators, and Expressions
Variables and Arithmetic Operators in JavaScript
University of Central Florida COP 3330 Object Oriented Programming
1.3 Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: Understand the problem Dissect the.
Starting JavaProgramming
null, true, and false are also reserved.
Introduction to Java Programming
An overview of Java, Data types and variables
Instructor: Alexander Stoytchev
Chapter 1: Computer Systems
Fundamentals of Programming
Units with – James tedder
Units with – James tedder
JavaScript Reserved Words
Instructor: Alexander Stoytchev
Java Software Solutions Foundations of Program Design 9th Edition
Focus of the Course Object-Oriented Software Development
Module 2 - Part 1 Variables, Assignment, and Data Types
Instructor: Alexander Stoytchev
Chap 2. Identifiers, Keywords, and Types
Agenda Types and identifiers Practice Assignment Keywords in Java
Presentation transcript:

Programming with Java

Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the problem –Dissect the problem into manageable pieces –Design a solution –Consider alternatives to the solution and refine it –Implement the solution –Test the solution and fix any problems that exist

The Java Programming Language A programming language specifies the words and symbols that we can use to write a program A programming language employs a set of rules that dictate how the words and symbols can be put together to form valid program statements Java was created by Sun Microsystems, Inc. It was introduced in 1995 and has become quite popular It is an object-oriented language

Java Program Structure In the Java programming language: –A program is made up of one or more classes –A class contains one or more methods –A method contains program statements These terms will be explored in detail throughout the course A Java application always contains a method called main

Java Program Structure public class MyProgram {}{} // comments about the class class header class body Comments can be added almost anywhere

Java Program Structure public class MyProgram {}{} public static void main (String[] args) {}{} // comments about the class // comments about the method method header method body

Comments Comments in a program are also called inline documentation They should be included to explain the purpose of the program and describe processing steps They do not affect how a program works Java comments can take two forms: // this comment runs to the end of the line /* this comment runs to the terminating symbol, even across line breaks */

Readable Code: Comments Comments can help make your program readable and understandable by others (including markers!) You will be required to comment your code extensively. –Before class headers –Before method headers –Before logical blocks of code –Explanations of any line of code that may not be completely obvious.

Commented Code /* MyLincoln.java Kirstie Hawkey B This program is the Canadian equivalent of the Lincoln program from the text. */ public class MyLincoln { /* Prints a Prime Ministerial quote Preconditions: none. Postconditions: A fake quote is printed to the screen. Parameters: none. */ public static void main (String[] args) { System.out.println (“A quote from Pierre Trudeau”); //fake quote System.out.println (“Whenever in the presence of royalty, pirouette”); }

Identifiers Identifiers are the words a programmer uses in a program An identifier can be made up of letters, digits (0-9), the underscore character _, and the dollar sign $ They cannot begin with a digit (0-9) Java is case sensitive, therefore Total and total are different identifiers

Identifiers Sometimes we choose identifiers ourselves when writing a program (such as My Lincoln ) Sometimes we are using another programmer's code, so we use the identifiers that they chose (such as println ) Often we use special identifiers called reserved words that already have a predefined meaning in the language A reserved word cannot be used in any other way

Reserved Words The Java reserved words: abstract boolean break byte byvalue case cast catch char class const continue default do double else extends false final finally float for future generic goto if implements import inner instanceof int interface long native new null operator outer package private protected public rest return short static super switch synchronized this throw throws transient true try var void volatile while

Identifiers and reserved words /* MyLincoln.java Kirstie Hawkey B This program is the Canadian equivalent of the Lincoln program from the text. */ public class MyLincoln { /* Prints a Prime Ministerial quote Preconditions: none. Postconditions: A fake quote is printed to the screen. Parameters: none. */ public static void main (String[] args) { System.out.println (“A quote from Pierre Trudeau”); System.out.println (“Whenever in the presence of royalty, pirouette”); }

Readable Code: Identifiers Choose identifiers that help a reader of your program understand what is happening. Choose a class name that gives a good idea of the purpose of the class. The need for well-named variables and methods will become more apparent as we see more involved code.

Valid? Good? Sum 3rdCounter i Third_counter Counter3 $total dollars&cents theMaximumNumberFoundSoFar

What does this program do? public class Mystery { public static void main (String[] args) { int z = 1; int fox = 0; int water = 100; do { fox = fox + z; z = z + 1; } while (z <= water); System.out.println("Fox = " + fox + ", z = " + z + " water = " + water); }

What does this program do? public class Sum1to100 { public static void main (String[] args) { int number = 1; int sum = 0; int max = 100; do { sum = sum + number; number = number + 1; } while (number <= max); System.out.println(“sum = " + sum + ", number = " + number + " max = " + max); }

White Space Spaces, blank lines, and tabs are collectively called white space White space is used to separate words and symbols in a program Extra white space is ignored A valid Java program can be formatted many different ways Programs should be formatted to enhance readability, using consistent indentation

White space /* MyLincolnWS.java Kirstie Hawkey B This program is the Canadian equivalent of the Lincoln program from the text.*/ public class MyLincolnWS{ /* Prints a Prime Ministerial quote Preconditions: none Postconditions: A fake quote is printed to the screen Parameters: none.*/ public static void main (String[] args){ System.out.println (“A quote from Pierre Trudeau”); System.out.println (“Whenever in the presence of royalty, pirouette”); }}