Java Programming

 

     

 

Monday, April 27th

 

Refer to the Canvas Module for this assignment
Introduction to Error Handling
Types of Errors - syntax, logic, exceptions (runtime errors)
Unchecked and Checked exceptions - you MUST handle....
What to do when exceptions are thrown - catch them
try{ this part of the program might throw an exception }
catch (exception e){
this code will execute if the code in the try block throws an exception.
this code will handle the exception }

finally {

Common exceptions - also note the exceptions heirachy - exceptions are objects and are subclasses of the Throwable class. Two useful methods are getMessage() and printStackTrace();

  1. public class Testtrycatch2{  
  2.   public static void main(String args[]){  
  3.    try{  
  4.       int data=50/0;  
  5.    }catch(ArithmeticException e){System.out.println(e);}  
  6.    System.out.println("rest of the code...");  
  7. }  
  8. }  

Sample use of mutliple catch statements:

public class TestMultipleCatchBlock{
public static void main(String args[]){
try{
int a[]=new int[5];
a[5]=30/0;
}
catch(ArithmeticException e){System.out.println("task1 is completed");}
catch(ArrayIndexOutOfBoundsException e){System.out.println("task 2 completed");}
catch(Exception e){System.out.println("common task completed");}

System.out.println("rest of the code...");
}
}

Section 6 Lesson 2: Handling Errors Vocabulary:
- A keyword in Java that signals the following block of code handles a specified exception.
- An exception that is optional to be handled.
- An exception that MUST be handled.
- Indicates that there is a problem with interpreting your program.
- This stops the interpreter from running the rest of the code until it finds a catch.
- An error that indicates an issue with coding format.
- An error that occurs while the program is running, also known as an exception.
- An error that occurs as a result of incorrect programmer logic.
- A block of code that handles exceptions by dealing with the exception if it is thrown.
- Errors that occur during run-time and can be corrected or handled by your code.

Read Section 6 Lesson 2: Handling Errors slides
Complete Section 6 Lesson 2: Handling Errors questions 1-5.
Complete the Error Handling program and demonstrate for teacher check. 


Complete 6-2 Project - this is a continuation of Project 5-2. Be sure to read the instructions because you are not meant to start this project from scratch, you start with Project 5-2 and save it as ProductPart3 and ProductTesterPart3 and then make additions to your current code according to the instructions.

Section 7 Lesson 1: Classes, Objects and Methods Vocabulary:

- A template used for making Java objects.
- An optional keyword used to access the members and methods of a class.
- An instance of a class.
- The operator used to create an instance of a class.
- A built-in function of the Java VM that frees memory as objects are no longer needed or referenced.
- A method that changes the state of an object.
- A method that returns information about an object back to the calling program.
- A procedure (changes the state of an object) or function (returns information about an object) that is encapsulated as part of a class.
- A verb used to describe the act of creating a class object using the keyword new.
- The process of assigning a default value to a variable. An object reference that has not been instantiated.
- An object reference that has not been instantiated.
- An optional method that is called just before an object is removed by the garbage collector.
- The name of a variable that is associated with an object.
- A special method used to create an instance of a class.

 

Homework

Install Eclipse on your home computer if you would like to be able to work on your java at home.

 

What

In this lesson, you will learn how to:
•Recognize the correct general form of a class
• Create an object of a class
• Describe object references
• Create methods that compile with no errors
• Return a value from a method
• Use parameters in a method

 

Why

Class templates are the foundation of the Java language. Understanding how to create a class with various methods will be essential to becoming a good Java programmer. Knowing how to instantiate an object and compare it to other objects is critical to learning to use and work with Java data types.

 

How

By completing the slides, quiz and practice exercises.