Category Archives: Java

Java.net.HttpURLConnection Class in Java

HttpURLConnection class is an abstract class directly extending from URLConnection class. It includes all the functionality of its parent class with additional HTTP specific features. HttpsURLConnection is another class which is used for the more secured HTTPS protocol. Where is it used? It is one of the popular choices among the Java developers for interacting… Read More »

Using final with Inheritance in Java

Prerequisite – Overriding in java, Inheritance final is a keyword in java used for restricting some functionalities. We can declare variables, methods and classes with final keyword. Using final with inheritance During inheritance, we must declare methods with final keyword for which we required to follow the same implementation throughout all the derived classes. Note… Read More »

Association, Composition and Aggregation in Java

Association Association is relation between two separate classes which establishes through their Objects. Association can be one-to-one, one-to-many, many-to-one, many-to-many. In Object-Oriented programming, an Object communicates to other Object to use functionality and services provided by that object. Composition and Aggregation are the two forms of association. Output: Neha is employee of Axis In above… Read More »

Dynamic Method Dispatch or Runtime Polymorphism in Java

Prerequisite: Overriding in java, Inheritance Method overriding is one of the ways in which Java supports Runtime Polymorphism. Dynamic method dispatch is the mechanism by which a call to an overridden method is resolved at run time, rather than compile time. When an overridden method is called through a superclass reference, Java determines which version(superclass/subclasses)… Read More »

Inheritance in Java

Inheritance is an important pillar of OOP(Object Oriented Programming). It is the mechanism in java by which one class is allow to inherit the features(fields and methods) of another class. Important terminology: Super Class: The class whose features are inherited is known as super class(or a base class or a paren class). Sub Class: The… Read More »

Java.lang.Boolean Class in Java

Java provides a wrapper class Boolean in java.lang package. The Boolean class wraps a value of the primitive type boolean in an object. An object of type Boolean contains a single field, whose type is boolean. In addition, this class provides useful methods like to convert a boolean to a String and a String to… Read More »

Working with UDP DatagramSockets in Java

DatagramSockets are Java’s mechanism for network communication via UDP instead of TCP. Java provides DatagramSocket to communicate over UDP instead of TCP. It is also built on top of IP. DatagramSockets can be used to both send and receive packets over the Internet. One of the examples where UDP is preferred over TCP is the… Read More »

Passing and Returning Objects in Java

Although Java is strictly pass by value, the precise effect differs between whether a primitive type or a reference type is passed. When we pass a primitive type to a method, it is passed by value. But when we pass an object to a method, the situation changes dramatically, because objects are passed by what… Read More »

Constructor Overloading in Java

Prerequisite – Constructor, Overloading in java In addition to overloading methods, we can also overload constructors in java. Overloaded constructor is called based upon the parameters specified when new is executed. When do we need Constructor Overloading? Sometimes there is a need of initializing an object in different ways. This can be done using constructor… Read More »

Simple Calculator via UDP in Java

Networking is a two-way communication between a host and a server, rather an exchange of information. Any server is setup to respond to specific queries as requested by a client. There are many different kinds of server based on the utility they provide to the users. Some examples include File Server, Application Server, Domain Server… Read More »

Autoboxing and Unboxing in Java

Autoboxing: Converting a primitive value into an object of the corresponding wrapper class is called autoboxing. For example, converting int to Integer class. The Java compiler applies autoboxing when a primitive value is: Passed as a parameter to a method that expects an object of the corresponding wrapper class. Assigned to a variable of the… Read More »