
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

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] = n % 2; n = n / 2; i++; } for (int j = i - 1; j >= 0; j--) System.out.print(bin_num[j]); } public static void main (String[] args){ ... Read More

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 ‘print’ function is used to print specific characters in double quotes and then in single quotes. When the process of widening primitive conversion happens, the presence of ‘+’ operator is a must. This ‘+’ operator expects integer on both the left hand and right hand sides.

417 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){ System.out.println ("The exception has been caught"); } } } public class Main{ public static void main(String[] args){ int n = 6; for (int i=1; i

585 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 in a different order, whereas the threads might access them in a different order.This is usually true when write operation is being performed, thereby avoiding the CPU wait time.The write operation is an atomic one, meaning no other operation would be performed by other threads when a write operation is ... Read More

998 Views
In this article, we will learn how to merge the contents of all the text files in a directory into a single file using Java. It reads the data from each file and writes it into a new file while ensuring all data is stored in an organized manner. You’ll see how to handle files, read their content, and merge them programmatically. File class The java.io package contains the Java File class, which provides an abstract representation of file and directory pathnames. It is commonly used for creating files and directories, searching for files, deleting files, and performing other file-related operations. File ... Read More

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 < sub_level; i++) System.out.print("\t"); if(my_arr[my_index].isFile()) System.out.println(my_arr[my_index].getName()); else if(my_arr[my_index].isDirectory()){ System.out.println("[" + my_arr[my_index].getName() + "]"); print_recursively(my_arr[my_index].listFiles(), 0, sub_level + 1); } ... Read More

972 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 demo_inter = new Demo_interface(); my_interface.static_fun(); demo_inter.method_override("In the override method"); } @Override public void method_override(String str){ System.out.println(str); } }OutputIn the newly created static method In the override methodAn interface is defined, inside which a static function is defined. ... Read More

926 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 executing"); } static{ System.out.println(a); print(); System.out.println("We are inside the first static block"); } public static void print(){ System.out.println(b); } static{ System.out.println("We are inside the second static block"); } ... Read More

5K+ Views
A block of code that is associated with the static keyword is called as static block. This block executes when classloader loads the class. Remember, if your code contains any static block, it will be invoked before the main() method. In this article, we will learn how to create and invoke static blocks in Java along with its use case. But, before that let's understand the static keyword. What is Static Keyword? The static keyword in Java is a non-access modifier. This keyword is used with variables, methods, blocks of code and classes. A class, method or variable declared with ... Read More