Fundamentals of Software Development 1Slide 1 Review: Why start with WordGames? You wrote your first lines of code in this course in WordGames.You wrote.

Slides:



Advertisements
Similar presentations
Lecture 9: More on objects, classes, strings discuss hw3 assign hw4 default values for variables scope of variables and shadowing null reference and NullPointerException.
Advertisements

Fundamentals of Software Development 1Slide 1 Today’s Summary Hello World concepts – –main, static, console Programming patterns involving assignment and.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
03 Data types1June Data types CE : Fundamental Programming Techniques.
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
Datalogi A 1: 8/9. Book: Cay Horstmann: Big Java or Java Consepts.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Computer Science A 1: 3/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Writing methods. Calling Methods nameOfMethod(parameters) if method returns something, use that value Math.pow(2, 3) returns 8 System.out.println(Math.pow(2,
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
Java CourseWinter 2009/10. Introduction Object oriented, imperative programming language. Developed: Inspired by C++ programming language.
Writing algorithms using the while-statement. Previously discussed Syntax of while-statement:
Hello AP Computer Science!. What are some of the things that you have used computers for?
Fundamentals of Software Development 1Slide 1 Why start with WordGames? You wrote your first lines of code in this course in WordGames.You wrote your first.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Fundamentals of Software Development 1Slide 1 Recap: “From scratch” projects Today’s software engineering is almost NEVER “from scratch”Today’s software.
CSC172 Intro Pepper. Goals Reminder of what a class is How to create and use classes How to design classes How to think in terms of objects How to comment.
Classes and Objects. Topics The Class Definition Declaring Instance Member Variables Writing Instance Member Methods Creating Objects Sending Messages.
Java Classes Using Java Classes Introduction to UML.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Lecture # 5 Methods and Classes. What is a Method 2 A method is a set of code which is referred to by name and can be called (invoked) at any point in.
Copyright © Curt Hill Java Looking at our first console application in Eclipse.
Console Input & Output CSS 161: Fundamentals of Computing Joe McCarthy 1.
CS61B L02 Using Objects (1)Garcia / Yelick Fall 2003 © UCB Kathy Yelick Handout for today: These lecture notes Computer Science 61B Lecture 2 – Using Objects.
The scope of local variables. Murphy's Law The famous Murphy's Law says: Anything that can possibly go wrong, does. (Wikipedia page on Murphy's Law:
EXAM 1 REVIEW. days until the AP Computer Science test.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-4: Static Methods and Fields.
Input/Output in Java. Output To output to the command line, we use either System.out.print () or System.out.println() or System.out.printf() Examples.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 6: Object-Oriented Programming.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Hello Computer Science!. Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening.
Using the while-statement to process data files. General procedure to access a data file General procedure in computer programming to read data from a.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
CS305j Introduction to Computing Classes II 1 Topic 24 Classes Part II "Object-oriented programming as it emerged in Simula 67 allows software structure.
1 Object-Oriented Software Engineering CS Java OO Fundamentals Contents Classes and Objects Making new objects Method declarations Encapsulating.
1.Reading from Keyboard 2.Main programs 3.Responsibilities 1 CS12230 Introduction to Programming Lecture 2or3-Other things.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
OOP Basics Classes & Methods (c) IDMS/SQL News
Slides prepared by Rose Williams, Binghamton University Console Input and Output.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
File Input & Output Sections Outcomes  Know the difference between files and streams  Use a Scanner to read from a file  add “throws” annotations.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Programming – Lecture 15 Going Beyond the ACM Library.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
Programs and Models Almost all computer programs model some artifact – Artifact: product of civilization, either concrete or abstract, simple or complex.
Methods. Methods are groups of statements placed together under a single name. All Java applications have a class which includes a main method class MyClass.
Variable scope. Variable Scope Variables do not live forever. Failing to take that into account leads to problems. Let's look at an example. Let's write.
Loops A loop is: Java provides three forms for explicit loops:
CSC111 Quick Revision.
Input/Output.
Something about Java Introduction to Problem Solving and Programming 1.
Introduction to Classes and Methods
CSE 1020:Programming by Delegation
Java Programming Function Introduction
Week 4 Lecture-2 Chapter 6 (Methods).
Introduction to Java Brief history of Java Sample Java Program
Fundamentals of Software Development 1
Java Looking at our first console application in Eclipse
Java Programming Function Introduction
Methods/Functions.
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Fundamentals of Software Development 1Slide 1 Review: Why start with WordGames? You wrote your first lines of code in this course in WordGames.You wrote your first lines of code in this course in WordGames. Why start with such a complex project?Why start with such a complex project? Answer:Answer: –It is practical to do so, by using an interface to connect your code to ours –It makes the point that most software engineers modify/extend existing programs rather than creating their own “from scratch” See next slides for details on these two points

Fundamentals of Software Development 1Slide 2 UML class diagram for WordGames CapitalizerNameDropperxxx … StringTransformable transform(String) : String All our stuff The StringTransformable interface is how our code knows how to “connect” to your code Questions on this important idea?

Fundamentals of Software Development 1Slide 3 “From scratch” projects Today’s software engineering is almost NEVER “from scratch”Today’s software engineering is almost NEVER “from scratch” –Compilers translate from high-level language to machine code –We use libraries for printing and (in Java) much more –We reuse existing code During a 20 year career, a typical software engineer might:During a 20 year career, a typical software engineer might: –Work on about 20 projects –Be involved with the creation of only 1 or 2 projects from scratch For all the other projects, she modifies/extends existing projectsFor all the other projects, she modifies/extends existing projects We’ll do a “from scratch” project today called HelloWorldWe’ll do a “from scratch” project today called HelloWorld –So that you can see what one is like –And so that you can see “under the hood” of some of the concepts that you have been studying

Fundamentals of Software Development 1Slide 4 HelloWorld concepts – outline The next slide shows the entire HelloWorld programThe next slide shows the entire HelloWorld program –It illustrates the following concepts: The main methodThe main method Static methodsStatic methods Console projectsConsole projects How to use System.out.println to print a String to the consoleHow to use System.out.println to print a String to the console –As before, the slide omits comments to focus on the code –You experienced the above concepts in your own HelloWorld, Part 1

Fundamentals of Software Development 1Slide 5 HelloWorld – the complete program public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world"); } main is the name of the special method at which any Java application begins A static method is a method that “belongs” to the class instead of to each instance of the class. The static method cannot refer to the class’ non-static fields. The special main method is, by definition, static. System is a class that has “system” stuff System has a public static field called out that is a PrintStream – a thing that can print to the console main has command-line arguments sent as a String array println is a PrintStream method that prints its argument on a line Questions on any of these ideas?

Fundamentals of Software Development 1Slide 6 HelloWorld extended concepts – outline We just saw the following concepts from HelloWorld:We just saw the following concepts from HelloWorld: –The main method –Static methods –Console projects –How to use System.out.println to print a String to the console Now we turn to these additional concepts from HelloWorld:Now we turn to these additional concepts from HelloWorld: –How to read from the console (i.e., get input from the human) –How and why to use “helper” methods We continue to omit comments in order to focus on the codeWe continue to omit comments in order to focus on the code

Fundamentals of Software Development 1Slide 7 HelloWorld – the complete program public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world"); } System is a class that has “system” stuff System has a public static field called out that is a PrintStream – a thing that can print to the console To read from the console: 1.Declare and construct a new Scanner object, sending it System.in 2.Use the Scanner object’s next method to read and return a String Related methods to read int, double, etc. Exercise: What do you think is the name of the public field in System that is an InputStream – a thing that can read from the console? Answer: in Exercise: Write the statements that would read a String from the console. Ask questions!!! The answer is on the next slide, but you maximize your learning by thinking and asking, not looking.

Fundamentals of Software Development 1Slide 8 import java.util.Scanner; public class ScannerExample { public static void main(String[] args) { Scanner scanner; String input; scanner = new Scanner(System.in); System.out.print(“Enter a String: ”); input = scanner.next(); System.out.println(input.substring(3)); } To read from the console: When you use a library class (like Scanner), you usually need to import the class to tell Java where to find it. Declare a Scanner local variable Construct the Scanner, sending it System.in Prompt the human to type something next() waits for the user to type and returns the result. We could have done anything we want with the input – printing a substring of it is just an example.

Fundamentals of Software Development 1Slide 9 import java.util.Scanner; public class ScannerExample { public static void main(String[] args) { Scanner scanner; String input; scanner = new Scanner(System.in); System.out.print(“Enter a String: ”); input = scanner.next(); System.out.println(input.substring(3)); } To read from the console: This is the same slide as the previous slide. Study this code now. ASK QUESTIONS!

Fundamentals of Software Development 1Slide 10 “Helper” methods Encapsulation: bundling things together to make them easier to deal withEncapsulation: bundling things together to make them easier to deal with Encapsulation in methods:Encapsulation in methods: –Bundle a chunk of code –Give it a name –Perhaps give it parameters “Helper” methods“Helper” methods –Private methods that you create to help the rest of your program –Valuable for the same reasons that encapsulating in methods is valuable in general Allows a chunk of code to be referenced via a well-chosen name Allows the code to be reused in a more general way (by sending different values as arguments)

Fundamentals of Software Development 1Slide 11 import java.util.Scanner; public class ScannerExample { public static void main(String[] args) { ScannerExample.cubeRoot(12.0); for (int k = 100; k < 110; k = k + 1) { ScannerExample.cubeRoot((double) k); } ScannerExample.cubeRoot(); } private static void cubeRoot(double number) { System.out.println(“Cube root of ” + number + “ is ” + Math.pow(number, 1.0 / 3.0)); } private static void cubeRoot() { Scanner scanner = new Scanner(System.in); System.out.print(“Enter a number: ”); ScannerExample.cubeRoot(scanner.nextDouble()); } This slide illustrates: “helper” methods “for” loops Reading numbers from the console Methods that call other methods Study this code. ASK QUESTIONS! You will apply these ideas in HelloWorld, Part 2 (homework). The boxes are there to help your eyes – not part of the code If you wish, download and unzip ScannerExample ScannerExample

Fundamentals of Software Development 1Slide 12 HelloWorld extended concepts – summary We just saw the following concepts from HelloWorld:We just saw the following concepts from HelloWorld: –The main method –Static methods –Console projects –How to use System.out.println to print a String to the console –How to read from the console (i.e., get input from the human) –How and why to use “helper” methods Now do HelloWorld, Part 2 with your partnerNow do HelloWorld, Part 2 with your partnerHelloWorld, Part 2HelloWorld, Part 2