Docsity

Common Errors, Java Doc - Web Design and Development - Lecture Slides, Slides of Web Design and Development

Partial preview of the text

Download Common Errors, Java Doc - Web Design and Development - Lecture Slides and more Slides Web Design and Development in PDF only on Docsity!

Web Design & Development

Lecture 5

Common Errors

Error: Exception in thread “main”

NoClassDefFoundError

public class CommonErrors{

public static void main (String args[]) {

System.out.println(“Hello World”);

Error: Exception in thread “main”

NoSuchMethodError: main

public class CommonErrors{ public static void display () { System.out.println(“hello world”); }

public static void main (String args[]) { CommonErrors.display(); }

Error: Local variable not initialized

public class CommonErrors{
public static void main (String args[]) {
int number ;
System.out.println(number);

Error: ArrayIndexOutofBoundsException

public class CommonErrors{

public static void main (String args[]) {

System.out.println(args[0]);

Error: NullPointerException

public class CommonErrors{
public static void main (String args[ ]) {
Student s = null;
s.print( );

How to Use Java Doc

More OOP

Inheritance

Employee. java (super class)

public class Employee{ protected int id; protected String name;

//parameterized constructor public Employee(int id, String name){

this.id = id; this.name = name; }

//default constructor public Employee(){ this (10, “not set”); }

//continue

Employee. java (super class)

public void setId (int id) { this.id = id; }

public int getId () { return id; }

public void setName (String name) { this.name = name; }

public String getName () { return name; }

//continue ….

Teacher. java (sub class)

public class Teacher extends Employee{

private String qual;

//default constructor public Teacher () { //implicit call to superclass default construct qual = ""; }

//parameterized constructor public Teacher(int i, String n, String q){

super(i,n); //call to superclass const must be first line qual = q; } //continue

Teacher. java (sub class)

//accessors for qual

public void setQual (String qual){ this.qual = qual; }

public String getQual(){ return qual; }

//continue