Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#

Slides:



Advertisements
Similar presentations
Algorithms and Problem Solving
Advertisements

Lab#1 (14/3/1431h) Introduction To java programming cs425
03 Data types1June Data types CE : Fundamental Programming Techniques.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 28, 2005.
Datalogi A 1: 8/9. Book: Cay Horstmann: Big Java or Java Consepts.
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
Introduction to a Programming Environment
C# Programming: From Problem Analysis to Program Design1 2 Your First C# Program.
ASP.NET Programming with C# and SQL Server First Edition
GTECH 731 Lab Session 2 Lab 1 Review, Lab 2 Intro 9/6/10 Lab 1 Review Lab 2 Overview.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Introduction to Information and Computer Science Computer Programming Lecture c This material (Comp4_Unit5c), was developed by Oregon Health and Science.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
CS1101: Programming Methodology Aaron Tan.
Microsoft Visual Basic 2005: Reloaded Second Edition
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College Lecture 2: Working with Visual.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014
1 Java Console I/O Introduction. 2 Java I/O You may have noticed that all the I/O that we have done has been output The reasons –Java I/O is based on.
CS 106 Introduction to Computer Science I 03 / 19 / 2007 Instructor: Michael Eckmann.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Console Input. So far… All the inputs for our programs have been hard-coded in the main method or inputted using the dialog boxes of BlueJ It’s time to.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
Lecture 2: Classes and Objects, using Scanner and String.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
CSE 131 Computer Science 1 Module 1: (basics of Java)
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.
CIT 590 Intro to Programming First lecture on Java.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
CSC1401 Classes - 1. Learning Goals Computing concepts Identifying objects and classes Declaring a class Declaring fields Default field values.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
1 Principles of Computer Science I Prof. Nadeem Abdul Hamid CSC 120 – Fall 2005 Lecture Unit 2 - Using Objects.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
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.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Department of Computer Engineering Using Objects Computer Programming for International Engineers.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
Object Oriented Programming (OOP) LAB # 1 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
Input Characters from the Keyboard tMyn1 Input Characters from the Keyboard We have been using console output, but not console (keyboard) input. The main.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 6_1 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Chapter 10 Thinking in Objects
Advanced Programming Lecture 02: Introduction to C# Apps
Java IO and Testing made simple
Chapter 3 – Introduction to C# Programming
Fall 2018 CISC124 2/15/2019 CISC124 TA names and s will be added to the course web site by the end of the week. Labs start next week in JEFF 155:
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
F II 2. Simple Java Programs Objectives
CS313T Advanced Programming language
Presentation transcript:

Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#

“AP Computer Science with.NET and J#” Lecture 3: Object-Oriented Programming in Java and J# Microsoft.NET Workshops for Teachers

3-3 MicrosoftAP Computer Science with.NET and J# Workshop Track LectureTopic 1Java — History, Philosophy, and Overview 2Procedural Programming in Java and J# 3Object-oriented Programming in Java and J# 4Primitive Types vs. Object References (==, equals, toString, and arrays) 5Writing Your Own Classes 6Keeping Track of Your Objects with the Collection Classes 7Algorithms and Algorithm Analysis 8Debugging and Exception Handling Collection Classes and Iteration 19Additional Resources and Ideas

3-4 MicrosoftAP Computer Science with.NET and J# Lecture — Objectives “While procedural programming focuses on the code, object-oriented programming (OOP) is all about objects — solving a problem using objects that model the problem domain. Examples of common objects include Students, Customers, ShoppingCarts, Rectangles, and Files. Today, OOP is considered the best overall approach since it more closely models how we think about problems…” Topics: –Object-oriented programming –Creating objects –Writing classes –Working with objects [ Joe Hummel, Lake Forest College ]

3-5 MicrosoftAP Computer Science with.NET and J# Part 1 Object-Oriented Programming

3-6 MicrosoftAP Computer Science with.NET and J# Motivation Why OOP? Object-oriented programming enables us to: –think in terms of real-world objects –improve organization since code & data reside together Common examples of objects in computer programs: –students –customers, products, shopping carts –graphical shapes (rectangles, circles, …) –graphical user interfaces (windows, buttons, text boxes, …) –files Object

3-7 MicrosoftAP Computer Science with.NET and J# public static void main(String[] args) throws Exception { String first, last; int midExam, finalExam; first = getString("Please enter first name: "); last = getString("Please enter last name: "); midExam = getInt("Enter midterm exam score: "); finalExam = getInt("Enter final exam score: "); outputNameAndExamAverage(first, last, midExam, finalExam); System.in.read(); // keep console window open until user presses ENTER… } public static void main(String[] args) throws Exception { String first, last; int midExam, finalExam; first = getString("Please enter first name: "); last = getString("Please enter last name: "); midExam = getInt("Enter midterm exam score: "); finalExam = getInt("Enter final exam score: "); outputNameAndExamAverage(first, last, midExam, finalExam); System.in.read(); // keep console window open until user presses ENTER… } Example — Before OOP Suppose we want to compute a student's exam score average Procedural approach: –We use local vars to hold data –We use procedures to compute

3-8 MicrosoftAP Computer Science with.NET and J# Same Example using OOP Object-oriented approach: –Think in terms of a Student object –The Student object holds the data & performs the computations public static void main(String[] args) throws Exception { Student s; s = new Student(); // create a Student object to hold data s.outputNameAndExamAverage(); // ask object to output name and exam average System.in.read(); } public static void main(String[] args) throws Exception { Student s; s = new Student(); // create a Student object to hold data s.outputNameAndExamAverage(); // ask object to output name and exam average System.in.read(); } Key idea: the same work is being performed (prompt, input, compute), it’s just being done by a separate, self-contained program entity — an “object”. Objects give us a more natural way to organize programs… Student

3-9 MicrosoftAP Computer Science with.NET and J# Advantages? Makes it easier to represent lots of students –What if you had 100 students? –Easier to have 100 self-contained objects than 400 pieces of data… Makes it easier to work with complex problems –What if you had 1200 students, 100 faculty & 3000 courses to track? –Easier to think in terms of self-contained Student, Faculty and Course objects…

3-10 MicrosoftAP Computer Science with.NET and J# Student Class Objects are defined by templates called classes Here’s our Student class: –A student has 4 variables (“ fields ”) and two procedures (“ methods ”) public class Student { public String first, last; // fields for name and exam scores public int midExam, finalExam; public Student() throws Exception // method {. } public void outputNameAndExamAverage() throws Exception // method {. } public class Student { public String first, last; // fields for name and exam scores public int midExam, finalExam; public Student() throws Exception // method {. } public void outputNameAndExamAverage() throws Exception // method {. } Kim Lee Method with same name as class is called a “constructor” — called automatically by Java’s new operator to initialize object’s fields Ordinary subroutine method — note the lack of “static” keyword, because method is called via “object.” syntax

3-11 MicrosoftAP Computer Science with.NET and J# Demo! Student exam average using objects…

3-12 MicrosoftAP Computer Science with.NET and J# Implementation Details Here’s a complete implementation of the Student class: public class Student { public String first, last; public int midExam, finalExam; public Student() throws Exception { System.out.print("Please enter first name: "); first = Program.keyboard.readLine(); System.out.print("Please enter first name: "); last = Program.keyboard.readLine(); System.out.print("Enter midterm exam score: "); midExam = Integer.parseInt(Program.keyboard.readLine()); System.out.print("Enter final exam score: "); finalExam = Integer.parseInt(Program.keyboard.readLine()); } public void outputNameAndExamAverage() throws Exception { double avg; avg = (midExam + finalExam) / 2.0; System.out.println(first + " " + last + ", your average is " + avg); } public class Student { public String first, last; public int midExam, finalExam; public Student() throws Exception { System.out.print("Please enter first name: "); first = Program.keyboard.readLine(); System.out.print("Please enter first name: "); last = Program.keyboard.readLine(); System.out.print("Enter midterm exam score: "); midExam = Integer.parseInt(Program.keyboard.readLine()); System.out.print("Enter final exam score: "); finalExam = Integer.parseInt(Program.keyboard.readLine()); } public void outputNameAndExamAverage() throws Exception { double avg; avg = (midExam + finalExam) / 2.0; System.out.println(first + " " + last + ", your average is " + avg); } import java.io.*; public class Program { public static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); import java.io.*; public class Program { public static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); Note use of “Classname.” when accessing static item

3-13 MicrosoftAP Computer Science with.NET and J# Part 2 Working with Objects

3-14 MicrosoftAP Computer Science with.NET and J# Java Objects Java is an object-oriented programming language As a result, most things in Java are objects –Keyboard, console screen, strings, … import java.io.*; public class Program { public static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws Exception {. String s; s = keyboard.readLine(); // ask keyboard object to read next line of input int len; len = s.length(); // ask string object for length of its string System.out.println(len); // now ask console screen object to output this value for us char c; c = s.charAt(len – 1); // ask string object for last char in string (0-based indexing) System.out.println(c); import java.io.*; public class Program { public static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws Exception {. String s; s = keyboard.readLine(); // ask keyboard object to read next line of input int len; len = s.length(); // ask string object for length of its string System.out.println(len); // now ask console screen object to output this value for us char c; c = s.charAt(len – 1); // ask string object for last char in string (0-based indexing) System.out.println(c);

3-15 MicrosoftAP Computer Science with.NET and J# Demo! Working with common Java objects…

3-16 MicrosoftAP Computer Science with.NET and J# Beware — Java vs.NET objects Java contains a large class library called the JCL –Java Class Library.NET also contains a large class library called the FxCL –.NET Framework Class Library How do you tell them apart in J#? –Look for the little “J” in the IntelliSense icons, which means Java… len = s.l

3-17 MicrosoftAP Computer Science with.NET and J# Beware — not everything is an object? Wait! Not everything in Java is an object…  The good news is this makes Java programs more efficient  The bad news is this makes Java programming more complex Example: –Integers and reals are not objects, so you cannot treat them as such Object obj; obj =...; // let obj represent *any* object in Java int i; i =...; // let i represent any integer value String s1, s2; s1 = obj.toString(); // every object has a toString() method to convert object to a string s2 = i.toString(); s2 = String.valueOf(i); // since i is not an object, we have to ask String class to convert it Object obj; obj =...; // let obj represent *any* object in Java int i; i =...; // let i represent any integer value String s1, s2; s1 = obj.toString(); // every object has a toString() method to convert object to a string s2 = i.toString(); s2 = String.valueOf(i); // since i is not an object, we have to ask String class to convert it

3-18 MicrosoftAP Computer Science with.NET and J# Demo! Not everything in Java is an object…

3-19 MicrosoftAP Computer Science with.NET and J# Differentiating between Objects and Non-Objects The easiest way to identify objects is via capitalization –If type starts with an UPPER-CASE letter, it represents an object –If type starts with a lower-case letter, it is not an object int i = 1234; double d = ; String s = "Hello world!"; BufferedReader keyboard = new...; int i = 1234; double d = ; String s = "Hello world!"; BufferedReader keyboard = new...; non-objects objects

3-20 MicrosoftAP Computer Science with.NET and J# Learning more about Java Objects Java contains 1,000’s of classes One of the hurdles to learning Java is learning its classes… How to learn more? –Java books and tutorials –Explore via Visual Studio’s IntelliSense –Visual Studio’s integrated help (F1) Position cursor on type and press F1 Lookup in index using Java package name + type (e.g. “java.lang.String”) –Sun’s online documentation:

3-21 MicrosoftAP Computer Science with.NET and J# Summary Java programming is object-oriented programming –though procedural programming is alive and well Object-oriented programming requires a new way of thinking –a program is built from classes –classes are templates for creating objects –objects store program data & perform program computations Is object-oriented programming easier? –at first, no –in the long-term, yes…

3-22 MicrosoftAP Computer Science with.NET and J# Resources Web site for slides, demos, associated lab exercises: – – – Supplemental Reading: –M. Weisfeld, “ The Object-Oriented Thought Process ” (language-neutral) –D. West, “ Object Thinking ” (language-neutral) –Sierra & Bates, “ Head First Java ” Your students may really like this one, a very hip approach to learning Java

3-23 MicrosoftAP Computer Science with.NET and J# That’s it! Next up: LectureTopic.. 4Primitive Types vs. Object References (==, equals, toString, arrays)......