Java Codes Basic to Advance
2.03K subscribers
4 photos
2 videos
1 file
48 links
Download Telegram
// fetch song lyrics from url

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();
        }
    }
} // @Java_Codes_Pro
👍1
// 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
}
} // @Java_Codes_Pro
👏1
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 #share #support
👍7🥰1
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(message);
}
}

// @java_Codes_pro
Java Codes Basic to Advance pinned «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):…»
Java Codes Basic to Advance pinned «Notes 📝 : Telegram.me/BCA_Sem1_Notes Telegram.me/BCA_Sem2_Notes Telegram.me/BCA_Sem3_Notes Telegram.me/BCA_Sem4_Notes Telegram.me/BCA_Sem5_Notes Telegram.me/BCA_Sem6_Notes Code practice Channels: Telegram.me/C_Codes_pro Telegram.me/CPP_Codes_pro Telegram…»
How to run manually without clicking on show button

Click on run button here [in code]

Go to @compiler0bot

Type /start run

You will see code is running there which you clicked here 😉
इस बाॅट में कोड रन करना सीखें
Learn how to run code in this bot.

@CodeCompiler_Bot

लाभ (Advantage):
आप किसी को भी रियल टाइम में कोड का आउटपुट दिखा सकते हो, जिससे अगर आपके कोड में कोई गलती है तो वह भी सरलता से एक दूसरे से डिस्कस करके साॅल्व कर सकते हो।

See features written in pic ☝️☝️

You can show the output of the code to anyone in real time, so that if there is any mistake in your code, they can easily solve it by discussing with each other.

Full tutorial: https://t.me/logicBots/147
// Atithmetic Operations in Java
public class MyClass {
public static void main(String args[]) {

// declaring variables
int add, sub, div, mul, rem;

// Declaring two varables
int x=4;
int y=2;

// performing Operations
add = x+y; // Addition
sub = x-y; // Subtraction
div = x/y; // Division
mul = x+y; // Multiply
rem= x%y; // reminder

// Showing results
System.out.println("4 + 2 = "+ add);
System.out.println("4 - 2 = "+ sub);
System.out.println("4 * 2 = "+ mul);
System.out.println("4 / 2 = "+ div);
System.out.println("4 % 2 = "+ rem);
}
}
👍1
Learn in 55 seconds
How to run codes in telegram 👇
https://t.me/logicBots/163
👍1
// Factotial from recursion in java
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
 
Scanner s = new Scanner(System.in);
System.out.print("Enter Number: " );
int n = s.nextInt();
if(n>26)
System.out.print("Please enter number less than 25\n" );
else{
 
System.out.println("Showing factorial for "+ n + " Number" );
System.out.print("\n" +Main.f(n));
}
}

// Factorial value calculation + series printing
static long f(long n){
  if (n==1){
   System.out.print(n);
     return n;
  }
  else{
     System.out.print(n + " * ");
     return n*f(n-1);
   }
}

}  // @Java_Codes_Pro
👍4
Ab aap log apna khud ka Compiler bot bana sakte hain easily 🥳🥳🔥
Apne manpasand name aur username se

Create your own
By using @CloneCompiler_bot

See full details: Click Here
👍2
// Run and see bharateey flag clolours

public class Main{
public static void main(String[] args){

System.out.println(" Ye Hain\n bharat ke flag\n\"ke colours\"");
}
}
You can practice your codes in
@codeCompiler_bot

It supports short coding 👇

For upper part of java you can simply write

"Start"


And for lower part

"End"


Then in middle you can write java code

But one thing more
You don't need to write big print statement like
System.out.println();


Just write
pt

And then your code without parenthesis

Full example
"Start"
Pt "hi this is mine short java"
"End"

You can run this code on @codeCompiler_bot using
/jv command

You can convert this code in real java code by using
/rjv command

Here is more short code example

import java.util.Scanner;

"Start"
Scanner scanner = new Scanner(System.in);

Pt"Enter an integer: "
int number = scanner.nextInt();

Pt"You entered: " + number

scanner.close();

"End"

See practical example 👇
t.me/LogicB_Support/11005

Is it easy give reactions or ask questions 👇
👍2🥰1
It's discussion group is now public
Join @java_group_pro
Select your group/channel/service
t.me/Sid_info/69
40+ String methods of java 👇
(Share)