Posts

Showing posts from May, 2024

Exception Handling in Java

 Exception handling Exception handling in Java is a powerful mechanism that allows you to handle runtime errors, ensuring the smooth flow of the application. It enables a program to catch and handle exceptions gracefully, avoiding abrupt termination and providing meaningful feedback. Here's a detailed explanation of exception handling in Java: There are two types of exception 1) System defined 2) User defined System defined exceptions:- In Java, system-defined exceptions are exceptions provided by the Java standard library. These exceptions are part of the java.lang package and are derived from the Throwable class. They can be broadly categorized into two types: checked exceptions and unchecked exceptions. 1. Checked Exceptions Checked exceptions are exceptions that must be either caught or declared in the method signature using the throws keyword. They are checked at compile-time. 2.Unchecked Exceptions Unchecked exceptions are not checked at compile-time. They are checked at runt...

Data types in Java

In Java, data types are classified into two main categories: primitive data types and reference data types.  Primitive Data Types Primitive data types are the most basic data types available in Java. They are predefined by the language and named by a reserved keyword. Java has eight primitive data types: byte Description: 8-bit signed integer. Range: -128 to 127. Example:- byte b = 100; System.out.println("Byte value: " + b); short Description: 16-bit signed integer. Range: -32,768 to 32,767. Example: short s = 10000; System.out.println("Short value: " + s); int Description: 32-bit signed integer. Range: -2^31 to 2^31 - 1. Example: int i = 100000; System.out.println("Int value: " + i); long Description: 64-bit signed integer. Range: -2^63 to 2^63 - 1. Example: long l = 10000000000L; System.out.println("Long value: " + l); float Description: 32-bit floating-point number. Range: Approximately ±3.40282347E+38F (6-7 significant decimal digits). Examp...