The document provides an overview of the content to be covered in Day 2 of training, including: reviewing classes and objects; exploring collection classes like NSArray, NSDictionary, and NSSet; learning about protocols and categories; and using NSUserDefaults for storage. It then describes building a simple contact list app that uses the Person, Employee, and Client classes, allows filtering contacts by name and sorting by last name, and distinguishes employee and client objects through introspection. Exercises are provided to practice these concepts by modifying existing classes and creating categories.
Object Oriented JavaScript.
Types in JavaScript
Objects in JavaScript
Object Literals
Calling Functions
Constructor Functions
new on JavaScript
Inheritance in JavaScript
__proto__
prototype
Object Oriented JavaScript.
Types in JavaScript
Objects in JavaScript
Object Literals
Calling Functions
Constructor Functions
new on JavaScript
Inheritance in JavaScript
__proto__
prototype
JavaScript - Chapter 4 - Types and StatementsWebStackAcademy
A computer program is a list of "instructions" to be "executed" by a computer.
In a programming language, these programming instructions are called statements.
A JavaScript program is a list of programming statements.
JavaScript statements are composed of:
Values, Operators, Expressions, Keywords, and Comments.
This statement tells the browser to write "Hello Dolly." inside an HTML element with id="demo":
JavaScript Data Types
JavaScript variables can hold many data types: numbers, strings, objects and more.
In programming, data types is an important concept.
To be able to operate on variables, it is important to know something about the type.
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...Paris Open Source Summit
WarpScript est un langage de programmation open source conçu pour facilement requêter, manipuler et traiter des données de séries temporelles à la volée. Bien qu'il soit compatible nativement avec Warp 10, WarpScript peut aussi être connecté à d'autre sources de données. Dans cette présentation, nous allons détecter des anomalies à la volée en utilisant des fonctions WarpScript et répondre aux questions suivantes. Que doit-on définir comme une anomalie ? Quel algorithme correspond au type d'anomalie que l'on cherche à détecter ? Comment prendre en compte la possible saisonnalité de mes données ?
Class object method constructors in javaRaja Sekhar
Presented By :
N.V.Raja Sekhar Reddy
www.technolamp.co.in
www.programming9.com
Want more interesting...
Watch and Like us @ https://www.facebook.com/Technolamp.co.in
subscribe videos @ http://www.youtube.com/user/nvrajasekhar
It's not your mother's C++ anymore. Manual memory management, tedious loops, difficult-to-use STL algorithms -- are all a thing of the past now. The new C++ 11 standard contains a huge number of improvements to the C++ core language and standard library, and can help C++ developers be more productive.
In this session we will discuss the major features of C++ 11, including lambda functions, type inference for local variables, range-based for loops, smart pointers, and more. We will see how to use these features effectively to modernize your existing C++ programs and how to develop in the modern C++ style.
JavaScript - Chapter 4 - Types and StatementsWebStackAcademy
A computer program is a list of "instructions" to be "executed" by a computer.
In a programming language, these programming instructions are called statements.
A JavaScript program is a list of programming statements.
JavaScript statements are composed of:
Values, Operators, Expressions, Keywords, and Comments.
This statement tells the browser to write "Hello Dolly." inside an HTML element with id="demo":
JavaScript Data Types
JavaScript variables can hold many data types: numbers, strings, objects and more.
In programming, data types is an important concept.
To be able to operate on variables, it is important to know something about the type.
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...Paris Open Source Summit
WarpScript est un langage de programmation open source conçu pour facilement requêter, manipuler et traiter des données de séries temporelles à la volée. Bien qu'il soit compatible nativement avec Warp 10, WarpScript peut aussi être connecté à d'autre sources de données. Dans cette présentation, nous allons détecter des anomalies à la volée en utilisant des fonctions WarpScript et répondre aux questions suivantes. Que doit-on définir comme une anomalie ? Quel algorithme correspond au type d'anomalie que l'on cherche à détecter ? Comment prendre en compte la possible saisonnalité de mes données ?
Class object method constructors in javaRaja Sekhar
Presented By :
N.V.Raja Sekhar Reddy
www.technolamp.co.in
www.programming9.com
Want more interesting...
Watch and Like us @ https://www.facebook.com/Technolamp.co.in
subscribe videos @ http://www.youtube.com/user/nvrajasekhar
It's not your mother's C++ anymore. Manual memory management, tedious loops, difficult-to-use STL algorithms -- are all a thing of the past now. The new C++ 11 standard contains a huge number of improvements to the C++ core language and standard library, and can help C++ developers be more productive.
In this session we will discuss the major features of C++ 11, including lambda functions, type inference for local variables, range-based for loops, smart pointers, and more. We will see how to use these features effectively to modernize your existing C++ programs and how to develop in the modern C++ style.
http://highperformancecoredata.com/
Learn how to analyze, debug, and squeeze every last bit of performance out of Core Data. The standard Core Data implementation is very powerful and flexible but lacks performance. In this advanced session we will cover various performance analysis tools, model optimization, and various high performance concurrency models. This is an advanced discussion that assumes you have used Core Data before.
JavaScript - An Introduction is a beginner's guide to JavaScript. It starts with very basic level and goes to intermediate level. You'll be introduced with every language constructs, Event handling, Form handling and AJAX which is supported by JavaScript with XMLHttpRequest object. This XHR object is discussed in enough detail so that you can understand how the underlying AJAX functionality works in jQuery. At the end it discusses advance concepts and library build on/around JavaScript.
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
Getting Started
Create a class called Lab8. Use the same setup for setting up your class and main method as you
did for the previous assignments. Be sure to name your file Lab8.java. Additionally, make
another file called Arrays.java. This file will be an object, so simply start it off by declaring an
Arrays class. You can copy the following skeleton and fill in the appropriate code below each of
the comments:
public class Arrays {
/ Instance Variables
// Constructors
// findMin 1
// findMax
// calcSum
// calcAverage
// toString
}
Task Overview
Your task for this lab is to create a class called Arrays with some array processing methods. This
class will maintain an array and the number of elements present in it. Additionally, methods will
be available to display the current min and max elements along with the average of all of them.
Finally, a toString() method will be available to cleanly display all the array elements. Finally,
you will write a simple driver class to test out the above Arrays class.
Part 1: Instance Variables for Arrays
The first thing to do for the Arrays class is to set up its instance variables. Declare the following
(private) instance variables:
• An int array called array ? this will be the array we will be writing methods for.
• An int called count - this represents the number of valid elements in the array.
Part 2:
Constructors for Arrays The Arrays class will have two constructors. The first constructor takes
the maximum size of the array as input as a parameter and initializes the array instance variable
appropriately. It also sets count to size. Finally, it will initialize all of the array elements to some
values between 0 and 10, inclusive. To create this constructor, follow these steps:
• Import java.util.Random to make use of the random number generator.
• Create a constructor with the following header: public Arrays(int size)
• Initialize your array variable and set its size to size (see the chart on page 252 for reference on
initializing arrays). Be very careful that you are setting the value of your array instance variable,
as opposed to creating a new variable called array.
• Set the value of the count variable to size because we will be populating the entire array.
• Copy the following code to the constructor in order to generate random values between 0 and
10, inclusive:
Random rand = new Random();
for (int i = 0; i < count; i++)
{
array[i] = (rand.nextInt(10));
}
Next, create another constructor with the following header: public Arrays(int[] arr). This
constructor will initialize the class by using the passed arr argument in order to fill its instance
variables. The following things need to be done inside of this constructor:
• Set the array variable equal to arr.
• Set the count variable equal to the length of the array.
Part 3: Displaying the Output findMin()
The first method of this class will search the array for the minimum element. Copy the following
code for the findMin method. Note how the count i.
This full day course will give you a hands-on, deep dive into React Native. In this course, you will learn how to build cross-platform mobile applications from scratch using Facebook's React Native.
ave time learning on your own. Start Building with React, MongoDB, Express, & Node. The MERN Stack.
Learning a new JavaScript framework is difficult. You can spend weeks learning new concepts. If an online example doesn’t work, you may spend countless hours Googling, searching Stack Overflow and blogs for the solution.
Take the fast track and learn from an experienced Senior Software Engineer and professional instructor!
About this Course
This highly interactive course features a large amount of student labs and hands-on coding. You will be taught how to assemble the complete stack required to build a modern web app using React.js, MongoDB (a NoSQL database) and Express (a framework for web application servers). This course will also cover many other tools that go into building a complete web application: React Router, React-Bootstrap, Redux, Babel, and Webpack.
What You Will Learn
• How to use modern JavaScript features
• Webpack
• Node & Express
• Reading and writing data to a MongoDB database
• Babel
• React
• State Management with Redux
• Mongoose
• And More!
5. Person Class
‣ Create a new project with a new class called
“Person”
‣ Properties
‣ firstName
‣ lastName
‣ address
‣ city
‣ state
‣ emailAddress
‣ phoneNumber
‣ Override the -(NSString *)description method
‣ Create an initializer taking first and last name
‣ Create some of each type and print to console
7. NSString
‣ Represents an array of characters
‣ All strings are UTF-8
‣ No need to worry about null terminator
‣ Strings are immutable
‣ The @”” syntax creates a new string literal.
‣ Use NSMutableString for strings that will be
modified
‣ Facilities for searching and comparing
8. NSNumber
‣ Storage class for numeric values
‣ chars, ints, floats, doubles, BOOL
‣ NSNumber will remember the type that was
put into it.
‣ Use this class for storing numerics in collections
(as we’ll see later)
‣ You can use NSDecimalNumber for a convenient
wrapper for dealing with base 10 decimal numbers
9. NSDate
‣ Houses a single point in time.
‣ Has facilities for comparisons and date arithmetic
‣ Use NSDateFormatter to customize the printing
of a given date
NSDate *date = [[NSDate alloc] init];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm 'on' EEEE MMMM d"];
NSLog("%@", [formatter stringFromDate:date]);
‣ Format strings are based on the unicode standard.
10. Exercises
‣ Open the fraction calculator application from
yesterday
‣ Modify the fraction class, adding an “asNumber”
method to return the value of the fraction as an
NSNumber.
‣ Modify the person class, adding a Date of Birth
field.
‣ Add the appropriate property declaration
‣ BONUS: Create a method that returns the
person’s age in years as an Integer.
‣ (Hint you will need use NSCalendar)
12. Collections Overview
‣ Provide common data structures
‣ Mutable and immutable flavors
‣ Collections work on objects only (ids).
‣ Primitives must stored converted to NSNumber
or NSValue.
‣ Common types
‣ NSArray - contiguous, indexed memory
‣ NSDictionary - objects are accessed by a string
key (aka Hashtable)
‣ NSSet - a bag of objects, unindexed. No
duplicates.
13. NSArray
‣ Ordered collection of objects
‣ Access is constant time
‣ A valid index of an array cannot be nil. You can
insert NSNull instead.
‣ Facilities for traversal, sorting, and querying.
‣ Arrays retain their members (more on this later)
14. Filtering / NSPredicate
‣ Filtering an array is simple using an NSPredicate:
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"lastName like %@", @"zearfoss"];
‣ Operation modifiers : [cd]
‣ “Case and diacritic insensitive”
‣ Diacritics means OHare == O’Hare
‣ Many operators available:
‣ Predicate Programming Guide
NSArray *filtered = [array filteredArrayUsingPredicate:predicate];
15. Sorting an Array
‣ Using NSSortDescriptor
‣ A sort descriptor contains a key and an ordering
(ASC / DESC) :
NSSortDescriptor *d
= [NSSortDescriptor sortDescriptorWithKey:@"lastName" ascending:YES];
NSArray *sds = [NSArray arrayWithObject:d];
NSArray *sorted = [array sortedArrayUsingDescriptors:sds];
16. NSDictionary
‣ Associations of keys and values
‣ Only one value per key
‣ Keys are determined by calling isEqual on the key
‣ Key can be any object
‣ Cannot insert nil for a key, use NSNull
‣ Includes facilities for traversing
‣ Dictionaries retain their members
17. NSSet
‣ A completely unordered collection of objects
‣ Operations are fast (constant time) but no control
over which object you get.
‣ Multiple objects can be added using an
NSCountedSet
18. Mutability
‣ Use modifiable collections by using the mutable
variant:
‣ NSMutableArray
‣ NSMutableDictionary
‣ NSMutableSet
‣ NSMutableCountedSet
19. Fast Enumeration
‣ Objects support traversal in a for . . . in construct
for (id obj in array)
{
/* statements */
}
‣ If you know what type of objects are in the array,
you can specify that type in the loop:
for (NSString *str in array)
{
/* statements */
}
20. Quick Exercise
‣ Modify the person class to contain a dictionary of
phone numbers with the following keys:
‣ “Office”
‣ “Home”
‣ “Cell”
‣ Use extern variables for the keys
‣ Create a method, phoneNumberForKey:
(NSString *)key to get phone numbers
‣ Create another method, setPhoneNumberForKey:
(NSString *)key
‣ Remove the property for phone numbers
22. Inheritance in Obj-c
‣ We have already see inheritance:
@interface Calculator : NSObject
‣ Methods can be overridden, such as (NSString
*)description
‣ While you don’t have to, all your classes should
inherit NSObject
‣ Benefits of NSObject
‣ Reflection & Introspection
‣ Dynamic method invocation
‣ Basic equality checking
‣ Memory management benefits
24. Managing Memory
‣ Reference count system
‣ alloc . . . init gives a reference count of 1
‣ copy gives a reference count of 1
‣ retain raises the reference count
‣ release drops the reference count
‣ When an object reference count reaches 0 and is
no longer in scope, it’s dealloc method is called and
the object is destroyed.
‣ The Rule: If you alloc, copy, or retain an object,
you must release.
25. Examples
‣ This must be released (alloc . . . init)
NSArray *array = [[NSArray alloc] init];
‣ This must be released (copied)
NSArray *array2 = [array copy];
‣ This should not be released (no alloc, copy, retain)
NSArray *array = [NSArray array];
‣ This must be released (reatined)
NSArray *array = [[NSArray array] retain];
26. The Autorelease Pool
‣ Messages from convenience constructors should
send objects an autorelease message.
‣ Objects sent an autorelease message are added
to the autorelease pool.
‣ The pool is drained at the end of the event loop
cycle, at which point all objects are sent a
release message.
‣ You have no control over when autorelease
pools are drained.
‣ Attempting to release an autoreleased object
will raise an exception.
28. Why?
‣ Fraction : : add: does not contain the words copy
or init
‣ The sender of the add message has no indication
that it should assume memory management
responsibility over the returned object.
29. Polymorphism and
Dynamic Binding
‣ Objects are dynamically typed at run-time
‣ Overridden methods are resolved by receiver
type, not to pointer type.
‣ Analogous to virtual in C++
‣ Referred to as late binding
‣ (You always get what you expect)
30. Example
@interface Base : NSObject
{
}
- (void)printMe;
@end
@interface Derived : Base
{
}
- (void)printMe;
@end
/* ... */
Base *obj = [[Derived alloc] init];
[obj printMe];
31. The Class Object
‣ Classes themselves are objects
‣ Calling a class (static) method calls a method on
the class object.
‣ Aids in introspection
‣ Get the class object by calling [anObject class]
32. Object Introspection
‣ Objects know what kind of class they are.
‣ These methods are built into the NSObject class
(another reason to always subclass NSObject).
True if the receiver is or
isKindOfClass:(Class)
inherits from the class
True if the receiver is an
isMemberOfClass:(Class)
instance of the class
True if the receiver is or
isSubclassOfClass:(Class)
inherits from the class
True if the supplied selector
respondsToSelector:(SEL)
is defined
33. All things are types
‣ Virtually all Objective-c constructs are types, and
may be used as such:
‣ Classes (as we’ve seen)
‣ Methods (compile time methods)
‣ Selectors (run time methods)
‣ IVars
‣ Properties
‣ Categories (coming later)
‣ Protocols (coming later)
‣ Details about these are found in the Runtime
Reference
‣ Classes and Selectors are commonly used.
34. Object Equality
NSString *str = @"foo";
NSArray *a1 = [NSArray arrayWithObject:str];
NSArray *a2 = [NSArray arrayWithObject:str];
NSLog(@"%d", (a1 == a2));
// FALSE!!!
‣ Objects are pointers, therefore == compares
addresses.
‣ Objects should override isEqual: where we want to
be able to check for object equality.
35. Exercises
‣ Fraction class
‣ Create a convenience constructor for the
fraction class:
+(Fraction *)fractionWith . . . .
‣ Override isEqual:(id)
‣ Override -(id)copy
36. More Exercises
‣ Create 2 subclasses of Person
‣ Client with properties:
companyName, companyPhone
‣ Employee with properties:
departmentName, managerName, title
‣ Override initializers and create convenience
constructors:
‣ personWithFirstName:LastName:
‣ clientWithFirstName:LastName:Company
‣ employeeWithFirstName:LastName:Department:
‣ Provide -(id)copy and isEqual for Person and
derived classes.
38. Protocols
‣ Analogous to Interfaces in Java, pure virtual in C++
‣ Defines a set of methods that an object may
implement.
‣ Allows for anonymous objects
‣ Often used for delegate definitions, offloading
some custom functionality to another class.
‣ Objects are said to “conform to a protocol”
‣ Formal protocols are named, informal protocols
exist in the frameworks.
‣ Formal protocols can contain @required and
@optional members
39. Example Protocols
Defines methods for copying
NSCopying
of objects
Defines methods for archival
NSCoding
of objects
Provides additional base level
NSObject
object methods
Defines some application
UIApplicationDelegate
lifecycle methods
‣ Adopting a protocol:
@interface MyClass : NSObject <NSCoding, NSCopying>
{
}
@end
40. Defining a Protocol
@protocol myProtocol
@optional
- (void)optionalMethod:(int)arg;
@required
- (void)requiredMethod:(int)arg;
@property (nonatomic, assign) int someProperty;
@end
‣ Protocols may do anything but define iVars
‣ Protocols may also conform to other protocols
‣ Type for an object conforming to a protocol:
‣ id<Protocol> obj;
41. Categories
‣ No analog in any other language (that I know of)
‣ Allow for composite classes
‣ Allows the developer to add functionality to class
without subclassing
‣ Categories can:
‣ Override existing methods
‣ Add methods to an existing class
‣ Adopt a protocol
‣ Categories cannot:
‣ Add iVars to a class
42. Using a Category
‣ Interface File:
@interface NSString
(VP)
+ (NSString*)stringWithUUID;
@end
‣ Implementation
@implementation NSValue(Selector)
+ (NSString*)stringWithUUID
{
// Create a new UUID
CFUUIDRef uuidObj = CFUUIDCreate(nil);
// Get the string representation of the UUID
NSString *newUUID = (NSString*)CFUUIDCreateString(nil, uuidObj);
CFRelease(uuidObj);
return [newUUID autorelease];
}
43. Exercises
‣ Modify the person and fraction classes to handle
the following:
‣ NSCopying Protocol
‣ NSCoding Protocol
‣ Create a category on NSNumber to allow to for
initialization with a fraction:
‣ +(NSNumber *)numberWithFraction:
(Fraction*)
45. NSUserDefaults
‣ Designed for holding small bits of user preference
data
‣ BUT, can be used for saving application state
between sessions
[[NSUserDefaults standardUserDefaults] setObject:anObject
forKey:@"myObject"];
‣ (There are better ways of doing this, which we’ll
cover tomorrow)
47. Simple Contact List
‣ Use project shell provided
‣ Use person, employee, and client classes
‣ Use introspection to show clients and employees
differently
‣ Use filtering to allow the user to screen objects by
name
‣ Use sorting to always sort the list by last name