Presentation is loading. Please wait.

Presentation is loading. Please wait.

Written by: Dr. JJ Shepherd

Similar presentations


Presentation on theme: "Written by: Dr. JJ Shepherd"— Presentation transcript:

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

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

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

4 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

5 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

6 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

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

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

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

10 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”;

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

12 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>>

13 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>> }

14 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>> }

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

16 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>> }

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

18 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>>];

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

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

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

22 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>> }

23 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>> }

24 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>>; }

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

26 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>> }

27 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>> }

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

29 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>>;

30 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>>; }

31 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>> }

32 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

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

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

35 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());


Download ppt "Written by: Dr. JJ Shepherd"

Similar presentations


Ads by Google