Tag Archives: Java

Behavioral Patterns

BEHAVIOURAL PATTERNS : These design patterns are specifically concerned with communication between objects. Chain of Responsibility : Chain of Responsibility is a behavioral design pattern that lets you pass requests along a chain of handlers. Upon receiving a request, each handler decides either to process the request or to pass it to the next handler Read More →

Creational Design Patterns

CREATIONAL PATTERNS These design patterns provide a way to create objects while hiding the creation logic, rather than instantiating objects directly using new operator. This gives program more flexibility in deciding which objects need to be created for a given use case. SINGLETON PATTERN : In object-oriented programming, a singleton class is a class that Read More →

Design Patterns

Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system. Each pattern is like a blueprint that you can customize to solve a particular design problem in your code. Design patterns are divided into three fundamental groups: 1. Behavioral, 2. Creational, 3. Structural Behavioral Read More →

Difference Between String , StringBuilder And StringBuffer With Example

String String is immutable ( once created can not be changed )object . The object created as a String is stored in the Constant String Pool . Every immutable object in Java is thread safe ,that implies String is also thread safe . String can not be used by two threads simultaneously. String once assigned Read More →

Difference Between HashMap And HashTable

Difference Between HashMap And HashTable 1. Synchronization or Thread Safe : This is the most important difference between two. HashMap is non synchronized and not thread safe. On the other hand, HashTable is thread safe and synchronized. 2. Null keys and null values : Hashmap allows one null key and any number of null values, Read More →

Threads , Lifecycle Explained With Example

threadstates

What is Thread ? Thread is a sequence of code executed independently with other threads of control with in a single executed program. Multi threading enables you to write in a way where multiple activities can proceed concurrently in the same program. Why Threads? If the program is break into different parts , then it Read More →

ArrayList vs. LinkedList

arraylist-vs-linkedlist-complexity

ArrayList vs. LinkedList   ArrayList is implemented as a resizable array. As more elements are added to ArrayList, its size is increased dynamically. It’s elements can be accessed directly by using the get and set methods, since ArrayList is essentially an array. LinkedList is implemented as a double linked list. Its performance on add and Read More →

Implement Stack and Queue using Linked List in Java

The implementation of a linked list is pretty simple in Java. Each node has a value and a link to next node. Two popular applications of linked list are stack and queue. Stack: What is stack? Stack is a linear data structure which implements data on last in first out criteria. Here is a java Read More →

Can we Overload Static methods in Java ?

Overloading: Overloading is also a feature of OOPs languages like Java that is related to compile time (or static) polymorphism. This feature allows different methods to have same name, but different signatures, especially number of input parameters and type of input parameters. Can we overload static methods? The answer is ‘Yes’. We can have two Read More →

Why can’t constructors be final, static or abstract in Java?

When you set a method as final, it means : “You don’t want any class override it”, but constructor by JLS definition can’t overridden,so it is clean. When you set a method as ‘abstract’,it means:”Method don’t have any body and you want to implement it at another time in a child class”, but the constructor Read More →

Can there be more than one main method in a Java Program

Yes, you can have as many main methods as you like. You can have main methods with different signatures from main(String[]) which is called overloading, and the JVM will ignore those main methods. You can have one public static void main(String[] args) method in each class. Some people use those methods for testing. They can test the operation Read More →

Can We Declare a Class Private in Java

Outer or concrete class can’t be private in java. For example: Output: Compile Time Error It is because, java follows oops concepts. If you make any class as private, it will not be accessible from another class. So there can’t be inheritance, runtime polymorphism, abstraction etc. But, nested class can be private. For instance: Output: Read More →