A Revamping Of our skills so far. Our Tools so Far Variable - a placeholder for a value Method - a set of code which accomplishes a task Class - a mold.

Slides:



Advertisements
Similar presentations
Programming Methodology (1). Implementing Methods main.
Advertisements

CIT 590 Intro to Programming Java lecture 4. Agenda Types Collections – Arrays, ArrayLists, HashMaps Variable scoping Access modifiers – public, private,
Access to Names Namespaces, Scopes, Access privileges.
19-Jun-15 Access to Names Namespaces, Scopes, Access privileges.
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
Classes with multiple methods Part 1. Review of classes & objects Early on, we learned that objects are the basic working units in object-oriented programs.
28-Jun-15 Access to Names Namespaces, Scopes, Access privileges.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
Introduction to Programming with Java, for Beginners Scope.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
COMP More About Classes Yi Hong May 22, 2015.
CSC 142 C 1 CSC 142 Object based programming in Java [Reading: chapter 4]
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Java Classes Methods Objects. Classes Classes We have been using classes ever since we started programming in Java Whenever we use the keyword class.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
1. 2 Reference... Student stu; Reference of Student stu When the reference is created it points to a null value. Before access the reference, objects.
More arrays Primitive vs. reference parameters. Arrays as parameters to functions.
Local Variables Garbage collection. © 2006 Pearson EducationParameters2 of 10 Using Accessors and Mutators Together What if you want to get a property.
1 Abstract Classes “I prefer Agassiz in the abstract, rather than in the concrete.” CS Computer Science II.
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.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
RECITATION 4. Classes public class Student { } Data Members public class Student { private String name; public String id; }
Procedural Programming Criteria: P2 Task: 1.2 Thomas Jazwinski.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
1 Methods Introduction to Methods Passing Arguments to a Method More About Local Variables Returning a Value from a Method Problem Solving with Methods.
More Methods and Arrays Material from Chapters 5 to 7 that we didn’t cover in 1226.
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.
Methods. Methods also known as functions or procedures. Methods are a way of capturing a sequence of computational steps into a reusable unit. Methods.
CS100A, Fall 1998 Key Concepts 1 These notes contain short definitions of the basic entities that make up a Java program, along with a description of the.
24-Dec-15 Class Structure. 2 Classes A class describes a set of objects The objects are called instances of the class A class describes: Fields (instance.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
Non-Static Classes What is the Object of this lecture?
Classes - Intermediate
Method Examples CS 139 Algorithm Development 10/06/2008.
Topics Instance variables, set and get methods Encapsulation
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
CSH Intro. to Java. The Big Ideas in Computer Science Beyond programming Solving tough problems Creating extensible solutions Teams of “Computational.
CONDITIONALS CITS1001. Scope of this lecture if statements switch statements Source ppts: Objects First with Java - A Practical Introduction using BlueJ,
ITM 3521 ITM 352 Functions. ITM 3522 Functions  A function is a named block of code (i.e. within {}'s) that performs a specific set of statements  It.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
Information and Computer Sciences University of Hawaii, Manoa
Examples of Classes & Objects
Some Eclipse shortcuts
Methods.
Method Mark and Lyubo.
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Building Java Programs
Class Structure 16-Nov-18.
Class Structure 28-Nov-18.
Classes & Objects: Examples
Group Status Project Status.
Classes, Encapsulation, Methods and Constructors (Continued)
Topic 10 Abstract Classes “I prefer Agassiz in the abstract,
Class Structure 7-Dec-18.
Implementing Classes Chapter 3.
Class Structure 2-Jan-19.
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Namespaces, Scopes, Access privileges
Topic 10 Abstract Classes “I prefer Agassiz in the abstract,
Class Structure 25-Feb-19.
Building Java Programs
Visibilities and Static-ness
ITM 352 Functions.
ITE “A” GROUP 2 ENCAPSULATION.
Presentation transcript:

A Revamping Of our skills so far

Our Tools so Far Variable - a placeholder for a value Method - a set of code which accomplishes a task Class - a mold for an object Object Instance - a variable which holds an object value If statement - alters flow of control based on boolean condition(s)

Variables -Have a type, name, and value int size = 5; Ball myBall = new Ball(50, Color.RED, 6); - Two kinds: Instance Variables and Local Variables typename value typename value

LOCAL VARIABLES -declared and defined w/in a method -can’t be accessed outside this method public class Tire { public Tire(){ int radius = 40; } public int getRad(){ return radius; } } X ‘radius’ is local to the constructor method and therefore can’t be accessed in this method INSTANCE VARIABLES -declared outside any methods (still w/in class) -can be accessed anywhere in the class -use the private keyword -should start with underscore public class Tire { private int _radius; public Tire(){ _radius = 40; } public int getRad(){ return _radius; } }

Methods -Block of code which can be called/executed public double average (double num1, double num2){ double sum = num1 + num2; double average = sum / 2.0; return average; } -always public -can have as many parameters as you want (including none) -use return type of void if method won’t return anything Modifier Return Type Method Name Parameters

void return type - Sometimes methods don’t need to return (output) anything - But every method needs to declare a return type public void greeting (boolean isMale){ if(isMale){ System.out.println(“Hello Sir”); } else{ System.out.println(“Hello Maam”); } } - note the lack of a return statement, void makes this fine!

Main Method This is where every java program starts One main method per program Looks like this: public static void main (String [] args){ //your java program starts here }

Classes The mold for our object instances Made up of two things: Instance Variables – model properties of the class Methods – model abilities of the class

Our Classic Ball Example public class Ball { //instance variables go here private int _size; private java.awt.Color _color; private int _bounciness; public Ball(int size, java.awt.Color color, int bounciness){ //this is the constructor method _size = size; _color = color; _bounciness = bounciness; } //here’s a method public void setSize(int newSize){ _size = newSize; } }

Object Instances Create one: Ball myBall = new Ball(60, Color.BLUE, 11); Call methods on it: myBall.setSize(30);

Now Something Random Many times you want to be able to create some randomness Java has a few solutions, here’s one: Random rand = new Random(); int randInt = rand.nextInt(5); A Java library object A method of the Random class randInt will be between 0 and 4

Call to Action Coding is inherently time-consuming You’ve been doing great work in lab But becoming a prolific coder will take more than 1.5hr/week You know enough to start embarking on your own projects outside of lab Dream big and start small Don’t be intimidated, you CAN do it! Stick with it!