Showing posts with label term. Show all posts
Showing posts with label term. Show all posts

Wednesday, December 7, 2016

Software Terms.

Framework and Software Testing
  • A framework is a semi-complete application that provides a reusable and common structure to share among developers who can incorporate it into their own application and extend it to their specific needs. 
  • A framework has a more coherent structure than a toolkits with a set of utility classes.
  • For example, JUnit (www.junit.org) is a framework created by Erich Gamma and Kent Beck in 1997, following an earlier work called SUnit.
  • Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides wrote the classic "Design Patterns : Elements of Reusable Object-Oriented Software" book in 1995 and the four authors are often referred to as the Gang of Four (GoF).
  • Kent Beck's software discipline: Extreme Programming

Types of Testing
  • Programmer Test or customer test
  • Unit test: confirms the method (or a unit of work) accepts the expected range of input and returns the expected output value for each input.
    • API contract provides a view of expected behavior by method signature.
    • Notion of API contract
    • An exception should be thrown if the method cannot fulfill the contract.
  • Integration tests
  • Acceptance tests
  • Functional tests / Behavioral tests
    • web page links
    • database connection
    • forms
    • cookies
  • Usability tests
    • efficiency
    • navigation
    • UI
    • content checking
    • visual style
  • Compatibility tests
    • browser compatibility
    • OS
    • mobile browser
    • printing options
  • Performance tests
    • traffic
    • loads
    • stress testing
  • Security tests
    • authentication and authorization
    • session management
    • cryptography and SSL
    • data validation
    • denial of service
    • risky activities



Sunday, October 9, 2016

OOP Programming Terms.


CRUD versus REST

CRUD means the basic operations to be done in a data repository. You directly handle records or data objects; apart from these operations, the records are passive entities. Typically it's just database tables and records. It is a simple term that was abbreviated because it's a common feature in many applications, and it's easier to say CRUD. It describes the 4 basic operations you can perform on data (or a resource). Create, Read, Update, Delete.

REST, on the other hand, operates on resource representations, each one identified by an URL. These are typically not data objects, but complex objects abstractions. It is more of a named practice just like AJAX but not a technology in itself. It encourages use of capabilities that have long been inherent in the HTTP protocol, but seldom used. When you have a URL (Uniform Resource Locator) and you point your browser to it by the address line, you're sending an HTTP request. Each HTTP request contains information that the server can use to know which HTTP response to send back to the client that issued the request.

Each request contains a URL, so the server knows which resource you want to access, but it can also contain a method. A method describes what to do with that resource.

But this "method" concept wasn't used very often.

Usually, people would just link to pages via the GET method, and issue any type of updates (deletions, insertions, updates) via the POST method.

And because of that you couldn't treat one resource (URL) as a true resource in itself. You had to have separate URLs for deletion, insertion or update of the same resource.

For example, a resource can be a user's comment. That means not only a record in a 'comment' table, but also its relationships with the 'user' resource, the post that comments, maybe another comment that it answers.

Operating on the comment isn't a primitive database operation, it can have significant side effects, like firing an alert to the original poster, or recalculating some gamelike 'points', or updating some 'followers stream'.

Also, a resource representation includes hypertext (check the HATEOAS principle), allowing the designer to express relationships between resources, or guiding the REST client in an operation's workflow.

In short, CRUD is a set primitive operations (mostly for databases and static data storages), while REST is a very-high-level API style (mostly for webservices and other 'live' systems).

a single URL describes a single resource. A single post is a single resource. With REST you treat resources the way they were meant to be treated. You're telling the server which resource you want to handle, and how to handle it.

There are many other features to "RESTful architecture", which you can read about in Wikipedia, other articles or books, if you're interested. There isn't a whole lot more to CRUD itself, on the other hand.


Example
http://...com/posts/create- POST request  -> Goes to posts.create() method in the server
http://...com/posts/1/show- GET request  -> Goes to posts.show(1) method in the server
http://...com/posts/1/delete - POST request  -> Goes to posts.delete(1) method in the server
http://...com/posts/1/edit- POST request  -> Goes to posts.edit(1) method in the server
With REST, you create forms that are smarter because they use other HTTP methods aside of POST, and program your server to be able to distinguish between methods, not only URLS. So for example:
http://...com/posts - POST request  -> Goes to posts.create() method in the server
http://...com/posts/1 - GET request  -> Goes to posts.show(1) method in the server
http://...com/posts/1 - DELETE request  -> Goes to posts.delete(1) method in the server
http://...com/posts/1 - PUT request  -> Goes to posts.edit(1) method in the server

CDN (Content Distribution Network)
  • Several companies, including Google and Microsoft, allow you to link to jQuery, and some other common libraries, and get that file directly from their servers.
  • This is more reliable and speedier.
  • Spreading the requests across different servers can improve performance.
  • Caching benefits - shared sites got cached on the client machine.
  • Remove "http:" to avoid complaints of encryption or not.
Example
// Linking to Google CDN
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js">
</script>
// remove http:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js">
</script>

Abstract Factory pattern vs Factory Method pattern

Abstract Factory vs. Factory Method

The methods of an Abstract Factory are implemented as Factory Methods. Both the Abstract Factory Pattern and the Factory Method Pattern decouples the client system from the actual implementation classes through the abstract types and factories. The Factory Method creates objects through inheritance where the Abstract Factory creates objects through composition.

The Abstract Factory Pattern consists of an AbstractFactory, ConcreteFactory, AbstractProduct, ConcreteProduct and Client.

How to implement

The Abstract Factory Pattern can be implemented using the Factory Method Pattern, Prototype Pattern or the Singleton Pattern. The ConcreteFactory object can be implemented as a Singleton as only one instance of the ConcreteFactory object is needed.

Factory Method pattern is a simplified version of Abstract Factory pattern. Factory Method pattern is responsible of creating products that belong to one family, while Abstract Factory pattern deals with multiple families of products.

Factory Method uses interfaces and abstract classes to decouple the client from the generator class and the resulting products. Abstract Factory has a generator that is a container for several factory methods, along with interfaces decoupling the client from the generator and the products.

When to Use the Factory Method Pattern

Use the Factory Method pattern when there is a need to decouple a client from a particular product that it uses. Use the Factory Method to relieve a client of responsibility for creating and configuring instances of a product.

When to Use the Abstract Factory Pattern

Use the Abstract Factory pattern when clients must be decoupled from product classes. Especially useful for program configuration and modification. The Abstract Factory pattern can also enforce constraints about which classes must be used with others. It may be a lot of work to make new concrete factories.


Sunday, September 25, 2016

Java Classes.


Terms
  • Local variable
  • Instance variable/members
  • Class variable/members
  • Fields (they are variables)
  • Methods (Functions in C++)
    • Method Overloading
    • Static Factory Methods
  • Constructor
  • Varargs (variable length of argument list)
  • Packages
  • Class Access Control Modifiers (public, private, default, protected)
Access Level Classes outside the package Classes in the same package Child Class Same Class
public yes yes yes yes
protected no yes yes yes
default no yes no yes
private no no no yes

Example
import java.io.FileReader;

class MyClassName {
    int localVar1;
    double localVar2;

    // public field name accessible by obj/reference
    public int instanceVar3; 
    // class field name available without obj creation
    // it is accessible by className.classVar
    static int classVar1;

    // Constructors
    public void MyClassName (int ageValue, double phoneNumber) {
    }
    // Method Overloading
    // 1. number of parameters 
    // 2. datatype 
    // 3. sequence of parameters
    public void MyClassName (char gender) {
    }

    void methodName1 (listOfArguments) {
        this.classVar1 = 0;
        this.localVar1 = 2;
        this.localVar2 = 3;
    }

    int methodName2 (int inputNumber, int a, int b) {
    }
    ClassName2 getData () {
        return new ClassName2(); // return a handle/reference
    }

    public static void main (String[] args) {
    }
}

// To create an object (an object reference to be precise)
// use: new MyClassName;
// without new to create and construct the object, 
// myInstanceName == null;
// public variable and method can be accessed by
// objectReference.methodName
// objectReference.fieldName
MyClassName myInstanceName = new MyClassName();
myInstanceName.instanceVar3 = 24;

if (book == null) {
    book = new Book(); // create the object/reference
}


Class member versus Instance member

Java supports the notion of static members, which are class members that can be called without first instantiating the class.
public static int a;
static public int b;
static final int NUMBER_OF_MONTHS = 12;
public static final float PI = (float) 22 / 7;

public static int add (int a, int b) {
    return a + b;
}

// You can't call non-static members from a static method
// Remember, if it is not declared to be static, it does not
// exist until you create/construct the object/instance

pub class StaticDemo {
    public int b = 9;
    public static void main (String[] args) {
        System.out.println (b); // will generate compile error!
    }
}

// To solve the above error, there are two solutions.
// 1. Make b static
// 2. Create an instance of the class and access b 
//    by the object reference

// You can only declare a static variable in a class level.
// You cannot declare local static variables even if the 
//    method is static.



Useful Packages
  • java.awt.Component
  • java.awt.Container
  • java.awt.Object
  • java.awt.Object
    • java.applet.Applet

  • java.io
  • java.io.File
  • java.nio.File
  • java.io.FileReader
  • java.io.PrintWriter
  • java.io.FileNotFoundException
  • java.io.PrintSteam
  • java.lang.annotation
  • java.lang.Boolean
  • java.lang.Integer
  • java.lang.Math
  • java.lang.Object (toString)
  • java.lang.reflect
  • java.lang.Runtime
  • java.lang.Scanner
  • java.lang.String
  • java.lang.StringBuffer
  • java.lang.StringBuilder
  • java.lang.System
  • java.math.BigDecimal
  • java.sql.Date
  • java.time.Clock
  • java.text.NumberFormat
  • java.util.ArrayList
  • java.util.Calendar
  • java.util.Date
  • java.util.LocalDate
  • java.util.Locale
  • java.util.Random
  • java.util.Scanner
  • java.util.*

EXAMPLE
// You cannot use new to instantiate an object when a class has a
// private constructor, such as java.util.LocalDate. Instead, use
// its static methods.

LocalData today = LocalDate.now ();

// such methods are called static factory methods.
// Often time this is because these private constructors define 
// constants and members that should stay intact by the class users.

// The static factory methods can invoke the private constructors 
// because they are in the same class. This way, the class creator 
// can restrict an object to contain only certain legitimate values 
// and make other values impossible.

import static java.lang.System.out;

...
out.print("id");
out.println ("whatever you want to print");




    JAVA Terms.


    General

    • abstraction
    • encapsulation
    • enum
    • inheritance
    • inner classes
    • polymorphism
    • precedence (answer)

    Operators
    - Unary Minus Operator
    + Unary Plus Operator
    ++ Increment Operator
    -- Decrement Operator
    ! Logical Complement Operator (Only takes boolean types as operands)
    ~ Bitwise Complement Operator
    + - * / % Arithmetic Operators (+ addition, - subtraction, * multiplication, / division, % modulus)
    == Equality Operator
    < >  <=  >= Relational Operator
    &&  || Conditional Operator
    ? : Ternary Operator
    (expression)? true_statements : false_statements ;
    <<  >>  Shift Operator (Only takes integer-convertible types as operands)
    >>> Unsigned Right Shift Operator
    (Only takes integer-convertible types as operands)
    = Assignment Operator (There are 12 of them and only integer-convertible types as operands)
    =  +=  -=  *=  /=  %=  <<=  >>=  >>>=  &=  ^=  |=
    &  |  ^ Integer Bitwise Operators


    Examples
    int j = 2;
    int k = ~j; // k = -3; j = 2;
    boolean z = x != y;
    //
    byte x = 5;
    byte z = -x; // error
    byte y = (byte) -x; // correct
    short x = 200;
    short y = 400;
    short z = x + y ; // error
    short z = (short) (x + y); // correct
    //
    // The casting is necessary or an integer will be assigned to pi
    final float pi = (float) 22 / 7; 
    //