AmitDiwan has Published 10744 Articles

Print Single and Multiple variables in Java

AmitDiwan

AmitDiwan

Updated on 14-Jul-2020 06:57:00

3K+ Views

To print single and multiple variables in Java, the code is as follows −Example Live Demopublic class Demo {    public static void main(String args[]){       String name_1 = "Hello";       String name_2 = "World";       System.out.println("Printing single variable");       System.out.printf("%s", name_1);   ... Read More

Java program to convert floating to binary

AmitDiwan

AmitDiwan

Updated on 14-Jul-2020 06:52:56

1K+ Views

To convert floating to binary, the Java code is as follows −Example Live Demoimport java.io.*; public class Demo {    static void decimal_to_bin(int n){       int[] bin_num = new int[50];       int i = 0;       while (n > 0){          bin_num[i] ... Read More

Widening Primitive Conversion in Java

AmitDiwan

AmitDiwan

Updated on 14-Jul-2020 06:51:24

272 Views

Following is an example showing widening primitive conversion −Example Live Demopublic class Demo {    public static void main(String[] args) {       System.out.print("H" + "E");       System.out.print('L');       System.out.print('L');       System.out.print('O');    } }OutputHELLOA class named Demo contains the main function. Here, the ... Read More

Can we call run() method directly instead of start() in Java

AmitDiwan

AmitDiwan

Updated on 14-Jul-2020 06:50:05

416 Views

Yes, we can do that. Let us see an example −Example Live Democlass my_thread extends Thread{    public void run(){       try{          System.out.println ("The thread " + Thread.currentThread().getId() + " is currently running");       }       catch (Exception e){     ... Read More

Memory Consistency Error in Java

AmitDiwan

AmitDiwan

Updated on 14-Jul-2020 06:48:21

583 Views

When the concept of multithreading is implemented, it is possible that changes made by one thread wouldn’t be visible to the other thread. This indicates that the view of each thread is inconsistent with respect to each other. This is known as memory consistency error.CPU might initiate main memory access ... Read More

Thread Interference Error in Java

AmitDiwan

AmitDiwan

Updated on 14-Jul-2020 06:46:02

211 Views

Let us see an example to understand the concept of Thread Interference error −Example Live Demoimport java.io.*; class Demo_instance{    static int val_1 = 6;    void increment_val(){       for(int j=1;j

Java program to List all files in a directory and nested sub-directory - Recursive approach

AmitDiwan

AmitDiwan

Updated on 14-Jul-2020 06:39:02

513 Views

To list all files in a directory and nested sub-directory, the Java program is as follows −Exampleimport java.io.File; public class Demo{    static void print_recursively(File[] my_arr, int my_index, int sub_level){       if(my_index == my_arr.length)       return;       for (int i = 0; i < ... Read More

Static method in Interface in Java

AmitDiwan

AmitDiwan

Updated on 13-Jul-2020 12:31:03

968 Views

To implement static method in Interface, the Java code is as follows −Example Live Demointerface my_interface{    static void static_fun(){       System.out.println("In the newly created static method");    }    void method_override(String str); } public class Demo_interface implements my_interface{    public static void main(String[] args){       Demo_interface ... Read More

Static Control Flow in Java

AmitDiwan

AmitDiwan

Updated on 13-Jul-2020 12:29:19

922 Views

The Static Control Flow identify static members, executes static blocks, and then executes the static main method. Let us see an example −Example Live Demopublic class Demo{    static int a = 97;    public static void main(String[] args){       print();       System.out.println("The main method has completed ... Read More

Java Program for Standard Normal Distribution (SND)

AmitDiwan

AmitDiwan

Updated on 13-Jul-2020 12:25:50

373 Views

Following is the Java program for Standard Normal Distribution −Example Live Demoimport java.io.*; import java.util.*; public class Demo{    public static void main(String[] args){       double std_dev, val_1, val_3, val_2;       val_1 = 68;       val_2 = 102;       val_3 = 26;   ... Read More

Advertisements