Difference between Array and ArrayList in Java

Here you will learn about difference between array and arraylist in java. Both array and arraylist are most important and frequently used data structure in java. Below I have discussed about various differences between them.   Difference between Array and ArrayList in Java Property Array ArrayList Size Array is fixed in size. Once declared, its size can’t be changed. ArrayList size can be changed after declaration. For example when we add or remove element in arraylist, its size increases or

Read more

How to Split String in Java with Example

Here you will learn how to split string in java. We can split string in Java using split() method of java.lang.String class. It takes a regular expression as an argument and returns an array of strings. Syntax:

  Split String in Java Example Below program will split the string by space.

  Output I Love Java Programming   There are few special characters like ., ?, |, +, etc. and some escape characters like \n, \t, \b, etc.

Read more

Why Java Does Not Support Pointers?

Below are some reasons why Java does not support pointers. Although there are various advantages of pointer but it has several disadvantages that I have mentioned in the article.     Simple The pointer concept is very confusing, difficult to understand (especially for beginners) and causes bugs in code. To make java simpler and less complex the java creators decided to remove the concept of pointers.   Secure Security is one of the biggest issue in programming world. Pointer provides

Read more

Binary Search in Java

In this tutorial you will learn about binary search in Java. Binary search is a searching algorithm that uses divide and conquer technique. The array on which searching is to be done must be sorted in ascending order. The target element is compared with middle element. If it is less than middle element then left half is discarded and if it is greater than middle element then right half is discarded. Now a new middle element is calculated in the remaining

Read more

Java Virtual Machine (JVM) Architecture

In this tutorial you will learn about Java Virtual Machine (JVM) architecture. What is JVM? Java Virtual Machine (JVM) is software or a virtual machine that takes .class file as an input and runs java bytecode. Java is machine independent but JVM is machine dependent.   What is Bytecode? When java program is compiled using javac compiler, it is converted into intermediate code known as bytecode. The byte code is stored in .class file. Bytecode contains special instructions that are

Read more

Comparable vs Comparator in Java

Here you will learn about Comparable vs Comparator in Java. Difference between Comparable and Comparator is one of the commonly asked questions in Java interviews. Both the interfaces are used to sort collection objects but still there are some differences between them which I have discussed below. Also Read: Comparable and Comparator Example Comparable vs Comparator in Java S.No Comparable Comparator 1. It is used to sort objects on the basis of only one property at a time. For example if

Read more

Linear Search in Java

Here you will learn about linear search in Java. It is one of the simplest and basic searching algorithm which is also known as sequential search. The targeted element is compared with each element of array until it is found. Its best and worst case time complexity is O (1) and O (n) respectively. Also Read: Binary Search in Java Below program shows that how to implement this algorithm in Java. Program for Linear Search in Java

  Output Enter

Read more

Different Ways to Take Input from User in Java

There are mainly five different ways to take input from user in java using keyboard. 1. Command Line Arguments 2. BufferedReader and InputStreamReader Class 3. DataInputStream Class 4. Console Class 5. Scanner Class   Below I have shared example for each of them.     How to Take Input from User in Java Command Line Arguments It is one of the simplest way to read values from user. It will work only when you are running the program from command

Read more
1 7 8 9 10