0% found this document useful (0 votes)
38 views3 pages

Java Notes

The document outlines key concepts in Java programming, including identifiers, local variables, constructors, and method overriding rules. It also presents assignments for practice, such as calculating averages and working with arrays, along with a task to develop an ATM withdrawal system that incorporates exception handling. The document specifies requirements for exception handling and program behavior during withdrawals, including appropriate error messages for insufficient funds and invalid amounts.

Uploaded by

cudummymail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views3 pages

Java Notes

The document outlines key concepts in Java programming, including identifiers, local variables, constructors, and method overriding rules. It also presents assignments for practice, such as calculating averages and working with arrays, along with a task to develop an ATM withdrawal system that incorporates exception handling. The document specifies requirements for exception handling and program behavior during withdrawals, including appropriate error messages for insufficient funds and invalid amounts.

Uploaded by

cudummymail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Tuesday, 28 January 2025

JAVA

Identifiers
- All alphanumeric characters are allowed from A-Z and 0-9 and there are two
symbols that are allowed $, _
- Identi ers should not start with digits.
- Local Variable : Local variables are those variable that are declared inside a
method.
- Assignment 1: WAP to take three numbers from user and perform the average of
those numbers and print the average.
- Assignment 2: WAP in which an array of 5 size is taken as input from the user and
then store the array and then display it.
- Objects consist of four things : state, behaviour,
- Constructor : no return type, same name as class, used to initialise the object, it
is called by itself when object is created
- Qn) You have a class Main having two instance variables name and age, you have
to create a parameterised constructor having parameters name and age and
create a method in this class named display where name and age will be
displayed
- Qn) WAP using inheritance where a person class with name and age, is extended
by student having variable “grade” and teacher has a variable “subject” and a
method display_details in person class used by teacher and student class, text
the functionality in main method.

Rules for Method Overriding (11/02/25)

1) Method name must be same

2) Same parameters

3) Access modi er restrictions : the access modi er of the overriding method must
be same or less restrictive than the access modi er of the override method in the
superclass.

4) Same return type or co-variant return type.

1
fi
fi
fi
fi
5) When you are working with method overriding you can’t work with static
keyword.

25/02/25
Throw :
- In Java throw keyword is used to throw an exception explicitly.
- We de ne throw exception inside a method.
- We can only propagate check and uncheck exceptions
- “throws” keyword can be used to propagate check exception only.
- We are allowed to throw only one exception at a time but, in “throws” you can
de ne multiple exceptions at a time.
- Java “throws” keyword is used to declare an exception and with “throws”
keyword we can declare checked exceptions only

You are tasked with developing a basic ATM withdrawal system using java
exception handling (throw, throws and try-catch)

Requirements:

Account balance management : The system should allow the user to enter an initial
bank account balance.

The user should be able to withdraw money from their account.

Exception handling Rules :

If the withdrawal amount is greater than the balance, throw an ArithmeticException


with the message : “Insu cient balance, your balance is only <balance>”

If the withdrawal amount is zero or negative, throw an IllegalArgumentException


with the message : “Invalid withdrawal amount ! Please enter a positive number”

Program behaviour :

Us try-catch to handle exceptions, if an exception occurs display an appropriate


message but continue the program execution normally.

If the withdrawal is successful, display the remaining balance.

2
fi
fi
ffi
18/03/25

You might also like