Java Articles

Page 22 of 450

Implementing Checksum Using Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 2K+ Views

Following is the code to implement Checksum using Java −Exampleimport java.util.*; public class Demo{    public static void main(String args[]){       Scanner my_scan = new Scanner(System.in);       System.out.println("Enter the input string ");       String my_in = my_scan.next();       int my_checksum = generate_checksum(my_in);       System.out.println("The checksum that has been generated is " + Integer.toHexString(my_checksum));       System.out.println("Enter the data that needs to be sent to the receiver ");       my_in = my_scan.next();       System.out.println("Enter the checksum that needs to be sent to the receiver ");   ...

Read More

Interesting facts about Increment and Decrement operators in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 248 Views

There are many interesting facts with respect to increment and decrement operators in Java. We will discuss a few of them with examples −The increment and decrement operators can’t be used with the ‘final’ variables. This is due to the fact that variables associated with ‘final’ keyword can’t be changed −Examplepublic class Demo{    public static void main(String[] args){       final int my_val = 34;       int my_val_2 = ++my_val;       System.out.println("The value is :");       System.out.println(my_val_2);    } }Output/Demo.java:6: error: cannot assign a value to final variable my_val int my_val_2 = ...

Read More

Interesting facts about null in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 234 Views

There are many facts associated with null in Java. We will discuss a few of them here with examples −The default value of any reference variable in Java is always null.Examplepublic class Demo{    private static Object my_obj;    public static void main(String args[]){       System.out.println("The default value of object my_obj is : " + my_obj);    } }OutputThe default value of object my_obj is : nullA class named Demo defines a static object and the main function that shows the default value of this pre-defined object.The not equal to (!=) and comparison (==) operators can be used ...

Read More

Is an array a primitive type or an object in Java?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 2K+ Views

Array is considered to be an object in Java. The reason behind this is that an array can be created using the ‘new’ keyword. The ‘new’ keyword/operator is always used to create an object. This is how an array is perceived as an object.The direct parent class or super class of any array is the ‘Object’ class. Every array type in Java belongs to a certain class. This indicates that there are explicit classes for integer array types, float array types, double array types, and so on.Arrays can be dynamically created, and be assigned variables as well.Let us see an ...

Read More

Island of Isolation in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

After an object has been used, it is deallocated from the memory using the Garbage Collector class. The objects are destroyed based on the fact that no reference to that object is present. The Garbage Collector class calls the ‘finalize’ function on the object that needs to be destroyed.What is island of isolation?When two objects ‘a’, and ‘b’ reference each other, and they are not referenced by any other object, it is known as island of isolation.It is a group of objects which reference each other but they are not referenced but other objects of other applications at all.Note − ...

Read More

Iterator vs Collection in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 508 Views

IteratorIt is used in Collection Framework so as to retrieve elements as and when they are required.public interface IteratorIt can be used with the ‘next’ function to move and access the next elements. The ‘remove’ function can be used to remove an element from the data structure.It is quicker in comparison to Collections, since the number of operations associated with Iterator is less.Below is an example of an iterator working with a list −Examplemport java.io.*; import java.util.*; public class Demo{    public static void main(String[] args){       ArrayList my_list = new ArrayList();       my_list.add("Its");     ...

Read More

Java Concurrency – sleep() method

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 465 Views

The sleep functionThis sleep function is used to ensure that the currently executing thread goes to sleep for a specific amount of milliseconds which is passed as a parameter to the function. The thread stops executing for that number of milliseconds.Let us see an exampleExampleimport java.lang.*; public class Demo implements Runnable{    Thread my_t;    public void run(){       for (int i = 0; i < 3; i++){          System.out.println(Thread.currentThread().getName()+ " " + i);          try{             Thread.sleep(100);          }         ...

Read More

Java Lambda Expression with Collections

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 970 Views

Sorting the elements of a list using lambda expression −Exampleimport java.util.*; public class Demo{    public static void main(String[] args){       ArrayList my_arr = new ArrayList();       my_arr.add(190);       my_arr.add(267);       my_arr.add(12);       my_arr.add(0);       System.out.println("Before sorting, elements in the array list are : " + my_arr);       Collections.sort(my_arr, (o1, o2) -> (o1 > o2) ? -1 : (o1 < o2) ? 1 : 0);       System.out.println("After sorting, elements in the array list are : " + my_arr);    } }OutputBefore sorting, elements in ...

Read More

Java Numeric Promotion in Conditional Expression

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 207 Views

The conditional operator (? :) leverages the output of one value (which is a bool) to decide which expression has to be evaluated next. Let us see an example −Exampleimport java.io.*; public class Demo{    public static void main (String[] args){       Object my_obj = true ? new Integer(91) : new Float(89);       System.out.println(my_obj);    } }Output91.0A class named Demo contains the main function. Here, an object instance is defined and if it is true, an integer value is displayed otherwise a float value is displayed. Next, they are printed on the console.When promotional expression is ...

Read More

Java Program for credit card number validation

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 6K+ Views

Given a long number containing digits of a credit card number; the task is to find whether the credit card number is valid or not with a program.For checking a credit card is valid or not, the following are the validations we have to be sure for declaring the result.A credit card’s number must have 13 to 16 digits, it must start with the following digits.All the visa cards start from 4 All the master cards start from 537 is the starting for American express cardsAll the discover cards start from 6Steps to check whether the credit card is valid or ...

Read More
Showing 211–220 of 4,498 articles
« Prev 1 20 21 22 23 24 450 Next »
Advertisements