Exception: When an error occurs within a method, the method creates an object and hands it off to the runtime system. The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the runtime system is called throwing an exception.

Types of Exception in Java with Examples

Built-in exceptions are the exceptions which are available in Java libraries. These exceptions are suitable to explain certain error situations. Below is the list of important built-in exceptions in Java. 
 

  1. ArithmeticException 
    It is thrown when an exceptional condition has occurred in an arithmetic operation.
  2. ArrayIndexOutOfBoundsException 
    It is thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array.
  3. ClassNotFoundException 
    This Exception is raised when we try to access a class whose definition is not found
  4. FileNotFoundException 
    This Exception is raised when a file is not accessible or does not open.
  5. IOException 
    It is thrown when an input-output operation failed or interrupted
  6. InterruptedException 
    It is thrown when a thread is waiting , sleeping , or doing some processing , and it is interrupted.
  7. NoSuchFieldException 
    It is thrown when a class does not contain the field (or variable) specified
  8. NoSuchMethodException 
    It is thrown when accessing a method which is not found.
  9. NullPointerException 
    This exception is raised when referring to the members of a null object. Null represents nothing
  10. NumberFormatException 
    This exception is raised when a method could not convert a string into a numeric format.
  11. RuntimeException 
    This represents any exception which occurs during runtime.
  12. StringIndexOutOfBoundsException 
    It is thrown by String class methods to indicate that an index is either negative or greater than the size of the string

Exception handling

Exception handling ensures that the flow of the program doesn’t break when an exception occurs. For example, if a program has bunch of statements and an exception occurs mid way after executing certain statements then the statements after the exception will not execute and the program will terminate abruptly.

class Main {
  public static void main(String[] args) {

    try {

      // code that generate exception
      int divideByZero = 5 / 0;
      System.out.println("Rest of code in try block");
    }
    
    catch (ArithmeticException e) {
      System.out.println("ArithmeticException => " + e.getMessage());
    }
  }
}

Output

ArithmeticException => / by zero

 Polymorphism: Polymorphism is considered one of the important features of Object-Oriented Programming. Polymorphism allows us to perform a single action in different ways. In other words, polymorphism allows you to define one interface and have multiple implementations. The word “poly” means many and “morphs” means forms, So it means many forms.

A person at the same time can have different characteristic. Like a man at the same time is a father, a husband, an employee. So the same person posses different behavior in different situations. This is called polymorphism.

Polymorphism in java programming

In Java polymorphism is mainly divided into two types:

  • Compile time Polymorphism
  • Runtime Polymorphism

1. Compile-time polymorphism: It is also known as static polymorphism. This type of polymorphism is achieved by function overloading or operator overloading. But Java doesn’t support the Operator Overloading.

Method Overloading: When there are multiple functions with same name but different parameters then these functions are said to be overloaded. Functions can be overloaded by change in number of arguments or/and change in type of arguments.

2. Runtime Polymorphism: It is also known as Dynamic Method Dispatch. It is a process in which a function call to the overridden method is resolved at Runtime. This type of polymorphism is achieved by Method Overriding.

Method Overriding , on the other hand, occurs when a derived class has a definition for one of the member functions of the base class. That base function is said to be overridden

 In Java, the final keyword is used to denote constants. It can be used with variables, methods, and classes.

Once any entity (variable, method or class) is declared final it can be assigned only once. That is,

  • the final variable cannot be reinitialized with another value
  • the final method cannot be overridden
  • the final class cannot be extended

1. Java final Variable

In Java, we cannot change the value of a final variable. For example,

class Main {
  public static void main(String[] args) {

    // create a final variable
    final int AGE = 32;

    // try to change the final variable
    AGE = 45;
    System.out.println("Age: " + AGE);
  }
}

In the above program, we have created a final variable named age. And we have tried to change the value of the final variable.

When we run the program, we will get a compilation error with the following message.

cannot assign a value to final variable AGE
    AGE = 45;
    ^

 The prime reason behind creation of Java was to bring portability and security feature into a computer language. Beside these two major features, there were many other features that played an important role in moulding out the final form of this outstanding language. Those features are :

1) Simple

Java is easy to learn and its syntax is quite simple, clean and easy to understand.The confusing and ambiguous concepts of C++ are either left out in Java or they have been re-implemented in a cleaner way.

Eg : Pointers and Operator Overloading are not there in java but were an important part of C++.

2) Object Oriented

In java, everything is an object which has some data and behaviour. Java can be easily extended as it is based on Object Model. Following are some basic concept of OOP's.

  1. Object

  2. Class

  3. Inheritance

  4. Polymorphism

  5. Abstraction

  6. Encapsulation

3) Robust

Java makes an effort to eliminate error prone codes by emphasizing mainly on compile time error checking and runtime checking. But the main areas which Java improved were Memory Management and mishandled Exceptions by introducing automatic Garbage Collector and Exception Handling.

4) Platform Independent

Unlike other programming languages such as C, C++ etc which are compiled into platform specific machines. Java is guaranteed to be write-once, run-anywhere language.

On compilation Java program is compiled into bytecode. This bytecode is platform independent and can be run on any machine, plus this bytecode format also provide security. Any machine with Java Runtime Environment can run Java Programs.

Java is platform Independent Language

5) Secure

When it comes to security, Java is always the first choice. With java secure features it enable us to develop virus free, temper free system. Java program always runs in Java runtime environment with almost null interaction with system OS, hence it is more secure.

6) Multi Threading

Java multithreading feature makes it possible to write program that can do many tasks simultaneously. Benefit of multithreading is that it utilizes same memory and other resources to execute multiple threads at the same time, like While typing, grammatical errors are checked along.

7) Architectural Neutral

Compiler generates bytecodes, which have nothing to do with a particular computer architecture, hence a Java program is easy to intrepret on any machine.

8) Portable

Java Byte code can be carried to any platform. No implementation dependent features. Everything related to storage is predefined, example: size of primitive data types

9) High Performance

Java is an interpreted language, so it will never be as fast as a compiled language like C or C++. But, Java enables high performance with the use of just-in-time compiler.

10) Distributed

Java is also a distributed language. Programs can be designed to run on computer networks. Java has a special class library for communicating using TCP/IP protocols. Creating network connections is very much easy in Java as compared to C/C++.

New Features of JAVA 8

Below mentioned are some of the core upgrades done as a part of Java 8 release. Just go through them quickly, we will explore them in details later.

  • Enhanced Productivity by providing Optional Classes feature, Lamda Expressions, Streams etc.

  • Ease of Use

  • Improved Polyglot programming. A Polyglot is a program or script, written in a form which is valid in multiple programming languages and it performs the same operations in multiple programming languages. So Java now supports such type of programming technique.

  • Improved Security and performance.

New Features of JAVA 11

Java 11 is a recommended LTS version of Java that includes various important features. These features includes new and upgrades in existing topic. Just go through them quickly, we will explore them in details later.

  • includes support for Unicode 10.0.0

  • The HTTP Client has been standarized

  • Lazy Allocation of Compiler Threads

  • Updated Locale Data to Unicode CLDR v33

  • JEP 331 Low-Overhead Heap Profiling

  • JEP 181 Nest-Based Access Control

  • Added Brainpool EC Support (RFC 5639)

  • Enhanced KeyStore Mechanisms

  • JEP 332 Transport Layer Security (TLS) 1.3

  • JEP 330 Launch Single-File Source-Code Programs

 Data Types in Java

Data types specify the different sizes and values that can be stored in the variable. There are two types of data types in Java:

  1. Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float and double.

  2. Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays.

Java Primitive Data Types

There are 8 types of primitive data types:

  • boolean data type

  • byte data type

  • char data type

  • short data type

  • int data type

  • long data type

  • float data type

  • double data type

Java Data Types

Data Type

Default Value

Default size

boolean

false

1 bit

char

'\u0000'

2 byte

byte

0

1 byte

short

0

2 byte

int

0

4 byte

long

0L

8 byte

float

0.0f

4 byte

double

0.0d

8 byte

Boolean Data Type

The Boolean data type is used to store only two possible values: true and false. This data type is used for simple flags that track true/false conditions.

The Boolean data type specifies one bit of information, but its "size" can't be defined precisely.

Example: Boolean one = false

Byte Data Type

The byte data type is an example of primitive data type. It isan 8-bit signed two's complement integer. Its value-range lies between -128 to 127 (inclusive). Its minimum value is -128 and maximum value is 127. Its default value is 0.

The byte data type is used to save memory in large arrays where the memory savings is most required. It saves space because a byte is 4 times smaller than an integer. It can also be used in place of "int" data type.

Example: byte a = 10, byte b = -20

Short Data Type

The short data type is a 16-bit signed two's complement integer. Its value-range lies between -32,768 to 32,767 (inclusive). Its minimum value is -32,768 and maximum value is 32,767. Its default value is 0.

The short data type can also be used to save memory just like byte data type. A short data type is 2 times smaller than an integer.

Example: short s = 10000, short r = -5000

Int Data Type

The int data type is a 32-bit signed two's complement integer. Its value-range lies between - 2,147,483,648 (-2^31) to 2,147,483,647 (2^31 -1) (inclusive). Its minimum value is - 2,147,483,648and maximum value is 2,147,483,647. Its default value is 0.

The int data type is generally used as a default data type for integral values unless if there is no problem about memory.

Example: int a = 100000, int b = -200000

Long Data Type

The long data type is a 64-bit two's complement integer. Its value-range lies between -9,223,372,036,854,775,808(-2^63) to 9,223,372,036,854,775,807(2^63 -1)(inclusive). Its minimum value is - 9,223,372,036,854,775,808and maximum value is 9,223,372,036,854,775,807. Its default value is 0. The long data type is used when you need a range of values more than those provided by int.

Example: long a = 100000L, long b = -200000L

Float Data Type

The float data type is a single-precision 32-bit IEEE 754 floating point.Its value range is unlimited. It is recommended to use a float (instead of double) if you need to save memory in large arrays of floating point numbers. The float data type should never be used for precise values, such as currency. Its default value is 0.0F.

Example: float f1 = 234.5f

Double Data Type

The double data type is a double-precision 64-bit IEEE 754 floating point. Its value range is unlimited. The double data type is generally used for decimal values just like float. The double data type also should never be used for precise values, such as currency. Its default value is 0.0d.

Example: double d1 = 12.3

Char Data Type

The char data type is a single 16-bit Unicode character. Its value-range lies between '\u0000' (or 0) to '\uffff' (or 65,535 inclusive).The char data type is used to store characters.

Example: char letterA = 'A

 

Switched communications network

A switched communications network transfers data from source to destination through a series of network nodes. Switching can be done in one of two ways. In a circuit-switched network, a dedicated physical path is established through the network and is held for as long as communication is necessary. An example of this type of network is the traditional (analog) telephone system. A packet-switched network, on the other hand, routes digital data in small pieces called packets, each of which proceeds independently through the network. In a process called store-and-forward, each packet is temporarily stored at each intermediate node, then forwarded when the next link becomes available. In a connection-oriented transmission scheme, each packet takes the same route through the network, and thus all packets usually arrive at the destination in the order in which they were sent. Conversely, each packet may take a different path through the network in a connectionless or datagram scheme. Since datagrams may not arrive at the destination in the order in which they were sent, they are numbered so that they can be properly reassembled. The latter is the method that is used for transmitting data through the Internet.


 Electromagnetic Spectrum consists of entire range of electromagnetic radiation. Radiation is the energy that travels and spreads out as it propagates. The types of electromagnetic radiation that makes the electromagnetic spectrum.

  • Supports larger bandwidth and hence more information is transmitted. For this reason, microwaves are used for point-to-point communications.
  • More antenna gain is possible.
  • Higher data rates are transmitted as the bandwidth is more.
  • Antenna size gets reduced, as the frequencies are higher.
  • Low power consumption as the signals are of higher frequencies.
  • Effect of fading gets reduced by using line of sight propagation.
  • Provides effective reflection area in the radar systems.
  • Satellite and terrestrial communications with high capacities are possible.
  • Low-cost miniature microwave components can be developed.
  • Effective spectrum usage with wide variety of applications in all available frequency ranges of operation.

Properties of Microwaves

Following are the main properties of Microwaves.

  • Microwaves are the waves that radiate electromagnetic energy with shorter wavelength.
  • Microwaves are not reflected by Ionosphere.
  • Microwaves travel in a straight line and are reflected by the conducting surfaces.
  • Microwaves are easily attenuated within shorter distances.
  • Microwave currents can flow through a thin layer of a cable.