CPSC150 Spring 2007 Dr. L. Lambert. CPSC150 Overview Syllabus Use Textbook, ask questions, extra thorough, I will post sections covered All information.

Slides:



Advertisements
Similar presentations
Fields, Constructors, Methods
Advertisements

University of Palestine software engineering department Introduction to data structures Introduction to java application instructor: Tasneem Darwish.
CPSC150 Fall 2008 Dr. L. Lambert. CPSC150 Overview Syllabus Use Textbook, ask questions, extra thorough, I will post sections covered All information.
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Object Oriented Concepts 2 Stewart Blakeway FML 213
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
CPSC150 JavaDr. L. Lambert CPSC150 Fall 2005 Dr. L Lambert.
Using JOptionPanes for graphical communication with our programs. Pages Horstmann 139.
CPSC150 Spring 2006 Dr. L Lambert. Week 1/2 intro (and Chapter 1)
Fall 2007ACS-1903 BlueJ Ron McFadyen Lab 1: Using BlueJ at UofW The purpose of this lab is to give you some experience with BlueJ. Over the course of the.
CPSC150 JavaLynn Lambert CPSC150 Spring 2005 Dr. Lambert.
Writing methods and Java Statements. Java program import package; // comments and /* … */ and /** javadoc here */ public class Name { // instance variables.
Objects Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
Introduction to Java A lab course by Dr. Junaid Ahmed Zubairi SUNY Fredonia.
Arrays, Loops weeks 4-6 (change from syllabus for week 6) Chapter 4.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Static, main, math, Strings. What helps me learn Java the most: A. Going to the Mac lab B. Writing Java on the Board C. Doing the Homework D. Watching.
Honors 101, Fall 2006 Please do not sit in back of room! Lots of info on web page Join the mailing list Download Eclipse and start using it Read the text.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Java: Chapter 1 Computer Systems Computer Programming II Aug
Chapter 5- Even more about objects and methods. Overview n Designing methods n Methods, methods, methods n Overloading methods n Constructor methods n.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
Java: Chapter 1 Computer Systems Computer Programming II.
EDW647: Internet for Educators Dr. Roger Webster Department of Computer Science Millersville University July 23, 2008 Create.
Introduction to Programming with Java. Overview What are the tools we are using – What is Java? This is the language that you use to write your program.
Lecture 61 CS110 Lecture 6 Thursday, February 12, 2004 Announcements –hw2 due today Agenda –questions –testing –modeling text files –declarations (classes,
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Introduction to Java. 2 Textbook David J. Barnes & Michael Kölling Objects First with Java A Practical Introduction using BlueJ Fourth edition, Pearson.
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.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Introduction to Computation and Problem Solving Class 9: Static Methods and Data Members Prof. Steven R. Lerman and Dr. V. Judson Harward.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
CIT 590 Intro to Programming First lecture on Java.
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
10-Nov-15 Java Object Oriented Programming What is it?
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.
Objects and Classes Chapter Nine. Definition “an object is a combination of some data (variables) and some actions (methods)”. Hopefully the data and.
Object Oriented Programming (OOP) LAB # 1 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
More about Java Classes Writing your own Java Classes More about constructors and creating objects.
Objects and Classes Start on Slide 30 for day 2 Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Much of.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
1 Introduction to Object Oriented Programming Chapter 10.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
Lecture 3: More on Classes Textbook: Chapter 2 Recap: –Classes vs. Objects –Q: What comes first a class or an object? –Q: Do we need a class to create.
CS/ENGRD 2110 FALL 2013 Lecture 3: Fields, getters and setters, constructors, testing 1.
1 Required , Google Group 1.Send the professor (This is also listed in the –In the Subject,
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Eastside Robotics Alliance / Newport Robotics Group 1 T/Th, 6:30 – 8:30 PM Big Picture School Day 3 · 10/9/2014.
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Agenda Warmup Lesson 2.5 (Ascii, Method Overloading)
Java Programming with BlueJ
Recap Week 2 and 3.
Programming in JavaScript
Programming in JavaScript
Java objects: a first view
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Java Programming with BlueJ Objectives
Java Programming Language
In this class, we will cover:
The beginning of media computation Followed by a demo
Presentation transcript:

CPSC150 Spring 2007 Dr. L. Lambert

CPSC150 Overview Syllabus Use Textbook, ask questions, extra thorough, I will post sections covered All information and assignments posted on CPSC150 web page: –On web now, first homework For anything you don’t see on the web page, send me All grades posted on WebCT

Success in this Class Collaborative Come prepared to work in class Take notes; pay attention; ask questions Never procrastinate Don’t assume you know/can program easily Come see me/Java expert early and often Ask questions Consult with (possibly non-expert) peers, but be careful. >50% of your grade is exams. Make sure you are doing your own work before you take the exam

Success in the Department Join ACM, IEEE, SWE Study with others. –Right now, find others and exchange: major, contact information, one thing about you Sign up for department info. 1.open browser, go to 2.click on mailing lists, and students and careers 3.Subscribe using an address that you read regularly

Using Java and BlueJ We will use BlueJ for program development BlueJ runs on the Java virtual machine BlueJ is IDE – lots of others (e.g., Eclipse) BlueJ is free and available for Mac, Windows, UNIX Download BlueJ for your home machines for development: (download Java 1.5 first): (Download SDK, NOT JRE)

Next Steps Running Java Code Reading Java Code Writing Java Code

Running a program: BlueJ Demo: Shapes Classes - everything in BlueJ is a class Object Bench - holds objects in BlueJ Objects constructors - create an object Calling methods –makeVisible, changeSize, moveHorizontal Parameters: what info does method need?

Reading Source Code A Java program import package; // if any // comments and /* … */ and /** javadoc here */ public class Name { // instance variables or fields // visible to all methods in class // constructors. with no parameters is Default // methods } Look at: Circle source code

Parts of a Java program: Textbook 1.10 comments reserved words modifiers - public/private others statements blocks { } classes methods main method

Parts of a Java program: comments reserved words modifiers - public/private others statements blocks { } classes methods main method - not there. skip this Find in Circle source code

Writing a Program public class Sphere // in your code, put blank lines and {s on lines by themselves { private double radius; // instance var should always be private // other types: double, int, char, boolean, String (note capital), others public Sphere( ) { // constructor is named same as class name. radius = 1.0; } public Sphere(double myRadius) { // second constructor radius = myRadius; } // double is type that is returned public double calculateVolume( ) { double volume; // local variable. no private/public // = is assignment. this calculation is not quit right. why? volume = 4 / 3 * * radius * radius * radius; return volume; } }

Go to Mac lab or Use laptops Bring laptops to class

Write, Compile and Test Listing Figure 1.2, page 22 /** This program displays a message */ import javax.swing.JOptionPane; // case matters public class Message // begin classes with capital { // no variables in this program /** Constructor is named the same thing as class. In textbook, code is in main, and call to JOptionPane has another parameter. either is ok */ public Message( ) { JOptionPane.showMessageDialog(null, "Print your message here"); // or System.out.println("Print your message here"); on terminal }

Java program import package; // comments and /* … */ and /** javadoc here */ public class Name { // instance variables or fields // constructors. with no parameters is Default // methods }

Which are ok? public class ATestClass { /* A */ private int number; /* B. */ public int number; /* C. */ public Int number; /* D. */ private String name; /* E. */ String name; // constructor on next page } // keep the valid ones Create a class and type in the following. Which are ok? Compile. See what compiles. Why do the others not compile? Which compile, but are not ok?

Instance Variables What does the following do? public ATestClass ( ) { number = 3; //prints in terminal window System.out.println("number is " + number); String mystring = "this string"; name = "another string"; name = new String("A Third String"); System.out.println("name is " + name + "mystring is " + mystring + "); System.out.println(name + mystring); } 1.Add this constructor. Compile 2.Create an object. What happened? Why? 3.Inspect fields by right clicking, then choosing inspect 4.Change the names of the variables. What happens?

Class details: fields/instance variables private type name; –always private –name is lowercase (Classes are caps) Visible to all methods in class –local variables visible only to that method Can be primitive type or Object type

Primitive vs Objects private int myField; // primitive –char, boolean, double, int, a few others private Square wall; // Object type –user and library defined –look at Picture and inspect –primitive has data; object has pointer 1.Open Picture in Examples. Compile. Create a Picture object 2.Inspect wall field/instance variable 3.Add an integer field 4.Inspect it

Back to lecture

Java program import package; // comments and /* … */ and /** javadoc here */ public class Name { // instance variables or fields // constructors. with no parameters is Default // methods }

Class details: constructors Initialize objects. Called when object is created same name as class name no return type can be overloaded public Circle(int x, int y, int size, String startColor) { diameter = size; xPosition = x; yPosition = y; color = startColor; isVisible = false; } public Circle( ) { diameter = 30; xPosition = 20; yPosition = 60; color = "blue"; isVisible = false; }

public Circle(int x, int y, int size, String startColor) { diameter = size; xPosition = x; yPosition = y; color = startColor; isVisible = false; } public Circle( ) { diameter = 30; xPosition = 20; yPosition = 60; color = "blue"; isVisible = false; } 1.On the board, write a Circle constructor with a color parameter. call: new Circle("yellow"); 2.Write a variable declaration for Circle e. Create the circle using your new constructor. Circle c = new Circle( ); Circle d = new Circle(10, 20, 30, "green" );