COP 2800 Lake Sumter State College Mark Wilson, Instructor.

Slides:



Advertisements
Similar presentations
Escape Sequences \n newline \t tab \b backspace \r carriage return
Advertisements

COMP 110: Introduction to Programming Tyler Johnson Mar 23, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Basic Java Constructs and Data Types – Nuts and Bolts
Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
Methods Java 5.1 A quick overview of methods
Perkovic, Chapter 7 Functions revisited Python Namespaces
Building Java Programs
1 MATH METHODS THAT RETURN VALUES. 2 JAVA'S MATH CLASS.
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Return values.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Lecture 15.1 Static Methods and Variables. © 2006 Pearson Addison-Wesley. All rights reserved Static Methods In Java it is possible to declare.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Pemrograman Dasar - Data Types1 OPERATOR. Pemrograman Dasar - Data Types2 Arithmetic operator  + - * /  / operator denotes integer division if both.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Lecture 2: Object Oriented Programming I
1 Fundamental Data types Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions l Assignment statement l Increment.
CS 106 Introduction to Computer Science I 02 / 24 / 2010 Instructor: Michael Eckmann.
Review Java.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
CS 106 Introduction to Computer Science I 02 / 19 / 2007 Instructor: Michael Eckmann.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
1 Python Chapter 2 © Samuel Marateck, After you install the compiler, an icon labeled IDLE (Python GUI) will appear on the screen. If you click.
1 Data types, operations, and expressions Continued l Overview l Assignment statement l Increment and Decrement operators l Short hand operators l The.
Constructors A constructor is a method that creates an object in Java. It does not return anything and it is not void. It’s only purpose is to create an.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
Applications in Java Towson University *Ref:
10/25: Methods & templates Return to concepts: methods Math class methods 1 st Program of the day About DrawLine.java modifications Method definitions.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Basic Java Syntax CSE301 University of Sunderland Harry R Erwin, PhD.
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.
The java.lang Package chapter 8 Java Certification Study Group February 2, 1998 Seth Ladd.
Math With Java The Math Class. First, A Quick Review of Math Operators in Java Primitive Data type in Java that represent numbers: Primitive Data type.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
Slides prepared by Rose Williams, Binghamton University Chapter 5 Defining Classes II.
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with.
10-Nov-15 Java Object Oriented Programming What is it?
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
Geoff Holmes Date Math Weighted Distr Strings String methods Tokenizers System Examples Utility Classes (Chapter 17) import java.util.*;
Introduction to Methods. Previously discussed There are similarities in make up of that can help you remember the construct of a class a class in the.
CSCE 121: Introduction to Program Design and Concepts, Honors J. Michael Moore Spring 2015 Set 14: Plotting Functions and Data 1.
Basics and arrays Operators:  Arithmetic: +, -, *, /, %  Relational:, >=, ==, !=  Logical: &&, ||, ! Primitive data types Byte(8), short(16), int(32),
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
PHY 107 – Programming For Science. Announcements  Lectures may not cover all material from readings  Material that is most difficult or challenging.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Creating and Using Class Methods. Definition Class Object.
CPRG 215 Introduction to Object-Oriented Programming with Java Module 2- Using Java Built-in Classes Topic 2.4 Using Java Built-in Classes Produced by.
Chapter 5 Defining Classes II Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
CSE 110: Programming Language I Afroza Sultana UB 1230.
Chapter 7 User-Defined Methods.
Static Members and Methods
Java Primer 1: Types, Classes and Operators
C Short Overview Lembit Jürimägi.
Static and non-Static Chapter 5.
CMSC 202 Static Methods.
Unit-2 Objects and Classes
The Building Blocks Classes: Java class library, over 1,800 classes:
Classes and Objects 5th Lecture
Java Classes and Objects 3rd Lecture
More About Objects and Methods
Programs and Classes A program is made up from classes
Classes and Objects Static Methods
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

COP 2800 Lake Sumter State College Mark Wilson, Instructor

Mid-Term Review

Static and Final

 Static variable is still variable (mutable)  Sometimes called a class variable  One variable shared with all objects of the class (belongs to the class, not the object)  Default Initialization applies  Initialized before object creation and before any static method of the class runs  Improves compiler optimization private static int variableName;

 Point to a single object  Can’t be altered to point to another object  Object pointed to works as expected

Public class Duck { private int size; private static in duckCount = 0; public Duck () { duckCount++; } public void setSize(int s) { size = s; } public int getSize() { return size; }

 Good for utilities that don’t rely on instance variables  Belongs to the class, not the object  Can call any other static method  Can’t call non-static methods  Can’t use non-static instance data  Can act on variables passed in parameters  Called using the class name: Math.abs(i);  Remember: every program has a public static void main(String[] args) public static void methodName() {... }

 Only available to nested classes  We aren’t going there in this course

 Not really variable (immutable)  Must be initialized at definition or in constructor  Can only be assigned once  Static final variable = constant private final int VARIABLE_NAME = 0; public static final double PI =

 Initialize at definition or  Initialize in static public static final double PI = public static final double SEED; static { SEED = Math.random(); }

 Can’t be overridden class Stuff { public final void things () { // do important things // that can’t be overridden }

 Can’t be extended final class Stuff { public final void things () { // do important things // that can’t be overridden } // more stuff }

Math

 Provides a set of math functions  Similar to but, less extensive than C/C++ math libraries  Included in java.lang, no import required  Methods are all static  No instance variables  Private constructor therefore can’t be instanced  Employs overloading int index = Math.random() * range;

 Random  Round  Min  Max  Abs  Sqrt  Cbrt  Pow  Floor  Ceil  copySign  Sin  Sinh  Cos  Cosh  Tan  Asin  Acos  Atan  Atan2  ToDegrees  toRandom  Exp  Expm1  Hypot  Log  Log10  Log1p  Nextafter  Nextup  Scalb  getExponent

Wrapping Primitives

Boolean Character Byte Short Integer Long Float Double  One to one match to the primitives  Spelling isn’t always the same  Have some static methods int aValue = 999; Integer wrappedValue = new Integer(aValue); int unWrapped = wrappedValue.intValue();

 Use either a primitive or its wrapper type virtually anywhere either is expected  Method arguments  Return values  Boolean expressions  Operations on numbers  Assignments  Compiler takes care of the accounting  Not the same as assigning different number formats or casting

 Exceptions  Packages, Jars and Deployment. Oh, my!