Commit 88aa0dee authored by michael lundquist's avatar michael lundquist
Browse files

Changing this folder to just contain notes.

# ch1 Java primer
## 1.1 Getting Started
- The book describes writing hello world, java key words...
- __method__: executible statements inside java functions
- __class__
- __block__: code contained with braces ("{" and"}")
- __identifier__: the name of a class, method or variable.
- Syntax:
- begins with letter
- contains only letters, numbers, and underscore characters
- can't be a keyword
#### Comments
- single line comments begin with `//`
- multi line comments are surrounded by `/*` and `*/`
- multi-line comments that begin with `/**` are Javadoc comments that can automatically generate documentation (see 1.9.4)
### 1.1.1 Base Types
- __base types__: data types that variables can store the actual value of.
- aka *primitive types*
- the base types are:
- _boolean_: A boolean value: true or false
- must be true or false: `boolean flag = true;`
- _char_: 16-bit Unicode character
- surrounded with single quotes: `char grade = 'A'`
- _byte_: 8-bit signed two's complement integer
- an integer number from -128 to 127 `byte b = 12;`
- _short_: 16-bit signed two's complement integer
- an integer number from -32,768 to 32,797 `short s = 24`
- _int_: 32-bit signed two's complement integer
- an integer number from -2,147,483,648 to 2,147,483,647 `int i = 257;`
- _long_: 64_bit signed two's complements integer
- an integer number from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,80 that must be followed by `l` or `L` `long lo = 890L;`
- _float_: 32-bit floating-point number (IEEE 754-1985)
- 4 bytes, 7 decimal digits. Must be followed by `f` or `F` `float pi = 3.1416F;`
- _double_: 64-bit floating-point number (IEEE 754-1985)
- 8 bytes, 16 decimal digits `double e = 2.72342;`
- In java, uninitalized base types variables are assigned a default value. By default:
- numeric types are `0`
- boolean types are `false`
- character types are `null`
- You can declare (and initialize) multiple variables simultaneously:
- `int i = 5, k = 257, j;`
- in this example j is set to the default int value of 0
## 1.2 Classes and Objects
- _Objects_ are _instances_ of a _class_. Objects are of the class's _type_ and have all the *member* variables (aka instance variables or fields) and methods of the class.
- *accessor methods*: return information to the caller from an object without changing information in the object.
- *update method*: changes one or more object instance variable when called.
### 1.2.1 Creating and Using Objects
- Classes are aka *reference types*
- variables that store objects are aka *reference variable*
- reference variables store the location (*memory address*) of an object from the declared class or *null* if they don't point to anything.
- new objects are created by calling *new*, then calling a constructor
- constructors are member methods with the same name as the class
- the default constructor has no parameters
- the new operator returns a reference to a new object
- Steps that happen when a new class instance is created:
1. a new object is dynamically allocated in memory along and assigns default values to instance variables.
2. The constructor is called, assigning meaningful values to instance variables, and performing additional computations
3. The *new* operator returns a reference to the new object.
#### The Dot Operator
- Object's members are accessed with the format `variableName`.`memberName`
- remember, members can be methods or variables
- if you try to access members of a `null` object, you get a `NullPointerException`
- Java support __method overloading__.
- Method Overloading is a feature that allows a class to have more than one method having the same name, if their argument lists (*signature*) are different. It is similar to constructor overloading in Java, that allows a class to have more than one constructor having different argument lists.
- note the signature includes method name and parameter types but not the return type
- Many references to an object can exist, but if any of the references call an update method, the underlying data (that all references refer to) is changed so future references to that data from any of the references will be different.
- you can reassign a reference variable to any object of the same reference type or to `null`.
### 1.2.2 Defining a Class
- classes are defined inside code blocks. Inside the block, instance variables and methods are defined.
#### Modifiers
- __modifiers__ can add stipulations to class, instance variable, or method definitions.
##### Access Control Modifiers
- __Access control modifiers__: control the level of access (aka *visibility*) the defining class grants to other classes.
- __public__: all classes may access this member using dot notation
- in java, public (non inner) classes must be defined in their own file whose file name matches the class name.
- __Protected__: access is only granted to *subclasses* of the class and other classes in the same *package*
- __subclasses__: classes that inherit from a class (see 2.2)
- __package__ (see 1.8)
- __Private__: access is restricted to the class level.
- If access control isn't specified, __package-private__ is the default, meaning members can be accessed inside, but not outside the package (even by subclasses)
- Access control is the basis of encapsulation
##### The __Static__ Modifier
- The __static method__ says that all objects refer to one class member instead of having their own object members for this member.
- To access static members, use dot notation with the name of the class instead of an object's name.
##### The __abstract__ Modifier
- Abstract classes can provide abstract methods that subclasses must implement.
- see 2.3.3
- Java will not allow any instances of an abstract class to be constructed, although reference variables may be declared with an abstract type.
##### The __final__ Modifier
- variables initialized with the final varaible can't be reassigned.
- final reference variables always refer to the same object
- final variables are typically static
- final methods can't be overridden by subclasses
#### Declaring Instance Variables
- Objects have their own instance variables
- instance variable declaration syntax:
- [*modifiers*] *type* *identifier1* [*=initialValue1*], *identifier2* [*= initialValue2*];
#### Declaring Methods
\ No newline at end of file
# Class notes 1.22.19
- Intros
- programming:
- code reuse
- guide lines
- Need to get text books on the syllabus
- Input and outputs in files
- IPO charts
- junit for group project?
- see the project section also
- we don't have to use UML for the assignments, just the code.
## module 2 methods
- steps in modularization
## module 3 Arrays
- Java doesn't allow pass by reference for primitives
## Module 3 Objects
- UML class diagrams
- minus sign for private, + for public
- *{final}* is a thing too
- constructors us <<constructor>>
- [erd software](
- [UML software](
- ask about this
## Module 7 Abstract classes
- interfaces:
- all methods must be public
## Assignment
- Don't change
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment