objects are passed as arguments to allow methods to access and manipulate data that belongs to those objects. While Java is technically always "pass-by-value," when you pass an object, you are actually passing a copy of the reference (the memory address) to that object.
throws in java
throws is a keyword in Java used in a method declaration to specify the exceptions that the method may throw, allowing the caller to handle those exceptions. The caller to these methods has to handle the exception using a try-catch block.
- Declares possible exceptions.
- Mainly used with checked exceptions.
Scanner class methods in java
Scanner class is used for get data from the user using console.
*the package *
import java.util.Scanner;
creating scanner class object
Scanner sc = new Scanner(System.in);
- Scanner → Class name
- sc → Object name
- System.in → Standard input stream (keyboard)
scanner class have different methods for taking data in different data type.
-
boolean =>
nextBoolean() -
byte =>
nextByte() -
double =>
nextDouble() -
float =>
nextFloat() -
int =>
nextInt() -
long =>
nextLong() -
short =>
nextShort() -
String =>
nextLine()
Top comments (0)