Found 7442 Articles for Java

Java Program for Radix Sort

AmitDiwan
Updated on 14-Sep-2020 08:21:15

449 Views

Radix sort is a sorting technique that sorts the elements based on every digit in every element (or number). Based on the ones place digit (which is also known as least significant digit) and tens place digit (which is also known as most significant digit), hundreds place digit, and so on, the elements are sorted.ExampleFollowing is an example for Radix Sort in Java − Live Demoimport java.util.*; public class my_radix_sorting {    static int get_max_val(int my_arr[], int arr_len) {       int max_val = my_arr[0];       for (int i = 1; i < arr_len; i++)       ... Read More

Java Program for Pancake sorting

Alshifa Hasnain
Updated on 13-Dec-2024 13:54:50

720 Views

In this article, we will learn pancake sorting which is a unique way to sort an array by flipping sections of it. The algorithm finds the largest unsorted element, flipping it to the front, and then flipping it to its correct position. Although not the fastest sorting method, it’s an interesting and creative way to learn about problem-solving and data manipulation. This article explains the algorithm in simple steps and shows how to implement it in Java. What is Pancake Sorting? Pancake sorting is a sorting technique that resembles selection sort, i.e. sorting the largest element first thereby reducing the ... Read More

Differences between String and StringBuffer

Himanshu shriv
Updated on 09-Sep-2020 12:05:04

14K+ Views

String is an immutable class and its object can’t be modified after it is created but definitely reference other objects. They are very useful in multithreading environment because multiple threads can’t change the state of the object so immutable objects are thread safe.String buffer is mutable classes which can be used to do operation on string object such as reverse of string, concating string and etc. We can modify string without creating new object of the string. String buffer is also thread safe.Also, string concat + operator internally uses StringBuffer or StringBuilder class. Below are the differences.Sr. No.KeyStringStringBuffer1BasicString is an ... Read More

Difference between compile-time polymorphism and runtime polymorphism

Himanshu shriv
Updated on 12-Sep-2023 09:54:51

36K+ Views

Polymorphism is one of the most important OOPs concepts. Its is a concept by which we can perform single task in multiple ways. There are two types of polymorphism one is Compile-time polymorphism and another is run-time polymorphism.Method overloading is the example of compile time polymorphism and  method overriding is the example of run-time polymorphism.Sr. No.KeyCompile-time polymorphismRuntime polymorphism1BasicCompile time polymorphism means binding is occuring at compile timeR un time polymorphism where at run time we came to know which method is going to invoke2Static/DynamicBindingIt can be achieved through static bindingIt can be achieved through dynamic binding4.InheritanceInheritance is not involvedInheritance is ... Read More

Difference between mutable and immutable object

Aishwarya Naglot
Updated on 10-Oct-2024 14:18:27

4K+ Views

In Java, state of the immutable object can’t be modified after it is created but definitely reference other objects. They are very useful in multi-threading environment because multiple threads can’t change the state of the object so immutable objects are thread-safe. Immutable objects are very helpful to avoid temporal coupling and always have failure atomicity and also helpful in multiple threading. Why though? because no one can change the object right? So, it becomes thread-safe, it means it will not cause any unexpected issues when different parts of the program are trying to access that particular object. On the other ... Read More

Difference between CountDownLatch and CyclicBarrier in Java Concurrency

Himanshu shriv
Updated on 09-Sep-2020 11:55:46

1K+ Views

CountDownLatch and CyclicBarrier both used in multithreading environment and they both are part of.As per Java Doc −CountDownLatch − A synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes.CyclicBarrier − A synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point.Sr. No.KeyCyclicBarrierCountDownLatch1BasicA synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point.A synchronization aid that allows one or more threads to wait until a set of operations being ... Read More

Difference between Apache Kafka and JMS.

Himanshu shriv
Updated on 09-Sep-2020 11:47:03

823 Views

Kafka and JMS both are messaging system. Java message service is an api which are provided by Java. It is used for implementing messaging system in your application. JMS supports queue and publisher /subscriber(topic) messaging system . With queues, when first consumer consumes a message, message gets deleted from the queue and others cannot take it anymore. With topics, multiple consumers receive each message but it is much harder to scale.Kafka is a generalization of these two concepts - it allows scaling between members of the same consumer group, but it also allows broadcasting the same message between many different ... Read More

Difference between Point-To-Point and Publish/Subscribe JMS Messaging Models

Himanshu shriv
Updated on 09-Sep-2020 11:44:58

826 Views

JMS is an acronym Java message service. Java message service is an api which are provided by Java. It is used for implementing messaging system in your application.JMS is an API or specification which does not contain implementation therefore to use JMS have to some third party service provider like ActiveMq , Weblogic messaging and etc.JMS support two types of messaging domain −Point to Point MessagingPublish /Subscribe messaging  Sr. No.KeyPoint to Point MessagingPublish /Subscribe1BasicIt is one to one destination of message. Message sent into the queue and that message can be read by only one receiver.It is one to many ... Read More

Difference between default and static interface method in Java 8.

Himanshu shriv
Updated on 31-Oct-2023 03:22:25

29K+ Views

According to Oracle's Javadocs −Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces.A static method is a method that is associated with the class in which it is defined rather than with any object. Every instance of the class shares its static methods.Static method in interface are part of the interface class can’t implement or override it whereas class can override the default method.Sr. No.KeyStatic Interface MethodDefault Method1BasicIt is a static method which belongs to the interface only. We can write implementation ... Read More

Difference between PermGen Space and MetaSpace.

Himanshu shriv
Updated on 09-Sep-2020 11:29:52

4K+ Views

PermGen is the memory area for storing class data like static variable, byte code and etc. By default 64 Mb is allocated for PermGen. It can be tuned by using -XXMaxPermSize.In Java 8, PermGen method area replaced with MetaSpace. They have moved permGem to the separate memory in the native OS and that is called MetaSpace. It can by default auto increases its size. In MetaSpace, classes can load and unload during the lifespan of the JVM.Sr. No.KeyPermGenMetaSpace1BasicPermGen is the memory area for storing class data like static variable, byte code and etcIn Java 8, PermGen method area replaced with ... Read More

Advertisements