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
Server Side Programming Articles - Page 1706 of 2650
1K+ 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
521 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
979 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
938 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
377 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; std_dev = (val_1 - val_2) / val_3; System.out.println("The standard normal deviation is: " + std_dev); } }OutputThe standard normal deviation is: -1.3076923076923077A class named Demo contains the main function, where certain double values are defined, and the formula for standard deviation is applied ((val_1 - val_2) / val_3) on these values and the resultant output is displayed on the console.
3K+ Views
In this article, we will learn how to replace a specific word in a sentence with asterisks using Java. This technique can be useful for obscuring certain words in a text for privacy or censorship purposes. Problem Statement Develop a program in Java that takes a sentence and a word to be censored as input, then outputs the sentence with the specified word replaced by asterisks, while preserving the original format of the sentence. Input This is a sample only, the sky is blue, water is transparent Output This is a ****** only, the sky is blue, water is transparent ... Read More
5K+ Views
In Java, checking if a string contains special characters can be easily done using regular expressions. We will be using the Pattern and Matcher classes from the java.util.regex package, we can efficiently determine whether a string includes any special characters. In this article, we will demonstrate how to use these classes to perform the check and handle the result accordingly. − Problem Statement For a given string write a Java program to check if it contains any special character or not − Input 1 I Love Tutorialspoint Output 1 Special character not found in the string Input 2 ... Read More
189 Views
Following is the Java program for Stooge sort −Example Live Demoimport java.io.*; public class Demo { static void stooge_sort(int my_arr[], int l_val, int h_val){ if (l_val >= h_val) return; if (my_arr[l_val] > my_arr[h_val]){ int temp = my_arr[l_val]; my_arr[l_val] = my_arr[h_val]; my_arr[h_val] = temp; } if (h_val-l_val+1 > 2){ int temp = (h_val-l_val+1) / 3; stooge_sort(my_arr, l_val, h_val-temp); stooge_sort(my_arr, l_val+temp, h_val); ... Read More