Programming Articles - Page 2441 of 3366

Difference between length of Array and size of ArrayList in Java

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

639 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.

Aishwarya Naglot
Updated on 14-Nov-2024 11:03:37

1K+ Views

As we know, both Java and JavaScript are programming languages and are used in application development. But there are significant differences between the languages, which we will discuss below. Java Java is a high-level language that is also a platform-independent language. It is mainly used in the development of web applications, mobile applications, games, etc. Java is a statically typed language, which means that the code must be checked for errors before it runs. JavaScript whereas JavaScript is a dynamically typed language, which means that the code is checked for errors while it runs. JavaScript is a client-server-side language, which ... Read More

Difference between HashMap and HashSet in Java.

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

26K+ 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

3K+ 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 continue and break statements in Java

Alshifa Hasnain
Updated on 21-Mar-2025 19:08:32

9K+ Views

As we know in programming execution of code is done line by line. Now in order to alter this flow Java provides two statements break and continue which are mainly used to skip some specific code at specific lines. Difference Table Following are the important differences between continue and break − Sr. No. Key ... Read More

Difference between concat() and + operator in Java

Aishwarya Naglot
Updated on 10-Oct-2024 12:46:11

2K+ Views

Java provides two ways to append strings and make them one. These two methods are namely the concat() method and + operator to join strings together, but there are some important differences between how they work. The concat() method is a bit more specific and limited, while the + operator is more flexible. So, even though they do the same thing, understanding how and when to use each one can help in writing more efficient or cleaner code in Java. Concat() Vs + operator The following are the important differences between the concat method and the + operator. ... Read More

Difference between Compile Time Errors and Runtime Errors in C Program

Nitin Sharma
Updated on 18-Sep-2019 11:49:02

2K+ Views

Error or exception is something that refers to the interruption of code execution due to which the expected outcome could not be attained to the end-user.On the basis of the event when an error is generated or identified we can classify them as Compile time error and runtime error.The following are the important differences between Compile Time Errors and Runtime Errors.Sr. No.KeyCompile Time ErrorsRuntime Errors1ReferenceCompile-time errors are generally referred to the error corresponding to syntax or semantics.Runtime errors on the other hand refer to the error encountered during the execution of code at runtime.2DetectionCompile-time errors get detected by compiler at ... Read More

How can we encode a JSON object in Java?

raja
Updated on 04-Jul-2020 05:58:28

3K+ Views

A JSONObject is a subclass of java.util.HashMap where no order is provided. We can also use the strict ordering of elements as well with the help of the JSONValue.toJSONString(map) method i.e. by the implementation of java.util.LinkedHashMap.We can encode a JSON object in the below two examples.Example import java.util.*; import org.json.simple.JSONObject; public class JSONEncodingTest {    public static void main(String[] args) {       Map dataMap = new HashMap();       dataMap.put("Name", "Adithya");       dataMap.put("Age", new Integer(25));       dataMap.put("Salary", new Double(25000.00));       dataMap.put("Employee Id", new Integer(115));       dataMap.put("Company", "TutorialsPoint");       JSONObject ... Read More

How can we parse a nested JSON object in Java?

Aishwarya Naglot
Updated on 22-Apr-2025 16:28:52

15K+ Views

Sometimes, we need to parse a nested JSON object, which means an object inside another object. In this article, let's learn about how to parse a nested JSON object in Java. If you don't know about JSON, refer JSON overview. Parsing a Nested JSON Object in Java? We can achieve this using some of the popular Java libraries. Those are listed below: Using org.json library : We will use jsonObject.getJSONObject method to parse a nested JSON object. Using Gson library : We will use JsonParser.parseString(json).getAsJsonObject(). Using Jackson library : In this, We will use ObjectMapper.readTree(json) method. Now, ... Read More

Advertisements