GasInTank

instance variable stay long, but local variable only stay short term.

public class CarTester
{
    public static void main(String[] args)
    {
        Car car = new Car();

        // TODO: Add 20 gallons and drive 100 miles
        car.addGas(20);
        car.drive(100);
        
        // TODO: Print actual and expected gas level
        System.out.println("Expected:18");
        System.out.println(car.getGasInTank());
    }
}
public class Car
{
    private double milesDriven;
    private double gasInTank;
    private double milesPerGallon;

    public Car()
    {
        milesDriven = 0;
        gasInTank = 0;
        milesPerGallon = 50;
    }

    /**
       Drives this car by a given distance.
       @param distance the distance to drive
    */
    public void drive(double distance)
    {
        milesDriven = milesDriven + distance;
        double gasConsumed = distance / milesPerGallon;
        gasInTank = gasInTank - gasConsumed;
    }

    public void addGas(double amount)
    {
        gasInTank = gasInTank + amount;
    }
    
    /**
       Gets the current mileage of this car.
       @return the total number of miles driven
    */
    public double getMilesDriven()
    {
        return milesDriven;
    }

    /**
       Gets the current amount of gas in the tank of this car.
       @return the current gas level
    */
    public double getGasInTank()
    {
        return gasInTank;
    }
}

test programming

public class test
{
    public static void main(String[] args)
    {
      Rectangle box = new Rectangle(45, 90, 60, 90);
      box.grow(20, 20);
      system.out.println(box.getX());
      system.out.println("exected: 25");
      system.out.println(box.getY());
      system.out.println("exected: 70");
    }
}
Rectangle frontFace = new Rectangle(20, 30 ,100, 40);
        Line leftLine = new Line(20, 30, 50, 10);
        Line topLine = new Line(50, 10, 150, 10);
        Line middleLine = new Line(120, 30, 150, 10);
        Line rightLine = new Line(150, 10, 150, 50);
        Line bottomLine = new Line(120, 70, 150, 50);

        frontFace.draw();
        leftLine.draw();
        topLine.draw();
        middleLine.draw();
        rightLine.draw();
        bottomLine.draw();
      box.setColor(new Color(255, 0, 0));
      box.draw();
      box2.setColor(new Color(0, 255, 0));
      box2.fill()

Object oriented programming

java put name before the variable name.

public class test
{
    public static void main(String[] args)
    {
        Picture rocket = new Picture("mariner4.jpg");
        rocket.translate(200, 200);
        rocket.draw();
        Picture planet = new Picture("mars.gif");
        planet.grow(-50, -50);
        planet.draw();
    }
}
public class test
{
    public static void main(String[] args)
    {
        Day birthday = new Day(1951, 5, 26);
        Day lastDay = new Day(2012, 5, 26);
        int daysAlive = lastDay.daysFrom(birthday);
        System.out.println(daysAlive);
    }
}

variable can vary and assignment has no type.

int numberOfPixels = object.methodname(arguments)

public class test
{
    public static void main(String[] args)
    {
        Rectangle box = new Rectangle(60, 90, 20, 30);
        Rectangle box2 = new Rectangle(80, 120, 20, 30);
        box.draw();
        box2.draw();
    }
}
public class test
{
    public static void main(String[] args)
    {
        String river = "Mississippi";
        int numberOfLetters = river.length();
        System.out.println(numberOfLetters);
    }
}

replace method

public class test
{
    public static void main(String[] args)
    {
        String river = "Mississippi";
        String result = river.replaceAll("i","x");
        System.out.println(result);
    }
}

cut space with trim()

String messyString = "Hello, Space!";
        messyString.trim()

AccessorとMutator:「Accessor=アクセスするヤツ」、「Mutator=mutate(訳すと変化させる)」
An accessor method is used to return the value of a private field.
A mutator method is used to set a value of a private field. It follows a naming scheme prefixing the word “set” to the start of the method name.

Implement test program, set actual result and expected result.

Test program

public class test
{
    public static void main(String[] args)
    {
        System.out.println("Hello\nWorld!");
    }
}

print and println

public class test
{
    public static void main(String[] args)
    {
        System.out.print(3);
        System.out.println(4 + 5);
    }
}

compile error

public class test
{
    public static void main(String[] args)
    {
        System.ouch.println(4 + 5);
    }
}

Hadoop

The reason to use big data is it’s too big to store in one machine.Challenges with big data is data is created fast and data from different source in various formats.

Hadoop
Store in HDFS
process with MAPREDUCE

Hadoop ecosystem
pig, hive … select * from
mapreduce, impala, hbase
HDFS <- sqoop, flume Hue, oozie, mahout Cloudera is a distribution of Hadoop(CDH) Hadoop picks three node as random.

jasmine

javascript test library
https://jasmine.github.io/

describe('Address Book', function(){
  it('should be able to add a contact', function(){
    var addressBook = new AddressBook(),
    thisContact = new Contact();

    addressBook.addContact(thisContact);

    expect(addressBook.getContact(0)).toBe(thisContact);
  });
});
describe('Address Book', function(){
  it('should be able to add a contact', function(){
    var addressBook = new AddressBook(),
    thisContact = new Contact();

    addressBook.addContact(thisContact);

    expect(addressBook.getContact(0)).toBe(thisContact);
  });

  it('should be able to delete a contact', function(){
    var addressBook = new AddressBook(),
    thisContact = new Contact();

    addressBook.addContact(thisContact);
    addressBook.deleteContact(0);

    expect(addressBook.getContact(0)).not.toBeDefine();
  });
});

grunt file

/*
 After you have changed the settings at "Your code goes here",
 run this with one of these options:
  "grunt" alone creates a new, completed images directory
  "grunt clean" removes the images directory
  "grunt responsive_images" re-processes images without removing the old ones
*/

module.exports = function(grunt) {

  grunt.initConfig({
    responsive_images: {
      dev: {
        options: {
          engine: 'im',
          sizes: [{
            /*
            Change these:
            
            width: ,
            suffix: ,
            quality:
            */
          }]
        },

        /*
        You don't need to change this part if you don't change
        the directory structure.
        */
        files: [{
          expand: true,
          src: ['*.{gif,jpg,png}'],
          cwd: 'images_src/',
          dest: 'images/'
        }]
      }
    },

    /* Clear out the images directory if it exists */
    clean: {
      dev: {
        src: ['images'],
      },
    },

    /* Generate the images directory if it is missing */
    mkdir: {
      dev: {
        options: {
          create: ['images']
        },
      },
    },

    /* Copy the "fixed" images that don't go through processing into the images/directory */
    copy: {
      dev: {
        files: [{
          expand: true,
          src: 'images_src/fixed/*.{gif,jpg,png}',
          dest: 'images/'
        }]
      },
    },
  });
  
  grunt.loadNpmTasks('grunt-responsive-images');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-mkdir');
  grunt.registerTask('default', ['clean', 'mkdir', 'copy', 'responsive_images']);

};

https://unicode-table.com/en/

compression level

watch out image compression level and natural width.
should be less pixels.

Total bits = pixel x bit per pixel

    body {
      margin: 0;
    }
    img {
      float: left;
      margin-right: 10px;
      width: calc((100% - 20px)/3);
    }
img:last-of-type {
	margin-right: 0;
	}

Vector scales without quality degradation.

$0.naturalWidth
601
$0.naturalWidth
1202

The process of DOM

Characters -> Tokens -> Nodes -> DOM

Request page -> GET html -> page head(build DOM, render) -> search result(build DOM, render)

Characters -> Tokens -> Nodes -> CSSOM
hi tag is faster evaluation than div p tag as dom tree.

JavaScript is parser blocking

Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed for use with Node.js and installable via npm install –save async, it can also be used directly in the browser.

first canvas

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<canvas id="my_canvas"></canvas>
</body>
<script>
	var canvas = null;
	var context = null;

	setup = function(){

	canvas = document.getElementById("my_canvas");
	context = canvas.getContext('2d');
	canvas.width = 1200;
	canvas.height = 720;
	};
</script>
</html>