uk
Feedback
Java Codes Basic to Advance

Java Codes Basic to Advance

Відкрити в Telegram
2 333
Підписники
Немає даних24 години
-37 днів
-2030 день
Архів дописів
public class Main { public static void main(String[] args) { String message = new String(new int[] {32, 72, 97, 112, 112, 121, 32, 73, 110, 100, 101, 112, 101, 110, 100, 101, 110, 99, 101, 32, 100, 97, 121, 33}, 0, 24); System.out.println("\uD83C\uDDEE\uD83C\uDDF3" + message); } } // @java_Codes_pro

/jv public class Main { public static void main(String[] args) { String message = new String(new int[] {32, 72, 97, 112, 112, 121, 32, 73, 110, 100, 101, 112, 101, 110, 100, 101, 110, 99, 101, 32, 100, 97, 121, 33}, 0, 24); System.out.println("\uD83C\uDDEE\uD83C\uDDF3" + message); } } // @java_Codes_pro

Strings functions 1. length(): Returns the length of a string. 2. toUpperCase(): Converts a string to uppercase. 3. toLowerCase(): Converts a string to lowercase. 4. charAt(index): Returns the character at the specified index of a string. 5. indexOf(searchValue): Returns the index of the first occurrence of a specified value in a string. 6. lastIndexOf(searchValue): Returns the index of the last occurrence of a specified value in a string. 7. substring(startIndex): Returns a substring from a string, starting from the specified index to the end of the string. 8. substring(startIndex, endIndex): Returns a substring from a string, between the specified start and end indexes. 9. replace(oldValue, newValue): Replaces occurrences of a specified value with another value in a string. 10. split(separator): Splits a string into an array of substrings based on the specified separator. 11. trim(): Removes leading and trailing whitespace from a string. 12. startsWith(prefix): Returns true if a string starts with the specified prefix; otherwise, returns false. 13. endsWith(suffix): Returns true if a string ends with the specified suffix; otherwise, returns false. 14. contains(searchValue): Returns true if a string contains the specified value; otherwise, returns false. 15. equals(anotherString): Compares two strings for equality. 16. equalsIgnoreCase(anotherString): Compares two strings for equality, ignoring case differences. @Java_Codes_Pro

// Curried function in java (nested functions) import java.util.function.Function; public class CurryingExample { public static void main(String[] args) { Function> multiply = a -> b -> a * b; // Curried function can be used with partial application Function multiplyByTwo = multiply.apply(2); System.out.println(multiplyByTwo.apply(4)); // Output: 8 // Or it can be invoked with all arguments at once System.out.println(multiply.apply(3).apply(5)); // Output: 15 } }

/jv // Curried function in java (nested functions) import java.util.function.Function; public class CurryingExample { public static void main(String[] args) { Function<Integer, Function<Integer, Integer>> multiply = a -> b -> a * b; // Curried function can be used with partial application Function<Integer, Integer> multiplyByTwo = multiply.apply(2); System.out.println(multiplyByTwo.apply(4)); // Output: 8 // Or it can be invoked with all arguments at once System.out.println(multiply.apply(3).apply(5)); // Output: 15 } }

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.io.PrintWriter; public class GetSongLyrics {     public static void main(String[] args) {         String url = "https://song.panditsiddharth.repl.co/lyrics?song=ram+siya+ram";         try {             URL requestUrl = new URL(url);             HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();             connection.setRequestMethod("GET");             int statusCode = connection.getResponseCode();             BufferedReader reader;             if (statusCode == HttpURLConnection.HTTP_OK) {                 reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));             } else {                 reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));             }             PrintWriter writer = new PrintWriter(System.out);             String line;             while ((line = reader.readLine()) != null) {                 writer.println(line);             }             reader.close();             writer.flush();             connection.disconnect();         } catch (IOException e) {             e.printStackTrace();         }     } }

/jv import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.io.PrintWriter; public class GetSongLyrics {     public static void main(String[] args) {         String url = "https://song.panditsiddharth.repl.co/lyrics?song=ram+siya+ram";         try {             URL requestUrl = new URL(url);             HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();             connection.setRequestMethod("GET");             int statusCode = connection.getResponseCode();             BufferedReader reader;             if (statusCode == HttpURLConnection.HTTP_OK) {                 reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));             } else {                 reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));             }             PrintWriter writer = new PrintWriter(System.out);             String line;             while ((line = reader.readLine()) != null) {                 writer.println(line);             }             reader.close();             writer.flush();             connection.disconnect();         } catch (IOException e) {             e.printStackTrace();         }     } }

// Arrays in Java public class MyClass { public static void main(String args[]) { int arr[] = {2, 3, 6}; //Array declaration and initialization System.out.println(arr[0]); //Showing Array First element } } // @Java_Codes_pro

/jv // Arrays in Java public class MyClass { public static void main(String args[]) { int arr[] = {2, 3, 6}; //Array declaration and initialization System.out.println(arr[0]); //Showing Array First element } } // @Java_Codes_pro

// java basic threads example public class MultithreadingExample {     public static void main(String[] args) {         // Creating and starting two threads         Thread thread1 = new MyThread("Thread 1");         Thread thread2 = new MyThread("Thread 2");         thread1.start();         thread2.start();     } } class MyThread extends Thread {     private String threadName;     public MyThread(String name) {         threadName = name;     }     public void run() {         for (int i = 1; i <= 5; i++) {             System.out.println(threadName + " - Count: " + i);             try {                 Thread.sleep(1000); // Pause for 1 second             } catch (InterruptedException e) {                 e.printStackTrace();             }         }     } } // @Java_Codes_Pro

/jv // java basic threads example public class MultithreadingExample {     public static void main(String[] args) {         // Creating and starting two threads         Thread thread1 = new MyThread("Thread 1");         Thread thread2 = new MyThread("Thread 2");         thread1.start();         thread2.start();     } } class MyThread extends Thread {     private String threadName;     public MyThread(String name) {         threadName = name;     }     public void run() {         for (int i = 1; i <= 5; i++) {             System.out.println(threadName + " - Count: " + i);             try {                 Thread.sleep(1000); // Pause for 1 second             } catch (InterruptedException e) {                 e.printStackTrace();             }         }     } } // @Java_Codes_Pro

Learnt these functions ?

// java string functions part 2 public class StringFunctionsProgram2 { public static void main(String[] args) { // STRING FUNCTIONS - PROGRAM 2 // 1. Trimming leading and trailing whitespace String str1 = " Hello, World! "; String trimmedStr = str1.trim(); System.out.println("Trimmed String: " + trimmedStr); // 2. Splitting a String into an array of substrings String[] splitStr = str1.split(","); System.out.println("Split Strings:"); for (String split : splitStr) { System.out.println(split.trim()); } // 3. Checking if two Strings are equal String str2 = "Hello"; boolean isEqual = str1.equals(str2); System.out.println("Strings are equal: " + isEqual); // 4. Getting the character at a specific index char charAt = str2.charAt(1); System.out.println("Character at index 1: " + charAt); // 5. Checking if a String is empty boolean isEmpty = str2.isEmpty(); System.out.println("Is empty: " + isEmpty); // 6. Removing leading and trailing characters String removedStr = str1.strip(); System.out.println("Removed String: " + removedStr); // 7. Reversing a String StringBuilder reversedStr = new StringBuilder(str1).reverse(); System.out.println("Reversed String: " + reversedStr); // 8. Checking if a String matches a regular expression boolean matchesRegex = str1.matches("Hello.*"); System.out.println("Matches regular expression 'Hello.*': " + matchesRegex); // 9. Formatting a String String formattedStr = String.format("Price: $%.2f", 10.5); System.out.println("Formatted String: " + formattedStr); // 10. Comparing two Strings lexicographically int comparison = str1.compareTo("Goodbye"); System.out.println("Comparison result: " + comparison); } }

/jv // java string functions part 2 public class StringFunctionsProgram2 { public static void main(String[] args) { // STRING FUNCTIONS - PROGRAM 2 // 1. Trimming leading and trailing whitespace String str1 = " Hello, World! "; String trimmedStr = str1.trim(); System.out.println("Trimmed String: " + trimmedStr); // 2. Splitting a String into an array of substrings String[] splitStr = str1.split(","); System.out.println("Split Strings:"); for (String split : splitStr) { System.out.println(split.trim()); } // 3. Checking if two Strings are equal String str2 = "Hello"; boolean isEqual = str1.equals(str2); System.out.println("Strings are equal: " + isEqual); // 4. Getting the character at a specific index char charAt = str2.charAt(1); System.out.println("Character at index 1: " + charAt); // 5. Checking if a String is empty boolean isEmpty = str2.isEmpty(); System.out.println("Is empty: " + isEmpty); // 6. Removing leading and trailing characters String removedStr = str1.strip(); System.out.println("Removed String: " + removedStr); // 7. Reversing a String StringBuilder reversedStr = new StringBuilder(str1).reverse(); System.out.println("Reversed String: " + reversedStr); // 8. Checking if a String matches a regular expression boolean matchesRegex = str1.matches("Hello.*"); System.out.println("Matches regular expression 'Hello.*': " + matchesRegex); // 9. Formatting a String String formattedStr = String.format("Price: $%.2f", 10.5); System.out.println("Formatted String: " + formattedStr); // 10. Comparing two Strings lexicographically int comparison = str1.compareTo("Goodbye"); System.out.println("Comparison result: " + comparison); } }

// java string functions part 1 public class StringFunctionsProgram1 { public static void main(String[] args) { // STRING FUNCTIONS - PROGRAM 1 // 1. Length of the String String str = "Hello, World!"; int length = str.length(); System.out.println("Length of the String: " + length); // 2. Concatenation of Strings String newStr = str.concat(" Welcome"); System.out.println("Concatenated String: " + newStr); // 3. Extracting a Substring String subStr = str.substring(7); System.out.println("Substring: " + subStr); // 4. Converting to Uppercase String upperStr = str.toUpperCase(); System.out.println("Uppercase String: " + upperStr); // 5. Converting to Lowercase String lowerStr = str.toLowerCase(); System.out.println("Lowercase String: " + lowerStr); // 6. Checking if a String starts with a specific prefix boolean startsWith = str.startsWith("Hello"); System.out.println("Starts with 'Hello': " + startsWith); // 7. Checking if a String ends with a specific suffix boolean endsWith = str.endsWith("!"); System.out.println("Ends with '!': " + endsWith); // 8. Finding the index of a specific character int index = str.indexOf("o"); System.out.println("Index of 'o': " + index); // 9. Replacing characters in a String String replacedStr = str.replace("o", "x"); System.out.println("Replaced String: " + replacedStr); // 10. Checking if a String contains a specific sequence of characters boolean contains = str.contains("World"); System.out.println("Contains 'World': " + contains); } }

/jv // java string functions part 1 public class StringFunctionsProgram1 { public static void main(String[] args) { // STRING FUNCTIONS - PROGRAM 1 // 1. Length of the String String str = "Hello, World!"; int length = str.length(); System.out.println("Length of the String: " + length); // 2. Concatenation of Strings String newStr = str.concat(" Welcome"); System.out.println("Concatenated String: " + newStr); // 3. Extracting a Substring String subStr = str.substring(7); System.out.println("Substring: " + subStr); // 4. Converting to Uppercase String upperStr = str.toUpperCase(); System.out.println("Uppercase String: " + upperStr); // 5. Converting to Lowercase String lowerStr = str.toLowerCase(); System.out.println("Lowercase String: " + lowerStr); // 6. Checking if a String starts with a specific prefix boolean startsWith = str.startsWith("Hello"); System.out.println("Starts with 'Hello': " + startsWith); // 7. Checking if a String ends with a specific suffix boolean endsWith = str.endsWith("!"); System.out.println("Ends with '!': " + endsWith); // 8. Finding the index of a specific character int index = str.indexOf("o"); System.out.println("Index of 'o': " + index); // 9. Replacing characters in a String String replacedStr = str.replace("o", "x"); System.out.println("Replaced String: " + replacedStr); // 10. Checking if a String contains a specific sequence of characters boolean contains = str.contains("World"); System.out.println("Contains 'World': " + contains); } }

All Codes @C_Code5 @CPP_Coding @Python_Codes_Pro @Java_Codes_Pro @jsCode0 Diffrent Compiler bots For group @CodeCompiler_Bot For channel @IOChannel_bot For Channel Cmpl @Compiler0bot For inline @cmpbbot info in @LogicBots Discussion @bca_mca_btech

public class DiamondPattern { public static void main(String[] args) { int rows = 5; for (int i = 1; i <= rows; i++) { for (int j = 1; j <= rows - i; j++) { System.out.print(" "); } for (int j = 1; j <= 2 * i - 1; j++) { System.out.print("*"); } System.out.println(); } for (int i = rows - 1; i >= 1; i--) { for (int j = 1; j <= rows - i; j++) { System.out.print(" "); } for (int j = 1; j <= 2 * i - 1; j++) { System.out.print("*"); } System.out.println(); } } } // @Java_Codes_pro

/jv public class DiamondPattern { public static void main(String[] args) { int rows = 5; for (int i = 1; i <= rows; i++) { for (int j = 1; j <= rows - i; j++) { System.out.print(" "); } for (int j = 1; j <= 2 * i - 1; j++) { System.out.print("*"); } System.out.println(); } for (int i = rows - 1; i >= 1; i--) { for (int j = 1; j <= rows - i; j++) { System.out.print(" "); } for (int j = 1; j <= 2 * i - 1; j++) { System.out.print("*"); } System.out.println(); } } } // @Java_Codes_pro

public class StarPyramidPattern { public static void main(String[] args) { int rows = 5; for (int i = 0; i < rows; i++) { for (int j = 0; j < rows - i - 1; j++) { System.out.print(" "); } for (int j = 0; j <= i; j++) { System.out.print("* "); } System.out.println(); } } } // @Java_Codes_Pro