Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

JP 1 1 SG

Download as pdf or txt
Download as pdf or txt
You are on page 1of 46

Release Date: August, 2015

Updates:

This lesson is aimed at reviewing the knowledge that you should already have . If you have any difficulty
with any topic in this area, it is advisable to research some additional material before continuing.

Primitive data types are common amongst most languages. So if you have a background in another
language then you should see similar names and types here.

You will not use all of the data types, but some will be used often depending on the project.

You should always try and use the most suitable type. If you never require a fractional part in your number
then choose int or long depending on the size you require.

When dealing with chars we use single quotes, and with strings double quotes.

Remember that we should not use == to compare two strings. This tests for reference equality and not
value equality.

It is worth getting familiar with the methods available to Strings. Many are overloaded to offer different
options.
The code above would produce:
string3: How are you CaronCaron
Length: 5
Sub: How a
Upper: HOW ARE YOU CARONCARON

If we require to test the ordering of two strings then then we should use compareTo.
Lexicographical order is alphabetical ordering of your strings. These orderings are based on the ASCII value
of the characters.

10

This will only ever test for equality, not order.

11

You should explore the scanner class in more depth. You will see there are many methods for reading
different types from the console.

12

Remember that the == is the comparison check. The = is commonly typed by mistake and is used for
assignment.

13

Understanding boolean logic is fundamental to programming.

14

We can write logic statements multiple ways. It is good to use the method that best describes your goal.
E.g. testing if a student is over 16 or more we could write either (age >= 16), (age > 15), (age > (16-1))

15

Remember that the double equals(==) is the comparison operator.

16

isTrue in the second example above is a variable of type boolean.

17

Loops in java can also be exited by the use of the break statement. This will terminate the loop.
The continue statement will skip the current iteration, but not break out of the loop.

18

You dont have to use the letter i, but it is commonly used within loops.

19

Arrays will be explored throughout the course when we focus on their strengths and weaknesses.

20

It is a common convention within java to make the first letter of a class uppercase.

21

We will explore class design in java in greater detail early on in the course. You should have a basic
familiarity with its structure.

22

The default constructor is not added to code. Java will create a constructor at runtime that will set all of
the fields to their default type value.

23

Overloading constructors will be covered during this course.

24

You can overload constructors and methods within java as long as they have different parameter type
listings. The word this is used in the code this.ssn = ssn to differentiate between the class instance field
ssn and the paramater ssn. this tells Java to use the class instance field.

25

A method signature is the name of the method and its parameters.

26

Java uses the types that you pass to the parameter to determine which method to call if it is overloaded.

27

Classes dont have to have methods, but most will have them to increase their functionality.

28

It is common practice to have private fields with public accessors and mutators to set and get their values.

29

We use the optional this statement to differentiate between the class variable called name and the
parameter name.

30

Void methods tend to be mutators and non-void accessors. This isnt always the case though. You may
wish to change data, but also receive a boolean confirmation if this has happened or not.

31

If we call dog.bark("Growl"); Java realizes that we are passing a string. There is only one method of bark
that accepts a single string value, so it choses that method.

32

If you have no java main method then you cant run your software.

33

Fields are typically private and methods public, but this is not always the case.
If you do not specify the access modifier then the Default modifier is chosen.
It is not always clear what the difference between Protected and Default is. Protected allows a subclass to
have access to the method or variable where default doesnt.

34

The method of specializing a class more and more as you subclass is fundamental to the OOP paradigm.

35

A superclass is the parent and the subclass is the child.


A subclass will have access to all of the visible methods and properties defined in the superclass it is
inherited from.

36

All classes extend from other classes in java. If you do not use the keyword extends, then by default it
extends the class Object.

37

Java supports only single inheritance. That means that it can only extend one class, and not multiple
classes.

38

This means that


public myClass extends Objects

is identical to
public myClass

39

Encapsulation surrounds us. You dont have to know how a car works, but you must learn how to start and
control it. The inner workings of what happens when you push a pedal are kept from you, but you must
know its function. This is encapsulation.

40

As stated earlier we tend to make our fields private and give access to them via public methods.

41

Can you define these terms?

42

Can you define these terms?

43

These are the objectives that you should have learned in this lesson.

44

These are the objectives that you should have learned in this lesson.

45

You might also like