Written by: Dr. JJ Shepherd

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Written by: Dr. JJ Shepherd
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Road Map Introduction to object oriented programming. Classes
Java Syntax Primitive data types Operators Control statements.
Object Oriented Programming.  OOP Basic Principles  C++ Classes  September 2004  John Edgar 22.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
Lecture 22 Miscellaneous Topics 4 + Memory Allocation.
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Java Tutorial. Object-Oriented Programming Concepts Object –a representation of some item state  fields/members and should be encapsulated behavior 
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
The Java Programming Language
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.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
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.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
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.
Introduction to Java Java Translation Program Structure
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Copyright Curt Hill Variables What are they? Why do we need them?
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
CMSC 341 Java Packages, Classes, Variables, Expressions, Flow Control, and Exceptions.
Lab 4 - Variables. Information Hiding General Principle: – Restrict the access to variables and methods as much as possible Can label instance variables.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
CS1101 Group1 Discussion 10 Lek Hsiang Hui comp.nus.edu.sg
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
A High Flying Overview CS139 – Fall 2006 How far we have come.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
OOP Basics Classes & Methods (c) IDMS/SQL News
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Arrays Chap. 9 Storing Collections of Values 1. Introductory Example Problem: Teachers need to be able to compute a variety of grading statistics for.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Today Encapsulation. Build a fully encapsulated Halloween class, going from Halloween1 to Halloween6 (eventually!): –The final version will have overloaded.
Written by: Dr. JJ Shepherd
Objects as a programming concept
Lecture 2: Data Types, Variables, Operators, and Expressions
CMPE212 – Stuff… Exercises 4, 5 and 6 are all fair game now.
null, true, and false are also reserved.
Defining Classes and Methods
JAVA CLASSES.
CIS 199 Final Review.
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

Written by: Dr. JJ Shepherd CSCE 146 Hey Remember Java? Written by: Dr. JJ Shepherd

Objectives Review the basics of Java Variables Branch Statements Loops Arrays Classes Inheritance Exceptions

Website www.cse.sc.edu/~shephejj/csce146/ Still under construction but will be up soon!

146 Notes This class is about how to structure data in a logical and efficient way Goals for each data structure is what it is, how we use it, and why we use it The most important parts to take away are the overall concepts of each one This class is focused less on do you know how to program in java and more do you understand the concepts that can be applied to any language

Key difference with 146 Efficiency now matters Don’t expect me to give you the code I go over in class I will give pseudo code Unless I specifically say otherwise you MAY NOT use Java’s built in data structures or data functionality (Like sorting and searching) I want you to understand what is behind that code

Key difference with 146 Cheating is NOT tolerated and code is highly scrutinized Cheating off of other students Copying code off of the internet Yes labs and homework is harder Are you surprised? I encourage you all to work together but don’t copy code

145 Was Sure Neat Hey you passed! That’s pretty rad Let’s review!

Variables Used to store information Has a defined size Two Types of Variables Primitive Types int, double, char Class Types String, PrintWriter, Exception

Variables Defining Variables Tells the computer to allocate storage in memory given a name Concept Example <<type>> <<name>>; int tacosConsumed; String tacoConvo;

Variables Initializing and Assigning Variables Sets variable to a defined value Concept Example <<name>> = <<value>>; tacosConsumed = 20; tacoConvo = “I ate “ + tacosConsumed + ” tacos. I feel sick now”;

Branch Statements Used for decision making problems If statement concept if(<<boolean expression>>) { <<body statements>> }

Branch Statements Else statements are the catch all of if statements Only exist if there is a prior if statement Else Concept if(<<boolean expression>>) { <<if body>> } else <<else body>>

Branch Statements Else if’s are short handed if statements in else statements Else if concept else { if(<<boolean expression>>) <<else if body>> } else if(<<boolean expression>>) { <<else if body>> }

Branch Statements Switch statements are specialized branch statements that has cases which can be integers, characters, or Strings Switch concept switch(<<variable>>) { case <<value>>: <<case body>> break; … default: <<default body>> }

Loops Loops repeat code until a boolean condition is no longer true While Loop Concept while(<<boolean expression>>) { <<loop body>> }

Loops For loops are used to loop the body a set amount of times For loop concept for(<<counter>>;<<boolean expression>>;<<update counter>>) { <<loop body>> }

Loops Do while’s are dumb They stupidly run 1 to many times Concept do { <<loop body>> } while(<<boolean expression>>);

Arrays Arrays are collections of data of the same type Concept for declaring arrays Use a for loop to initialize each element in the array ***These are used a lot in this course*** <<type>>[] <<name>> = new <<type>>[<<amount>>];

Classes Blueprints to create objects Remember the steps Define the class Instance variables Constructors Accessors and Mutators Additional Methods

Classes Defining the class Concept public class <<name>> { <<body of the class>> }

Classes Instance variables are the attributes of the class Concept public class <<name>> { private <<type>> <<name>>; … }

Classes Constructors constructs an instance of a class in memory and sets the instance variables to a value Default constructors have no parameters and set everything to a default value public <<name of the class>>() { <<set all instance variables>> }

Classes Parameterized Constructors have parameters that set one or all of the instance variables to a value Concept public <<name of the class>>(<<parameters>>) { <<set instance variables to parameters>> }

Classes Mutators are used to modify instance variables in a class Adds a layer of protection by validating values Concept public void <<set variable name>>(<<parameter>>) { this.<<variable>> = <<parameter>>; }

Classes Accessors are used to get values of instance variables outside of the class Concept public <<type>> <<get variable name>>() { return this.<<variable>>; }

Classes Methods are behaviors of classes Used internally and externally Accessors and mutators are methods Concept <<scope>> <<return value>> <<name>> (<<parameters>>) { <<body of the method>> }

Classes Static methods are static in memory Used as helper methods that exist outside of one particular instance <<scope>> static <<return value>> <<name>> (<<parameters>>) { <<body of the static method>> }

Inheritance Used to take the attributes and methods from a parent (super) class Concept public class <<name>> extends <<parent name>> { <<body of the class>> }

Inheritance In inherited constructors need to all the parent’s constructor by calling “super” Concept To call inherited methods use “super.” super(<<parameters>>); super.<<method name>>;

Interfaces Used as a blueprint to create classes. Classes are a blueprint to create instance of objects Only has method definitions Concept public interface <<name>> { <<method definition>>; … }

Interfaces Interfaces are the building concept of polymorphism To use an interface used “implements” Concept public class <<name>> implements <<interface name>> { <<body of the class>> }

Exceptions Gracefully allows programs to crash and an exceptional event happens To create exceptions extend the/an exception class Then call the parent’s constructors

Exceptions Concept public <<name>> extends <<Exception>> { public <<name>>(<<parameters>>) super(<<parameters>>) }

Exceptions Methods that can throw exceptions need to check for those cases Concept <<scope>> <<return>> <<name>> (<<parameters>>) throws <<Exceptions>> { … throw new <<exception name>>(); }

Exceptions If a method throws an exception it must be called in a try catch block that handles the exception Concept try { <<method that throws exception>>; } catch(<<exception name>> e) System.out.println(e.getMessage());