/images/art2.png

Review java - Array

Declaring an array

Both are allow

string argc[];
string[] argc;

Int array

int[] nums = new int[7];
nums[0] = 10;
Rabbit[] racers = new Rabbit[10];//10 empty rabbit array;
racers[0] = new Rabbit("B","F");

arraycopy()

System.arraycopy(nums, 0, nums, 0, nums.length);

Array vs ArrayList

  1. An array needs to know its size at the time of creation, arrayList does not.
  2. To assign an object in array you must assign it to a specific index.
  3. Array use array syntax ([]).
  4. ArrayList is parameterized. ArrayList<string>

ArrayList

ArrayList<Flower> flowerList = new ArrayList<Flower>();// <- ArrayList constructor
Flower f = new Flower();
Flower m = new Flower();

flowerList.add(f);
flowerList.add(m);

Review java - javadoc

JavaDocs

JavaDocs is able to easily generate a code “maintenance manual”

A doc comment is made up of two parts – a description and two or more tag.

/**
* Here is description
*
* @tag Comment for tag
*/

Tags

  • @author (classes and interfaces only, required)
  • @version (classes and interfaces only, required)
  • @param (methods and constructors only)
  • @return (methods only)
  • @exception
  • @see
  • @since
  • @serial (or @serialField or @serialData)
  • @deprecated

JDK Docs

External documentation can be created with javadoc

Review java - OO

Class & Object

A class only exists at compile time;

An object only exists at runtime.

Data Encapsulation

Data Encapsulation/information hiding: where the internal state and operation are hidden from others.

The more information Class A knows about Class B, the greater the possibility that changing Class A will adversely affect Class B. In an ideal world, making internal changes to Class A should have no, or very little, effect on other classes.

Review java - Variable

Basic types

Every type have a default value:

TypeRepresentationInitial valueStorageMax. value
bytesinged integer08 bits127
shortsinged integer016 bits32767
intsinged integer032 bits2147483647
longsinged integer064 bitsover 10^18
floatfloating point0.032 bitsover 10^38
doublefloating point0.064 bitsover 10^308
booleantrue or falsefalse1 bit
charUNICODE (not ASCII)u000016 bitsuFFFF

Difference between i++ and ++i

b = 1;
a = b++; // a = 1; b = 2
b = 1;
a = ++b; // a = 2; b = 2
int a = 1;
int res = a++ + a;
// res = 3 ; a = 2.
int a = 1;
int res = a + a++;
// res = 2; a = 2.
int a = 1;
int res = ++a + a;
// res = 4; a = 2.
int a = 1;
int res = a + ++a;
// res = 3; a = 2.

For loop

for(int i=0; i < n ; i++)

MarkDown overview

This is learning note for MarkDown

Heading 1

or

Heading 1

Heading 2

or

Heading 2

Italic and bold

italic or italic bold or bold italic and bold or italic and bold

Unordered list

  • line 1
  • line 2
  • line 3
    • sub 1
    • sub 2

or

  • line 1
  • line 2
  • line 3
    • sub 1
    • sub 2

Ordered list

  1. line 1
  2. line 2
    1. sub 1
    2. sub 2
  3. line 3

BlockQuotes

Use ‘>’ for a quotes

Welcome to Jekyll!

You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run jekyll serve, which launches a web server and auto-regenerates your site when a file is updated.

To add new posts, simply add a file in the _posts directory that follows the convention YYYY-MM-DD-name-of-post.ext and includes the necessary front matter. Take a look at the source for this post to get an idea about how it works.