Mobile Development Workshop JAVA REFRESHER Overview Programming - - PowerPoint PPT Presentation

mobile development workshop
SMART_READER_LITE
LIVE PREVIEW

Mobile Development Workshop JAVA REFRESHER Overview Programming - - PowerPoint PPT Presentation

Mobile Development Workshop JAVA REFRESHER Overview Programming languages Object Oriented Programming with Java First up Create a new project in Netbeans Call it Bank Running a Program Programming Languages High-level languages are


slide-1
SLIDE 1

Mobile Development Workshop

JAVA REFRESHER

slide-2
SLIDE 2

Overview

Programming languages Object Oriented Programming with Java

slide-3
SLIDE 3

First up…

Create a new project in Netbeans

  • Call it Bank
slide-4
SLIDE 4

Running a Program

slide-5
SLIDE 5

Programming Languages

High-level languages are relatively easy to use

  • Java, C#, C++, Visual Basic, Python, Ruby.

Unfortunately, computer hardware does not understand high-level languages.

  • Therefore, a high-level language program must be translated into a low-level

language.

slide-6
SLIDE 6

Java Byte-Code

The Java compiler does not translate a Java program into assembly language or machine language for a particular computer. Instead, it translates a Java program into byte-code.

  • Byte-code is the machine language for a hypothetical computer (or interpreter) called the Java Virtual

Machine.

slide-7
SLIDE 7

The Java Language

Java is an Object Oriented Language

  • Everything is represented as an object

Objects can have data and actions Data is stored in variables Actions are defined in methods

slide-8
SLIDE 8

OOP Terminology

Objects of the same kind have the same type and belong to the same class.

  • Objects within a class have a common set of methods and the same kinds of

data

  • but each object can have it’s own data values.
slide-9
SLIDE 9

Introduction to Encapsulation

The data and methods associated with any particular class are encapsulated (“put together in a capsule”), but only part of the contents is made accessible.

  • Encapsulation provides a means of using the class, but it omits the details of

how the class works.

  • Encapsulation often is called information hiding.
slide-10
SLIDE 10

Example

An automobile consists of several parts and pieces and is capable of doing many useful things.

  • Awareness of the accelerator pedal, the brake pedal, and the steering wheel is

important to the driver.

  • Awareness of the fuel injectors, the automatic braking control system, and the

power steering pump is not important to the driver.

slide-11
SLIDE 11

Back to your program…

Create a new class called BankAccount Give it the following properties

  • String ownerName
  • double balance

Give it a constructor that takes an ownerName and starting balance to set up the object Project a getter and setter for the ownerName property

slide-12
SLIDE 12

Back to your program…

Create two new methods

  • deposit(double) – this will increase the balance of the account
  • withdraw() – this will reduce the balance of the account
slide-13
SLIDE 13

Introduction to Inheritance

Classes can be organized using inheritance. A class at lower levels inherits all the characteristics of classes above it in the hierarchy. At each level, classifications become more specialized by adding other characteristics. Higher classes are more inclusive; lower classes are less inclusive.

slide-14
SLIDE 14

Introduction to Inheritance

slide-15
SLIDE 15

Back to your program…

Create two new calsses

  • CheckingAccount
  • SavingsAccount

Both classes should inherit from the BankAccount class

slide-16
SLIDE 16

Flow of Control

Flow of control is the order in which a program performs actions. A branching statement chooses between two or more possible actions. A loop statement repeats an action until a stopping condition occurs.

slide-17
SLIDE 17

The if-else Statement

A branching statement that chooses between two possible actions. Syntax

if (Boolean_Expression) Statement_1 else Statement_2

slide-18
SLIDE 18

Semantics of the if-else Statement

slide-19
SLIDE 19

Back to your program…

In the BankAccount class

  • Prevent the deposit method in the BankAccount class from accepting a deposit amount less than or

equal to zero

  • Prevent the withdrawal method from leaving a negative balance
slide-20
SLIDE 20

Overriding a method

When a subclass functionality from a base class, it can discard the functionality it doesn’t want by overriding the previous implementation The older version is still there, and can be accessed using the super keyword

slide-21
SLIDE 21

Back to your program

Override the withdraw() method in your CheckingAccount class to allow overdrafts up to $100

slide-22
SLIDE 22

Compound Boolean Expressions

Boolean expressions can be combined using the "and" (&&)

  • perator.

Example

if ((score > 0) && (score <= 100)) ...

Not allowed

if (0 < score <= 100)

slide-23
SLIDE 23

Java Logical Operators