mobile development workshop
play

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


  1. Mobile Development Workshop JAVA REFRESHER

  2. Overview Programming languages Object Oriented Programming with Java

  3. First up… Create a new project in Netbeans ◦ Call it Bank

  4. Running a Program

  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.

  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.

  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

  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.

  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.

  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.

  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

  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

  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.

  14. Introduction to Inheritance

  15. Back to your program… Create two new calsses ◦ CheckingAccount ◦ SavingsAccount Both classes should inherit from the BankAccount class

  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.

  17. The if-else Statement A branching statement that chooses between two possible actions. Syntax if (Boolean_Expression) Statement_1 else Statement_2

  18. Semantics of the if-else Statement

  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

  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

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

  22. Compound Boolean Expressions Boolean expressions can be combined using the "and" (&&) operator. Example if ((score > 0) && (score <= 100)) ... Not allowed if (0 < score <= 100)

  23. Java Logical Operators

Recommend


More recommend