Java Tutorial

Java Tutorial Java Features C++ vs Java Java History Java Hello World Java Development Kit Java Runtime Environment Java Virtual Machine Difference between JDK, JRE, and JVM Memory Areas in Java Java Operators Java Keywords Primitive Data Types Variables

Java Loops

Java Do While Loop Java While Loop Java For Loop Java Enhanced For Loop

Java Programs

Java Basic Programs Factorial Program in Java Fibonacci Series Program in Java Prime Number Program in Java Palindrome Number Program in Java Armstrong Number Program in Java Anagram Program in Java Pattern Programs in Java Calculator Program in Java Leap Year Program in Java Addition Program in Java Number Pattern Programs in Java Star Pattern Programs in Java Package Program in Java Pyramid Program in Java Sorting Program in Java String Palindrome Program in Java Even Odd Program in Java For Loop Program in Java If Else Program in Java Switch Case Program in Java GCD Program in Java LCM Program in Java Hello Program in Java Matrix Program in Java Menu Driven Program in Java Series Program in Java Client Server Program in Java Swapping Program in Java Pig Latin Program in Java Tower of Hanoi Program in Java Recursion Program in Java Matrix Multiplication Program in Java Perfect Number Program in Java Classes and Objects in Java Example Programs String Programs in Java Array Programs in Java Constructor Program in Java Inheritance Program in Java Abstract class Program in Java Interface Program in Java Encapsulation Program in Java Polymorphism Program in Java Exception Handling Program in Java Multithreading Program in Java Thread Program in Java Collection Programs in Java ArrayList Program in Java Stack Program in Java Applet Program in Java Swing Program in Java JDBC Program in Java How to run Java program in command prompt How to run Java program in Eclipse

Java Sorting

Sorting Algorithms in Java Merge Sort in Java Quick Sort in Java Bubble Sort in Java Insertion Sort in Java Selection Sort in Java Heap Sort in Java Radix Sort in Java Topological Sort in Java Bucket Sort in Java Counting Sort in Java

Java OOPs Concepts

OOPs - Object Oriented Programming Objects and Classes in Java Java Naming Conventions Constructors in Java Java this keyword Java static keyword Inheritance in Java Aggregation in Java Java super keyword Constructor Chaining and Constructor Overloading Java Polymorphism Static and Dynamic Binding in Java Java Abstraction Abstract class in Java Interface in Java Difference between Abstract class and Interface Java final keyword Packages in Java Access Modifiers in Java Java Wrapper classes Java Numbers Java Characters Java Integer Java Boolean Java Arrays Java Command Line Arguments Java strictfp Keyword Java Math

Java Strings

Java Strings Java String Methods StringBuilder in Java StringBuffer in Java Java Regular Expressions StringBuffer vs StringBuilder String vs StringBuffer String vs StringBuilder String Manipulation in Java Java String Concatenation How to Reverse a String in Java String Array in Java How to Compare Two Strings in Java How to Concatenate Two Strings in Java Why String in Immutable in Java java.lang.NumberFormatException for Input String String Pool in Java Java Generate Random String How to take String Input in Java Java String Interview Questions

Java Exceptions

Exception Handling in Java Java try catch Java throw Java throws Difference between throw and throws Java finally Java Custom Exception Java Exception Propagation

Garbage Collection

Automatic Resource Management in Java Java Garbage Collection Java finalize() Java gc() Difference between final, finally and finalize


Multithreading in Java Process and Thread in Java Basic Terms in Multithreading Java Thread creation Thread Scheduler in Java Java Thread class DeadLock in Java

Java IO

Java IO Java Read File Java BufferedWriter Java InputStreamReader Java File Java Read File Line By Line Java FileOutputStream Jar File in Java


Java Serialization Java transient


Java Network Programming Java Socket Programming Java URL Java URLConnection HttpURLConnection in Java Java InetAddress Java DatagramSocket and Java DatagramPacket


Java AWT


Swing in Java

Java Collections

Collections in Java Java List Interface ArrayList in Java LinkedList in Java Vector in Java Stack in Java ArrayList vs LinkedList in Java ArrayList vs Vector in Java Java Set Interface HashSet in Java LinkedHashSet in Java TreeSet in Java Java Queue Interface PriorityQueue in Java ArrayDeque in Java Java Map Interface HashMap in Java LinkedHashMap in Java TreeMap in Java Dictionary in Java Hashtable in Java Properties in Java Collections class in Java Java Comparable Java Comparator Comparable vs Comparator in Java

Java Generics

Generics in Java

Java Annotations

Annotations in Java


Java JDBC Tutorial

Java Differences

Java vs JavaScript Python vs Java Kotlin vs Java Java vs C++ C# vs Java Static vs Non-static in Java C vs Java int vs Integer in Java Stack vs Heap in Java Java Array vs ArrayList

How to

How to run Java program How to set path in Java How to check the Java version in cmd How to install Java in Windows 10 How to run Java program in cmd How to call a method in Java How to sort an array in Java How to iterate HashMap in Java How to write Java program How to create an array in Java How to create a package in Java How to generate random numbers in Java How to input String in Java How to create thread in Java How to find length of String in Java How to sort a string in Java How to use scanner in Java How to achieve multiple inheritance in Java How to run Java program in Eclipse How to call a function in Java How to create array of objects in Java How to create custom exception in Java How to achieve abstraction in Java How to call static method in Java

Java 8 Features

Java 8 Features Lambda Expressions in Java Functional Interface in Java Streams in Java Java Base64 Encoding and Decoding Parallel Arrays Sort in Java

Java 9 Features

Java 9 Tutorial Java 9 Try With Resources Java 9 Interface Private Method

Java Servlet Tutorial

Java Servlets Tutorial

Java JSP Tutorial

Java JSP Tutorial

Hibernate Tutorial

Hibernate Tutorial

Spring Tutorial

Spring Tutorial

Spring MVC Tutorial

Spring MVC Tutorial

Jenkins Tutorial

Jenkins Tutorial

Java Math Methods

Math.abs() Math.acos() Math.addExact() Math.asin() Math.atan () Math.atan2() Math.cbrt() Math.ceil() Math.copysign() Math.cos() Math.cosh() Math.decrementExact() Math.exp() Math.expm1() Math.floor() Math.floorDiv() Math.floorMod() Math.getExponent() Math.hypot() Math.IEEEremainder() Math.incrementExact() Math.log() Math.log10() Math.log1p() Math.max() Math.min() Math.multiplyExact() Math.multiplyFull() Math.negateExact() Math.nextAfter() Math.nextDown() Math.nextUp() Math.pow() Math.random() Math.rint() Math.round() Math.scalb() Math.signum() Math.sin() Math.sinh() Math.sqrt() Math.subtractExact() Math.tan() Math.tanh() Math.toDegrees() Math.toIntExact() Math.toRadians() Math.ulp()

Java String Methods

toCharArray() copyValueOf() endsWith() equals() equalsIgnoreCase() format() getBytes() getChars() hashCode() indexOf() intern() isEmpty() join() lastIndexOf() length() replace() replaceAll() replaceFirst() split() startsWith() subSequence() substring() toLowerCase() toUpperCase() trim() valueOf()

Java Conversion

Java Convert String to int Java Convert int to String Java Convert String to long Java Convert long to String Java Convert String to float Java Convert float to String Java Convert String to double Java Convert double to String Java Convert String to Date Java Convert Date to String Java Convert String to Object Java Convert Object to String Java Convert String to char Java Convert char to String Java Convert int to long Java Convert long to int


Functional Interfaces in Java Singleton class in Java Awesome explanation of Strings in Java Object class in Java Static class in Java All the important string methods in Java String Handling Method in Java What are Array strings in Java Advantages and Disadvantages of Strings in Java Big Decimal class in Java Class definition in Java Char and String differences in Java Difference between String, StringBuffer and StringBuilder in java Replace character in string Java String Coding Interview Questions in Java What is String in Java? String isnullorempty in Java String Matches in Java Trim Method in String Java Bean class in Java Libraries in Java Arithmetic Operations on String in Java Convert Char array to string in java Check whether Java is installed or not How to calculate time difference in Java How to stop execution after a certain time in Java Jagged Array in Java Java ArraylistRemove() Time Complexity Java Swing Time Picker Zigzag Array in Java

Java Networking


Networking is a way of communicating the devices. It is made up of various technologies like computers, switches, routers that are interconnected and share data among themselves.

The two common network protocols:


TCP stands for Transmission Control Protocol/Internet Protocol that allows reliable communication between two applications. TCP/IP specifies data exchange over the end-to-end communications and specify how it should be broken, transmitted, routed, packets, addressed, and received at the destination. TCP/IP is compatible with all the operating systems. TCP/IP is a highly scalable and routable protocol that searches the most efficient path through the network. The two main protocols in TCP/IP protocol suite serve specific functions:

  • TCP: The application can create channels of communication across the network. It also manages how messages are assembled into smaller packets and then transmit it over the Internet and re-assembled in the right order at the destination address.
  • IP: It defines how to address and route each packet to make sure it reaches the right destination.

2. UDP

UDP stands for User Datagram Protocol, a connectionless protocol that allows the packets of data to be transmitted between the applications. It is an unreliable and connectionless protocol, so there is no need to establish a connection before transferring the data. UDP permits packets drops instead of processing delayed packets. There is no error checking in UDP. UDP is more efficient, based on both latency and bandwidth. It is useful when it reduces the requirement of computer resources, the transmission of Real-time packets, mainly in multimedia applications. It is used for simple request-response communication when the size of data is less. It is a suitable protocol for multicasting as UDP supports packet switching. UDP is used for routing some update protocols. It is usually used for real-time applications that cannot tolerate uneven delays between sections of a received message.

Networking has the following modules, such as:

  1. Clients and Servers.
  2. IP Addresses.
  3. A network hub, switches, and cables.
  4. Routers and firewalls.

Client and Server concept

It is an essential architecture to communicate with each other over the network.


  1. The server is the computer that holds services and every single information related to the clients such as media files, database-related matters, and keep the website for Google search page, etc.
  2. It provides services in the form of webpages and sends it out when requested by the client.


  1. The client is a different computer that requests to view, download, or search the content from the server, such as to request for Google web page, etc.
  2. A client connects to the server and other clients over a network to exchange the information and data.
Client and Server concept

Mechanism of a working client-server architecture

In a client-server architecture, the client computer sends a request for data to the server, the server accepts the request of the client, process it, and deliver the data packets requested back to the client. One unique feature is that the server computer has the potential to manage numerous at the same time.

On the network, the server can locate anywhere, and if the client has its IP Address, it can access its services efficiently. The client asks for the services like website accessed from the server computer. The respective site is delivered through the server and displayed on the client web browser in the form of webpages.

IP Address

It is a unique address to identify the computer on the network. It is used for directing the data across a network, computers need to identify their destinations and origins. It is an identification which is known as IP Address.

Two types of IP Address:

  1. IPv4
  2. IPv6

IPv4 address

The IPv4 protocol is assigned for 232 addresses. Addresses in IPv4 is 32-bits long. There is a maximum of 4,294,967,296 unique addresses. IPv4 is 32- bit binary number that contains two sub-addresses i.e., the network and the host, with an imaginary boundary separating them. An IP address is represented as 4 octets of numbers from 0-255 represented in decimal form. An IPv4 address is represented in dotted-decimal notation, with every eight bits (octet) represented by a number from 1 to 255, each separated by a dot. An example of an IPv4 address is

IPv4 address contains two parts. The first part of the address specifies the network, and the second part specifies the host. A host represents a server offering resource information, services, and applications to users or other nodes on the network. It is a network that uses various protocols and attaches various hosts for their inter-communications.

IPv6 addresses

To avoid the address space issue in technology and to increase the address size from 32 bits in IPv4 to 128 bits, IPv6 specifies 3.4*1038 (2128) unique addresses. These are reportedly enough addresses, assigned one to every single host on the Internet. IPv6 addresses are shown in the form of eight sets of four hexadecimal digits, and each set of numbers separates by a colon. It looks like 2DAB:FFFF:0000:3EAE:01AA:00FF:DD72:2C4A. There are no defined classes in the IPv6 version.

Network devices


A repeater is operated at the physical layer. It is used to regenerate the signal before it becomes too weak or corrupted so that the signal can be transmitted over the network. The repeaters do not amplify the signal. They put the signal bit by bit and regenerate it at the original strength when the signal becomes weak.


Computers are connected via cables to create a network. But sometimes individual computers and cables were not able to make a good system so to overcome this issue hubs came into existence. The cable is a media that transmits the communication signals.

There are three types of cables:

  • Twisted-pair cable: It is a high-speed cable that transmits the data over 1Gbps or more.
  • Coaxial cable: Coaxial cable resembles a TV installation cable. Coaxial cable is expensive than the twisted pair cable and provides a high data transmission speed.
  • Fiber optic cable: It is a high-speed cable that transmits the data using a light beam. It has a high data transmission speed as compared to other cables and more expensive as compared to other cables.


 A hub connects multiple cables coming from different branches. Hubs do not filter the data.  Data packets are sent to all connected devices. The collision domain of all hosts connected through Hub remains one. It does not have the intelligence to find out the best path for the data packets, which leads to inefficiencies and wastage. It is the way to interconnect LANs. The Hub amplifies the signal. If a device wants to communicate a message to many computers, it sends a message to the Hub. It is the responsibility of Hub to resend the message to all the computers. Hub can slow down if many computers try to send a message again and again at a time, which leads to confusing the hub.

  1. Hub works on the physical layer (Layer 1 of the OSI model).
  2. Hub works internally in bus topology.
  3. It has 2,4,8 ports to establish communication between the devices. They allow communication to a maximum of 8 devices.
  4. Hub is not an intelligent device. If computer1 wants to communicate with the computer2, routers transfer the message to all the computers attached to its ports.
  5. The message which is broadcasted contains the sender and receiver address. It can be read or modified by the others, but it is accepted by its respective receiver.
  6. Hub favors a single Collision domain that has a single way to communicate with other computers. If more than one computer sends its packets, they will collide among themselves.
  7. Hub can only be used in the LAN network.
  8. Hub does not have a table to store MAC address or IP address for the computers; that is why it broadcast the messages to all the computers.

There are two types of Hub:

  1. Active Hub-It acts as a Repeaters as it needs electricity to run. Still, it amplifies the analog signal or regenerates the digital signal so that the signal can be transferred over a long way.
  2. Passive Hub-It does not require electricity. It does not amplify the signal but only receive and forward the signal.


A bridge is operated at the data link layer. A bridge functions as a repeater, with the functionality of filtering content by reading the MAC addresses of source and destination. It is used to interconnect two LANs working on the same protocol.

The bridges are full-fledged packet switches that forward and filter frames using the LAN destination addresses. When a frame reaches the bridge interface, the bridge does not copy the frame onto all of the other interfaces. The bridge specifies the destination address of the frame and attempts to forward the frame to the destination.

The bridge determines the 48-bit destination address for the packet and directs the packet only to the cable where the recipient resides. One packet causes less congestion, thereby. A bridge may store (buffer) enough bits to interpret the destination address. It could store (buffer) a whole packet and queue it for the correct outgoing link.



  1. It is an intelligent device. Bridge inspect incoming traffic and decide whether to forward or reject.
  2. It checks the source and destination MAC address, not IP address as the IP address do not work on the datalink layer.
  3. The bridge is broadcasted to all devices at the first time, then it is broadcast to one of the segments of either side as it knows the MAC address of the device on its port.
  4. It is used to connect multiple network segments or LAN segment.
  5. It can filter data traffic.
  6. Bridges decrease the traffic on the LAN by dividing it into two segments.
  7. It has two collision Domains.


A switch is a networking device that works on the data link layer device. It makes efficient communication as it does not forward packets that have errors and forward good packets selectively to correct port only. A network switch is a device that is used to connect multiple computers inside LAN (Local Area Network). Network switches perform at the second layer (Data Link Layer) of the OSI model. The basic function of a Network switch is to forward layer 2 packets (Ethernet frames) from source device to destination device.



  1. It is an intelligent device and also works on the Data Link layer.
  2. The switch has multiple collision Domains, so there is less chance of collision of messages, among others.
  3. It has full-duplex communication.
  4. It maintains a CAM table based on the MAC address. It will communicate among all the devices on the basis of the CAM table.
  5. First, it will broadcasts then unicast and multicast.
  6. Every port of the switch is a separate collision domain.
  7. The switch has one Broadcasting domain.
  8. It has a maximum of 48 switch ports.
  9. It is slow as compared to others.

Types of switches

  1. Store and forward switch- The switch buffers and verify each frame before forwarding it. It is a little bit slow but very reliable.
  2. Cut through switch- The switch reads up to the frame hardware address before starting to forward it. No error checking.
  3. Fragment Free Switch- A method that attempts to retain the benefits of both store and forward and cut through check first 64 bytes.

Routers and Firewalls


A router relates to the network device that routes data packets based on their IP addresses. The router is mainly a Network Layer device. A Router connects WANs and LANs and has a dynamically updating routing table based on which they make decisions on routing the data packets. Routers are the first device in your network that gives you internet connectivity.



  1. It is the layer 3 device.
  2. It is a WAN device.
  3. The router is an internetworking device. It can communicate between two or more different networks.
  4. The router has a routing table and maintains Network ID and port number in its table. It communicates the messages based on its Network ID.
  5. It mostly uses WAN, not LAN.
  6. In the router, every port has its broadcast domain for broadcasting the messages.
  7. It has 2,4,8 ports.
  8. It is fast as compared to others.



They can filter users and keep them out of private networks. Firewalls are network security appliances. Most of the small networks have perimeter-hardware firewalls, for controlling access and securing local networks from the outside world. Due to this reason, most perimeter firewalls also have routing capabilities.

The routers route traffic between two separate networks, firewalls monitor the traffic and block unauthorized traffic coming from the outside into your network. Few firewalls contain antivirus mechanisms to protect your network from viruses and unwanted emails.

There are many software firewall programs you can install on your computer, such as McAfee total protection, Norton antivirus, etc.


A gateway is a connecting device used to connect remote networks with the host network. Generally, it acts as an entry or exit point. Mostly gateway is operated at the application layer.

A gateway is a way to connect two networks that may work upon different networking models. They work as a messenger agent that take data from one system, interpret it, and transfer it to another system. Gateways are also referred to as protocol converters and can operate at any network layer.

Uses of computer Network

  • Resource sharing

These are the resources that are shared, such as programs, printers, and data among the users on the network.

  • Server-client model

The computer networking is used in the server-client model. A server acts as a central computer, used to store the information, and maintained by the system administrator. Clients act as a machine used to access the information stored in the remote server.

  • Communication medium

The computer network offers the communication medium among the users.

  • e-commerce

The computer network is also important in businesses. We can perform business over the internet.