- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 2617 Articles for Java
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
60 Views
Joiner provides various methods to handle joining operations on string, objects, etc. Let us see an example −Exampleimport com.google.common.base.Joiner; import java.util.*; public class Demo{ public static void main(String[] args){ String[] my_arr = { "hel", null, "lo", "wo", "r", null, "ld" }; System.out.println("The original array is : "+ Arrays.toString(my_arr)); String my_result = Joiner.on('+').skipNulls().join(my_arr); System.out.println("The joined string is : " + my_result); } }OutputThe original array is [hel, null, lo, wo, r, null, ld] The joined string is hel+lo+wo+r+ldA class named Demo contains the main function, which defines ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ 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); System.out.println("Printing multiple variables"); System.out.printf("First Name: %sLast Name: %s",name_1, name_2); } }OutputPrinting single variable Hello Printing multiple variables First Name: Hello Last Name: WorldA class named Demo contains the main function, which defines two strings. These strings are displayed using the ‘println’ function and using the ‘printf’ function.
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
388 Views
LinkedHashMapHash table and linked list implementation of the Map interface, with predictable iteration order. Let us see an example −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ LinkedHashMap my_set; my_set = new LinkedHashMap(); my_set.put(67, "Joe"); my_set.put(90, "Dev"); my_set.put(null, "Nate"); my_set.put(68, "Sara"); my_set.put(69, "Amal"); my_set.put(null, "Jake"); my_set.put(69, "Ral"); my_set.entrySet().stream().forEach((m) ->{ System.out.println(m.getKey() + " " + m.getValue()); }); } ... Read More
![Deepti S](https://www.tutorialspoint.com/assets/profiles/654803/profile/60_3875308-1684130615.jpg)
190 Views
Java is a powerful and versatile programming language. It is used in various applications. It's known for its reliability, portability, and safety, which makes it a famous desire for developers. Java is likewise exceptionally easy to analyze, which makes it a terrific desire for novices. However, it's critical to remember that simplicity might operate as an obstacle. If you're not mindful, you could be caught by Java's accessibility and neglect to explore the unique opportunities the language offers. Let's have a look at some tips to assist you develop as a Java developer and improve your language proficiency. Tip 1: ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
835 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
200 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.
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
297 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
451 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
527 Views
To merge contents of all the files in a directory, the Java code is as follows −Exampleimport java.io.*; public class Demo{ public static void main(String[] args) throws IOException{ File my_dir = new File("path to place where file is generated"); PrintWriter my_writer = new PrintWriter("The .txt where changes are stored"); String[] file_names = my_dir.list(); for (String file_names : fileNames){ System.out.println("Content read from " + file_names); File my_file = new File(my_dir, file_names); BufferedReader my_reader = new BufferedReader(new ... Read More