Paradigmer i Programmering 4 a. Java 1.5 -Generics -Autoboxing/unboxing -New for sætning -Static imports -enum.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
The ArrayList Class and the enum Keyword
9-Jun-14 Enum s (and a review of switch statements)
1 CSE 331 Enumerated types ( enum ) slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Java for C++ Programmers Second Night. Overview First Night –Basics –Classes and Objects Second Night –Enumerations –Exceptions –Input/Output –Templates.
New features in JDK 1.5 Can these new and complex features simplify Java development?
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Phil Campbell London South Bank University Java 1 First Steps.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
1 Calling within Static method /* We can call a non static method from a static method but by only through an object of that class. */ class Test1{ public.
Java Programming Abstract classes and Interfaces.
Objects contains data and methods Class – type of object Create class first Then object or instance String – defined class String s; // creates instance.
Public class ABC { private int information = 0; private char moreInformation = ‘ ‘; public ABC ( int newInfo, char moreNewInfo) { } public ABC () {} public.
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
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.
Static Members, Structures, Enumerations, Generic Classes, Namespaces Learning & Development Team Telerik Software Academy.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Delegates and Events.
Övning 4. Repetition göra egna klasser class Rektangel { private double längd; private double bredd; public Rektangel(double l, double b) { this.längd.
1-May-15 Java 1.5. Reason for changes “The new language features all have one thing in common: they take some common idiom and provide linguistic support.
Identifying Coins Pennies, Nickels, Dimes, and Quarters.
Interfaces. Lecture Objectives To learn about interfaces To be able to convert between class and interface references To appreciate how interfaces can.
What is your strategy for counting money?
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Lecture 16 CIS 208 Friday March 18 th, Last bit on structs, I swear Structs in Debugger It’s your friend.
I wonder who has more money…. 1 dollar, 3 nickels, 5 dimes 6 dimes, 3 pennies, 5 quarters 8 pennies, 6 nickels, 3 dimes 2 half dollars, 5 pennies, 8 nickels.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Math Review Show each amount using the fewest number of coins. 98¢ pennies nickels dimes quarters 1.
1162 JDK 5.0 Features Christian Kemper Principal Architect Borland.
24-Oct-15 Java Java beta 1 (“Tiger”) Released February 4, Themes Ease of Development Scalability.
Coins and their names! Ms. Masland’s 2 nd Grade Class.
Money By: Rachel Morello Teacher Page Click here!
ILM Proprietary and Confidential -
Money Counting By: Aleela Bovell 2 nd Grade Math LETS BEGIN!
Counting Money Pennies, Nickels, & Dimes Created by Mrs. Miller Math SOL K.7 & 1.10.
Penny Nickel Dime Penny Nickel Dime Quarter Half Dollar.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Counting Coins. The Basics Quarter 25 cents Dime 10 cents.
MONEY! Pick the correct coin! Click here to get started!!
Touch Money Jane Hancock.
Let’s Learn About Money!
Name the United States Coins Count the Pennies 10 ¢
MATH AND MONEY.
Adding and Subtracting Money! Click on the dollar sign to begin!
Counting Quarters, Dimes, Nickels, and Pennies Click here to begin Click here to begin.
COINS.
Money Counting change! Counting change! © Math As A Second Language All Rights Reserved 2.MD#8 next.
2 nd Grade Math Counting Money by Annette Burchett.
Money – Change Combinations &MathLine. Start with each ring representing a penny Money – Change.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Money Matters Math Activity for Primary Students.
What is your strategy for counting money?
Dime.
Begin at 5. Count by 5s to 100. Begin at 30. Count by 10s to 150.
k-2 Lesson d: kids as coins Coin Signs
Money Concept Assessment Bank
null, true, and false are also reserved.
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
Name the United States Coins
Money, Money Click on the piggy bank to get started!
class PrintOnetoTen { public static void main(String args[]) {
Counting Money By Lauren Dodson.
Module 2 - Part 1 Variables, Assignment, and Data Types
Module 2 Variables, Assignment, and Data Types
Java 5 New Features 1-May-19.
Money Math Review.
Counting Money Pennies, Nickels, & Dimes
Presentation transcript:

Paradigmer i Programmering 4 a

Java 1.5 -Generics -Autoboxing/unboxing -New for sætning -Static imports -enum

Java 1.5: generics I stedet for List words = new ArrayList(); skriver man List words = new ArrayList (); Og String title = ((String) words.get(i)).toUppercase(); skriver man String title = words.get(i).toUppercase();

Java 1.5: generics class Box { private T val; void setValue( T val ) { this.val = val; } T getValue() { return val; } } Box stringBox = new Box (); Box intBox = new Box (); Box pointBox = new Box (); double x = pointBox.getValue().getX();

Java 1.5: for sætning main(String args[]){ for(String arg : args) System.out.println(arg); List words = new ArrayList (); … for(String word : words) System.out.println(word); }

Java 1.5: autobox/unbox Map m = new TreeMap (); for (String word : args) { m.put(word, m.get(word) + 1); }

Java 1.5: enum public enum Coin { penny(1), nickel(5), dime(10), quarter(25); Coin(int value) { this.value = value; } private final int value; public int value() { return value; } } public class CoinTest { public static void main(String[] args) { for (Coin c : Coin.VALUES) System.out.println(c + ": \t" + c.value() +"¢ \t" + color(c)); } private enum CoinColor { copper, nickel, silver } private static CoinColor color(Coin c) { switch(c) { case Coin.penny: return CoinColor.copper; case Coin.nickel: return CoinColor.nickel; case Coin.dime: case Coin.quarter: return CoinColor.silver; default: throw new AssertionError("Unknown coin: " + c); } } }

Java 1.5: static import int x = Math.max(y,z); I stedet import static java.lang.Math.max; class StatiskImport { static int max3( int a, int b, int c ) { return max( a, max(b, c) ); }

C#: static void Main(string[] args) { foreach (string s in args) Console.WriteLine(s); }

C#: properties public class Button { private string caption; public string Caption { get { return caption; } set { caption = value; Repaint(); } }} Button b = new Button(); b.Caption = "ABC"; // set; causes repaint string s = b.Caption; // get b.Caption += "DEF"; // get & set; causes repaint

C#: delegates void MultiCall(SimpleDelegate d, int count) { for (int i = 0; i < count; i++) { d(); } } … class Test{ static void F() { System.Console.WriteLine("Test.F"); } static void Main() { SimpleDelegate d = new SimpleDelegate(F); MultiCall(d,7); }