Static revisited. Odds and ends. Static methods. Static methods 5/2/16. Some features of Java we haven t discussed



Similar documents
CS100: Introduction to Computer Science

A Secure Implementation of Java Inner Classes

Chapter 6: Variance, the law of large numbers and the Monte-Carlo method

Infinite Sequences and Series

SECTION 1.5 : SUMMATION NOTATION + WORK WITH SEQUENCES

Your organization has a Class B IP address of Before you implement subnetting, the Network ID and Host ID are divided as follows:

Modified Line Search Method for Global Optimization

Lecture 2: Karger s Min Cut Algorithm

Domain 1: Configuring Domain Name System (DNS) for Active Directory

.04. This means $1000 is multiplied by 1.02 five times, once for each of the remaining sixmonth

Time Value of Money, NPV and IRR equation solving with the TI-86

CCH Accountants Starter Pack

Soving Recurrence Relations

Now here is the important step

5 Boolean Decision Trees (February 11)

I apply to subscribe for a Stocks & Shares ISA for the tax year 20 /20 and each subsequent year until further notice.

Factoring x n 1: cyclotomic and Aurifeuillian polynomials Paul Garrett <garrett@math.umn.edu>

(VCP-310)

Simple Annuities Present Value.

Lesson 17 Pearson s Correlation Coefficient

In nite Sequences. Dr. Philippe B. Laval Kennesaw State University. October 9, 2008

Confidence Intervals for One Mean

Handling. Collection Calls

Authentication - Access Control Default Security Active Directory Trusted Authentication Guest User or Anonymous (un-authenticated) Logging Out

Domain 1: Designing a SQL Server Instance and a Database Solution

How To Solve The Homewor Problem Beautifully

I. Why is there a time value to money (TVM)?

CCH Accounts Production

1. C. The formula for the confidence interval for a population mean is: x t, which was

Desktop Management. Desktop Management Tools

CHAPTER 3 THE TIME VALUE OF MONEY

Example 2 Find the square root of 0. The only square root of 0 is 0 (since 0 is not positive or negative, so those choices don t exist here).

Engineering Data Management

1 Computing the Standard Deviation of Sample Means

How to use what you OWN to reduce what you OWE

Configuring Additional Active Directory Server Roles

LECTURE 13: Cross-validation

Exam 3. Instructor: Cynthia Rudin TA: Dimitrios Bisias. November 22, 2011

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies ( 3.1.1) Limitations of Experiments. Pseudocode ( 3.1.2) Theoretical Analysis

Chapter 14 Nonparametric Statistics

Repeating Decimals are decimal numbers that have number(s) after the decimal point that repeat in a pattern.

5.4 Amortization. Question 1: How do you find the present value of an annuity? Question 2: How is a loan amortized?

INVESTMENT PERFORMANCE COUNCIL (IPC)

How to set up your GMC Online account

Taking DCOP to the Real World: Efficient Complete Solutions for Distributed Multi-Event Scheduling

INVESTMENT PERFORMANCE COUNCIL (IPC) Guidance Statement on Calculation Methodology

CS100: Introduction to Computer Science

Comparing Credit Card Finance Charges

Solving Logarithms and Exponential Equations

Z-TEST / Z-STATISTIC: used to test hypotheses about. µ when the population standard deviation is unknown

Lesson 15 ANOVA (analysis of variance)

Best of security and convenience

Hypothesis testing. Null and alternative hypotheses

5.3. Generalized Permutations and Combinations

Sole trader financial statements

I apply to subscribe for a Stocks & Shares NISA for the tax year 2015/2016 and each subsequent year until further notice.

Project Deliverables. CS 361, Lecture 28. Outline. Project Deliverables. Administrative. Project Comments

Chapter 5: Inner Product Spaces

CS103A Handout 23 Winter 2002 February 22, 2002 Solving Recurrence Relations

Mathematical goals. Starting points. Materials required. Time needed

AP Calculus AB 2006 Scoring Guidelines Form B

client communication

Professional Networking

Quantitative Computer Architecture

ODBC. Getting Started With Sage Timberline Office ODBC

Investing in Stocks WHAT ARE THE DIFFERENT CLASSIFICATIONS OF STOCKS? WHY INVEST IN STOCKS? CAN YOU LOSE MONEY?

Math C067 Sampling Distributions

ADMISSION AND REGISTRATION

COMPARISON SHOPPING. 7 Store brands or generic brands usually cost. less than name or national brands. 7 Generic brand foods are safe and good for

Elementary Theory of Russian Roulette

Determining the sample size

Time Value of Money. First some technical stuff. HP10B II users

Normal Distribution.

FM4 CREDIT AND BORROWING

Inference on Proportion. Chapter 8 Tests of Statistical Hypotheses. Sampling Distribution of Sample Proportion. Confidence Interval

Vision Care Program. Vision Discounts Voluntary Vision Benefits LASIK Discounts

Week 3 Conditional probabilities, Bayes formula, WEEK 3 page 1 Expected value of a random variable

Chapter 10 Computer Design Basics

Case Study. Normal and t Distributions. Density Plot. Normal Distributions

Domain 1: Identifying Cause of and Resolving Desktop Application Issues Identifying and Resolving New Software Installation Issues

A Test of Normality. 1 n S 2 3. n 1. Now introduce two new statistics. The sample skewness is defined as:

FI A CIAL MATHEMATICS

CCH CRM Books Online Software Fee Protection Consultancy Advice Lines CPD Books Online Software Fee Protection Consultancy Advice Lines CPD

Chapter 5 Unit 1. IET 350 Engineering Economics. Learning Objectives Chapter 5. Learning Objectives Unit 1. Annual Amount and Gradient Functions

Present Value Factor To bring one dollar in the future back to present, one uses the Present Value Factor (PVF): Concept 9: Present Value

Measures of Spread and Boxplots Discrete Math, Section 9.4

FIBONACCI NUMBERS: AN APPLICATION OF LINEAR ALGEBRA. 1. Powers of a matrix

GCSE STATISTICS. 4) How to calculate the range: The difference between the biggest number and the smallest number.

Analyzing Longitudinal Data from Complex Surveys Using SUDAAN

ADMISSION AND REGISTRATION

3G Security VoIP Wi-Fi IP Telephony Routing/Switching Unified Communications. NetVanta. Business Networking Solutions

1. Introduction. Scheduling Theory

Pre-Suit Collection Strategies

Practice Problems for Test 3

Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed.

CCH Practice Management

CHAPTER 4: NET PRESENT VALUE

Theorems About Power Series

Consider these sobering statistics

How deductible plans work

Transcription:

Odds ad eds Static revisited Some features of Java we have t discussed Static methods // Example: // Java's built i Math class public class Math { public static it abs(it a) { if (a >= 0) { retur a; else { retur -a; public static double todegrees(double radias) { retur radias * 180 / PI; // Usig the class: System.out.pritl(Math.abs(-5)); //did t eed to create ay object Static methods static: Part of a class, ot part of a object. Static methods: Do ot reuire a istace of the class ad do ot uderstad the implicit parameter, this; therefore, caot access a object's istace variables good for code related to a class but ot to each object's state if public, ca be called from iside or outside the class 1

Examples i the Java library static: Part of a class, rather tha part of a object. Classes ca have static variables. are ot replicated i each object; a sigle variable is shared by all objects of that class. private static type ame; or, private static type ame = value; Example: private static it cout = 0; i the System class: System.i ad System.out. (System is a class, ad out is a static variable i that class, that has a method called pritl) Ad i the Java Math class: public class Math { public static fial double PI = 3.141592653589793; public static fial double E = 2.718281828459045; https://docs.oracle.com/javase/7/docs/api/java/lag/system.html Example You are writig a class to represet a bak accout, ad you would like the costructor to automatically assig a ruig umber as the accout umber. Assigig ids for BakAccout public class BakAccout { // static variable for assigig a accout umber // (shared amog all istaces of the class) private static it lastassigednumber = 1000; // istace variables(replicated for each object) private float balace; private it id; How ca static variables help you? public BakAccout(float iitial_balace) { lastassigednumber++; // advace the id id = lastassigednumber; // give umber to accout balace = iitial_balace; public it getid() { retur id; // retur this accout's id 2

Iitializig static variables 1. Do othig. variable is iitialized with 0 (for umbers), false (for boolea values), or ull (for objects) 2. Use a explicit iitializer, such as public class BakAccout { private static it lastassigednumber = 1000; // Executed oce should usually be declared private Figure from: Big Java by Cay Horstma Exceptio: Static costats, which may be either private or public: public class BakAccout { public static fial double OVERDRAFT_FEE = 5; // Refer to it as BakAccout.OVERDRAFT_FEE Java features we have t discussed Packages A package is a amed collectio of related classes that are grouped i a directory Usig code from a package: import java.awt.rectagle; Rectagle rectagle = ew Rectagle(); Miimize the use of static variables (static fial variables are ok) http://docs.oracle.com/javase/tutorial/java/package/idex.html 3

Java features we have t discussed JUit: a framework that lets you write tests for each method, the easily ru those tests (uit testig) Marti Fowler: Never i the field of software developmet was so much owed by so may to so few lies of code. The stadard tool for test-drive developmet i Java JUit itegratio i Eclipse Java features we have t discussed Aotatios. Provide iformatio about a program Example: @Override public boolea euals(object obj) { If a method marked with @Override does t override a method i oe of its superclasses, the compiler geerates a error. Java features we have t discussed Fial methods ad classes A fial method caot be overridde A fial class caot be exteded Example: public fial class Strig Java features we have t discussed Geerics. You ve had a taste more i CS200. 4

Exceptios revisited Util ow you oly used predefied Java exceptios. You ca write your ow! Why would you wat to do that? Example public class DivideByZero Exceptio exteds Exceptio { public DivideByZeroExceptio() { super( Divide by zero ); public DivideByZeroExceptio(Strig message) { super(message); Savitch Chapter 9 5