Tuesday, April 14, 2015

Arrays

An array is a container object that holds a fixed number of values, unlike a regular variable that can only contain a single value. 

The length of an array is established when the array is created. After creation, its length is fixed. 

Each item in an array is called an element, and each element is accessed by its numerical index.
The number corresponding to each position is called an index or a subscript.
Array indexes always begin at zero. That means the value stored at index 5 is actually the sixth value in the array.

Arrays are objects. To create an array the reference to the array must be declared.
The variable height is declared to be an array of integers whose type is written as int[].

All valuables stored in an array have the same type. An example is that you can create an array that can hold integers or an array that can hold strings but not an array that can hold both integers and strings.

Another important characteristic of arrays is that their size is held in a constant called length in the array object

One way you can declare an array is by:
int[] num = new int[7];

Here is a way you can assign value to arrays:
num[0] = 10;





Friday, February 6, 2015

Head First Chapter 4

A method uses parameters. A caller passes arguments. if a mthod takes a parameter you must pass it something. Getters and setters let you get and set things. Instance variables value. A getter sends back as a return value of whatever the value it wanted to get. A setter takes an arguement value and uses it to set the value of an instance value.


You can see if two primitives are the same by using the == to compare them.



Friday, January 23, 2015

Head First Chapter 3

Variables must have a type and also must have a name. It needs a name so you can use it in the code. Variables hold primitives and references to objects. There is actually no such thing as an object variable.  There’s only an object reference variable. An object reference variable holds bits that represent away to access an object.


Friday, January 16, 2015

Head First Java Chapter 2

A class is a blueprint for an object. It tells the virtual machine how to make an object of that particular type. You need two classes to create and use a object. One class for the type of object you want to use and a tester class to test your class. The tester class is where you put your main method.
A java application is basically objects talking to other objects.

Monday, January 12, 2015

Head First Java Chapter 1


I learned that a source file holds one class definition and that it represents a piece of the program. A class has one or more methods and the methods must be declared inside a class. Method is a set of statements, their like functions or procedures. Everything goes in a class. Running a program means it tells Java Virtual Machine to load a class and start executing its main ( ) method. Also java has three standard looping constucts, while, do-while, and for.

public class BeerSong {
    public static void main(String[] args) {
        int beerNum = 99;
        String word = "bottles";
        while (beerNum > 0)
        {
            if (beerNum == 1)
            {
                word = "bottle";
            }
            System.out.println(beerNum + " " + word + " of beer on the wall");
            System.out.println(beerNum + " " + word + " of beer");
            System.out.println("Take one down.");
            System.out.println("Pass it around.");
            beerNum = beerNum - 1;
            if (beerNum > 0)
            {
                System.out.println(beerNum +  " " + word + " of beer on the wall");
            }
            else
            {
                System.out.println("No more bottles of beer on the wall");
            }
        }
    }
}



This is the beer song it works by launching the main class and it has 99 bottles of beer on the wall. The code will count all the way to 0. Wheb it gets to 1 bottle on the wall it changes bottles to bottle so it is grammercally correct. Then the code is correct and there is no more issues.