Found 4338 Articles for Java 8

Difference between length of Array and size of ArrayList in Java

Nitin Sharma
Updated on 18-Sep-2019 12:23:03

494 Views

In collections, one of the main functional requirement is to get the number of elements which are get stored in our collection so that one can decide whether to put more elements in it or not. Also, the number of elements is also required for iteration of collection.As we know Array and Arraylist both are used to store elements but both have different defined methods in order to know the number of elements stored in it.The array has a length method that provides the number of elements can be stored or in simple words capacity of the Array. Also, the ... Read More

Difference between Java and JavaScript.

Nitin Sharma
Updated on 18-Sep-2019 14:18:20

851 Views

As we know both Java and javascript are the programming languages and used in application development. But there are significant differences between both of the languages which we will discuss below.The following are the important differences between Java and JavaScript.Sr. No.KeyJavaJavaScript1Language TypeJava is primarily an object-oriented programming language that requires a virtual machine platform for its execution.JavaScript is a lightweight programming language(“scripting language”) and used to make web pages that do not require such virtual environment for its execution.2Syntax and semanticsJava is a type of language where compiler reports exception in case syntax does not meet the requirement or we ... Read More

Difference between HashMap and HashSet in Java.

Nitin Sharma
Updated on 15-Sep-2023 01:07:13

22K+ Views

HashMap and HashSet both are one of the most important classes of Java Collection framework.Following are the important differences between HashMap and HashSet.Sr. No.KeyHashMapHashSet1ImplementationHashmap is the implementation of Map interface.Hashset on other hand is the implementation of set interface.2Internal implementationHashmap internally do not implements hashset or any set for its implementation.Hashset internally uses Hashmap for its implementation.3Storage of elementsHashMap Stores elements in form of key-value pair i.e each element has its corresponding key which is required for its retrieval during iteration.HashSet stores only objects no such key value pairs maintained.4Method to add elementPut method of hash map is used to ... Read More

Difference between Definition and Declaration in Java.

Nitin Sharma
Updated on 18-Sep-2019 12:14:17

2K+ Views

For the difference between definition and declaration, one should consider their literal meaning first which includes Declare means to announce or proclaim while Define means to describe some entity.The following are the important differences between the Definition and the Declaration.Sr. No.KeyDeclarationDefinition1ConceptThe concept of declaration includes informing the compiler about properties of the variable such as its name, type of value it holds and the initial value if any it takes.While the definition is basically the actual implementation and memory location of function and about memory for the variable is allocated during the definition of the variable.2Exception in CBoth declaration and ... Read More

Difference Between Daemon Threads and User Threads In Java

Nitin Sharma
Updated on 18-Sep-2019 12:10:14

1K+ Views

As we know java is a language that supports multi threading and on the basis of nature threads in java are classified into two types Daemon thread and User thread.The following are the important differences between Daemon Threads and User Threads.Sr. No.KeyDaemon ThreadsUser Threads1NatureDaemon thread is low in priority i.e JVM does not care much about these types of threads.User threads are recognized as high priority thread i.e. JVM will wait for any active user thread to get completed.2CPU availabilityIt is not guaranteed that Daemon thread always gets CPU usage whenever it requires due to its low priority.User thread always ... Read More

Difference between concat() and + operator in Java

Nitin Sharma
Updated on 18-Sep-2019 11:53:23

1K+ Views

Java provides two ways in order to append strings and make them one. These two methods are namely Concat() method and + operator. Both are developed for the same functionality but still have some major differences.The following are the important differences between concat method and + operator.Sr. No.Keyconcat method+ operator1TypeAs syntax refers concat() is a method and comes under java.lang.String package.While on the other hand + is an operator and not a method.2Number of argumentsThe concat method could take the only argument as input and append this input to the target string on which this method is called.+ operator could ... Read More

Difference between Arrays and Collection in Java

Nitin Sharma
Updated on 17-Sep-2019 10:34:05

12K+ Views

In order to store multiple values or objects of the same type, Java provides two types of data structures namely Array and Collection.The following are the important differences between Arrays and Collection.Sr. No.KeyArraysCollection1SizeArrays are fixed in size i.e once the array with the specific size is declared then we can't alter its size afterward.The collection is dynamic in size i.e based on requirement size could be get altered even after its declaration.2Memory ConsumptionArrays due to fast execution consumes more memory and has better performance.Collections, on the other hand, consume less memory but also have low performance as compared to Arrays.3Data ... Read More

Difference between an Integer and int in Java

Nitin Sharma
Updated on 02-Mar-2020 10:04:38

10K+ Views

A Java both int and Integer are used to store integer type data the major difference between both is type of int is primitive while Integer is of class type.This difference become significant when concept of OOPs comes in picture during development as int follows the principle of primitive data type while Integer behave as a wrapper class.Following are the important differences between int and Integer.Sr. No.KeyintInteger1TypeA int is a data type that stores 32 bit signed two's compliment integer.On other hand Integer is a wrapper class which wraps a primitive type int into an object.2Purposeint helps in storing integer ... Read More

Difference between a Static Queue and a Singly Linked List in Java.

Nitin Sharma
Updated on 16-Sep-2019 11:10:29

703 Views

In Java List and Queue both are introduced as an ordered list of objects, where the same object may be added more than once. The difference between both comes in the manner of adding elements. In the queue, all the elements get inserted at the rear and removed from the front while we can add an element anywhere in the list.Sr. No.KeyStatic QueueSingly Linked List1Data initialization.Static Queue works in first out(FIFO) fashion as all the elements get inserted at the REAR and removed from the FRONT of the queue.In the case of Singly Linked List, one can add elements anywhere ... Read More

Can we throw an Unchecked Exception from a static block in java?

Maruthi Krishna
Updated on 12-Sep-2019 08:57:15

1K+ Views

A static block is a block of code with a static keyword. In general, these are used to initialize the static members. JVM executes static blocks before the main method at the time of class loading.Example Live Demopublic class MyClass {    static{       System.out.println("Hello this is a static block");    }    public static void main(String args[]){       System.out.println("This is main method");    } }OutputHello this is a static block This is main methodExceptions in static blockJust like any other method in Java when an exception occurs in static block you can handle it using try-catch ... Read More

Advertisements