Restart system in Java

import java.io.IOException; public class Test { public static void main(String[] args) { try { Runtime.getRuntime().exec(“shutdown -r -t 0”); } catch (IOException e) { e.printStackTrace(); } } }

Shutdown windows system in Java

import java.io.IOException; public class Test { public static void main(String[] args) { try { Runtime.getRuntime().exec(“c:\\Windows\\System32\\shutdown -s -t 0”); } catch (IOException e) { e.printStackTrace(); } } }

Shutdown system in Java

import java.io.IOException; public class Test { public static void main(String[] args) { try { Runtime.getRuntime().exec(“shutdown -s -t 0”); } catch (IOException e) { e.printStackTrace(); } } }

Java Runtime exec() method

import java.io.IOException; public class Test { public static void main(String[] args) { try { Runtime.getRuntime().exec(“notepad”); } catch (IOException e) { e.printStackTrace(); } } }

concurrency issues in java

All threads in java have their own call stack but they may share some shared resources. In case of shared resources visibility and access problems can occur. Visibility problem: Visibility problem occurs when one thread (say first thread) reads a field value which is later updated by some other thread but changes are not guaranteed to … Read more

how hashset works internally in java?

HashSet uses HashMap internally to store its elements. When we create a HashSet, internally a HashMap is created. The elements inserted in HashSet are actually inserted as the keys in HashMap. Kindly click here to look at internal working of HashMap to see how hashset works internally.

How hashmap stores null key?

In Hashmap one null key is allowed and multiple null values are allowed. Since hashcode of null is 0 so null key actually stored at index 0 in hashmap. Hashmap in java actsually created as Array of linkedlist where index in array is find out by hashing on key. package com.w3schools; import java.util.HashMap; import java.util.Map; … Read more

HashMap internal working in java

HashMap: HashMap in java is represents a collection type which can contains the objects/elements in key-value pair form. It extends AbstractMap class and implements the Map interface. It not maintains any order for its elements. It not allowed duplicate values as key. It can have only one null key and multiple null values. HashMap uses … Read more

hashCode and equals method in java

The hashCode() method in java is an Object class method. It returns a hash code value (an integer number) for the object which represents the memory address of the object. It is supported for the benefit of hashtables such as those provided by java.util.Hashtable. Conceptually: The hashCode() is used for bucketing in Hash implementations like HashMap, HashTable, HashSet, etc. The value received from hashCode() is … Read more

Java networking tutorial

Java network programming provides the facility of connecting two or more computing devices together. The devices communicate with each other using either the Transmission Control Protocol (TCP) or the User Datagram Protocol (UDP). The java.net package provides the classes for java network programming. TCP protocol is used by URL, URLConnection, Socket, and ServerSocket classes whereas … Read more