Thursday, June 5, 2025

Resep Makanan

Telur Rebus : Telur + Kecap + Garam + air, campur semua tunggu matang 1 jam.
Mie : Terigu + Bawang Bombay + Bawang Putih yang di Haluskan + Air + Garam + Penyedap Makanan, Lalu aduk semua, lalu gilingkan tepung menjadi bentuk mie.
Doodly Ball : Tepung Beras + Bawang Putih + Bawang Merah + Gula Sedikit + Saus Tiram +Garam + Penyedap Makanan + Air untuk Tambahan Tambah Kikil Ayam, Aduk semua, bentuk dari adonan tepung menjadi bulat dan rebus hingga Matang.
Susu cokelat panas : Susu + Buah Cokelat + Garam Sedikit + Gula + Krimer, Buah cokelat di belah dan ambil bijihnya lalu kupas bijih nya hingga ada buah cokelatnya, panas buah cokelat yang telah di kupas, lalu susu tambahkan cokelat secukupnya di tambahkan garam sedikit, tambahkan gula,krimer tambahkan buah cokelat yang sudah di kupas pakai buah cokelat secukupnya, aduk hingga rata.
Kranyon : Tepung + Gula + Garam sedikit + Kacang + air, Aduk semua hingga rata, lalu kukus hingga matang.
Susu Kacang Ijo : Susu + Kacang Hijau + Garam Sedikit + Gula, Kacang hijau di tumbuk hingga halus, campurkan susu dan kacang hijau dan garam sedikit begitupun gula, aduk hingga merata.
Kue Kelapa : Tepung + Buah Kelapa + Garam Sedikit + Gula + Air, campurkan dari air buah kelapa dengan air,tepung,garam sedikit,gula dan pisahkan putih kelapa, aduk sampai merata, putih kelapa boleh di serut lalu campurkan ke adonan lalu bentukkan sesuka hati, lalu kukus adonan.
Ikan Pedas : Ikan + Jeruk Nipis + Garam Sedikit + Cabe + Air + Gula sedikit 1 capit tangan. Campurkan ikan dengan air,cabe,garam,gula, masak hingga matang campurkan peras jeruk nipis.
Mie instant : Mie + Air + Daging ayam di potong kecil-kecil + garam + bawang bombay + rumput sedikit + penyedap makanan, masak campur semua hingga matang.
Es jeruk : Jeruk + Es keras + Gula + Garam Sedikit + Krimer Sedikit + Air, Buang bijihnya dan haluskan buahnya lalu campur semua dan aduk hingga merata.
Es Buah : Buah apa saja + Gula + Garam Sedikit + Krimer Selera + Air + Es Keras, Haluskan Buah dan buang bijihnya, campurkan semua hingga merata.
Nasi Goreng : Nasi + Kecap + Bumbu Penyedap + Gula Sedikit + Garam cukup + Bawang Merah + Bawang Putih + air sedikit, potong semua bawang lalu campurkan semua, masak hingga matang.
Mie Goreng : Mie + Bawang Merah + Bawang Putih + Garam + Air Sedikit + Merica, Iriskan semua bawang lalu campurkan semua, masak hingga matang.
Saus : Air + Garam Sedikit + Cabe, Tumbuk hingga halus dan campurkan semua hingga merata.
Daging Burger : Daging + Tepung + Tepung Beras + Bawang Merah + Air + Garam + Kecap saus Tiram, tumbuk semua hingga merata, lalu kukus warnanya berubah, lalu masak hingga matang.
Roti : Tepung + Gula + Garam + Air, Campurkan semua lalu kukus.

Tuesday, June 3, 2025

Investasi dari Leluhur

Bukan penipuan. Bukan mencari tumbal. Saya mencairkan uang dimana anda invest lalu saya berikan yang sesuai dibawah ini :
𝐏𝐋𝐀𝐍 𝐁𝐀𝐒𝐈𝐂 📊
𝐍𝐎𝐌𝐈𝐍𝐀𝐋 𝐃𝐀𝐍 𝐊𝐄𝐔𝐍𝐓𝐔𝐍𝐆𝐀𝐍
1.000.000 = 15.000.000/bulan
2.000.000 = 25.000.000/bulan
3.000.000 = 35.000.000/bulan
4.000.000 = 45.000.000/bulan

Harga jasa = Rp. 200.000
Profit diatas akan di dapat selama di antara 1 Bulan. Di Withdraw setiap 7 hari sampai 1 bulan, jadi 5x pendapatan dari total di atas.

𝐏𝐋𝐀𝐍 𝐒𝐈𝐋𝐕𝐄𝐑 📊
𝐍𝐎𝐌𝐈𝐍𝐀𝐋 𝐃𝐀𝐍 𝐊𝐄𝐔𝐍𝐓𝐔𝐍𝐆𝐀𝐍 
5.000.000 = 50.000.000/bulan
6.000.000 = 60.000.000/bulan
7.000.000 = 70.000.000/bulan
8.000.000 = 80.000.000/bulan
9.000.000 = 90.000.000/bulan

Harga jasa = Rp. 200.000
Profit diatas akan di dapat selama di antara 1 Bulan. Di Withdraw setiap 7 hari sampai 1 bulan, jadi 5x pendapatan dari total di atas.

𝐏𝐋𝐀𝐍 𝐆𝐎𝐋𝐃 📊
𝐍𝐎𝐌𝐈𝐍𝐀𝐋 𝐃𝐀𝐍 𝐊𝐄𝐔𝐍𝐓𝐔𝐍𝐆𝐀𝐍
10.000.000 = 30.000.000/bulan
20.000.000 = 60.000.000/bulan
30.000.000 = 90.000.000/bulan
40.000.000 = 120.000.000/bulan

Harga jasa = Rp. 200.000
Profit diatas akan di dapat selama di antara 1 Bulan. Di Withdraw setiap 7 hari sampai 1 bulan, jadi 5x pendapatan dari total di atas.

Contoh : Anda pesan 10 juta ditambah 200ribu menjadi 10,2 juta maka akan mendapat selama 1 bulan 30juta. Di withdraw selama 7 hari akan dapat 7,5 juta.

𝐉𝐈𝐊𝐀 𝐌𝐈𝐍𝐀𝐓 𝐉𝐎𝐈𝐍 𝐈𝐍𝐕𝐄𝐒𝐓𝐀𝐒𝐈
𝐈𝐬𝐢 𝐃𝐚𝐭𝐚𝐧𝐲𝐚 𝐋𝐚𝐥𝐮 𝐤𝐢𝐫𝐢𝐦 𝐊𝐞 𝐀𝐝𝐦𝐢𝐧
𝐍𝐚𝐦𝐚 : 
𝐍𝐨.𝐇𝐩 :
𝐄𝐦𝐚𝐢𝐥 : 
𝐁𝐚𝐧𝐤 : 
𝐍𝐨.𝐑𝐞𝐤 : 
Nama dari Rekening Bank :
𝐉𝐮𝐦𝐥𝐚𝐡 𝐈𝐧𝐯𝐞𝐬𝐭𝐚𝐬𝐢 : 
Profit Investasi dari di atas :

𝐁𝐄𝐋𝐔𝐌 𝐏𝐀𝐇𝐀𝐌? 𝐁𝐈𝐒𝐀 𝐂𝐇𝐀𝐓 
ATAU YANG MAU JOIN SILAHKAN.
Click ➡️Modal Usaha

Saturday, May 31, 2025

[JAVA] EXPORT EXE FILE NO JAR

Within the JAR file, you can store the EXE file.
Upon application startup, the Java code extracts the EXE file to a temporary directory.
Use System.getProperty("java.io.tmpdir") to get the temporary directory path.
Then, the Java application can execute the extracted EXE file using Runtime.getRuntime().exec().
Note that this approach requires careful handling of file permissions and temporary file cleanup.

[JAVA] SERVER MAIL

Java applications can send emails using the JavaMail API, which provides a platform-independent framework for building mail and messaging applications. This API requires a connection to an SMTP server to send emails.
Key Concepts:
JavaMail API:
This is the core library for sending emails in Java. It provides classes for creating, sending, and receiving emails.
SMTP Server:
The Simple Mail Transfer Protocol (SMTP) server is responsible for sending emails. You need the server address, port, and authentication credentials to use it. Common SMTP servers include Gmail, Outlook, and others.
Session:
A JavaMail Session object represents a connection to a mail server. It is used to create email messages.
Message:
A Message object represents an email message. You set the sender, recipient, subject, and body of the email using this object.
Transport:
The Transport class is used to send the message.
Steps to Send Email:
Add Dependencies: Include the necessary JavaMail API dependency in your project. For example, with Maven:
Kode

    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>jakarta.mail</artifactId>
        <version>2.0.1</version>
    </dependency>
Configure Properties: Set up properties for the SMTP server, such as the host address, port, and authentication details.
Java

    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.example.com");
    props.put("mail.smtp.port", "587");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
Create Session: Create a Session object using the properties and authentication.
Java

    Session session = Session.getInstance(props, new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("your_email@example.com", "your_password");
        }
    });
Create Message: Create a MimeMessage object and set the sender, recipient, subject, and body. 
Java

    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress("your_email@example.com"));
    message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("recipient@example.com"));
    message.setSubject("Email Subject");
    message.setText("Email Body");
Send Message: Use the Transport class to send the message.
Java

    Transport.send(message);
Additional Considerations:
Attachments: Use MimeBodyPart and MimeMultipart to add attachments to emails.
HTML Content: Set the content type of the message to "text/html" to send HTML emails.
Gmail: For Gmail, you might need to enable "less secure apps" or use OAuth2 for authentication.
Spring Boot: Spring Boot provides a JavaMailSender to simplify email sending.
Email APIs: Consider using third-party email APIs for more advanced features.
By following these steps and using the JavaMail API, you can integrate email functionality into your Java applications.

[JAVA] SEARCH READ DATA FROM RUN FILE

search and read from a file in Java, you can use several classes and methods. Here's a breakdown of common approaches:
1. Using Scanner:
The Scanner class is suitable for reading formatted data, line by line, or token by token.
It can be used with a File object to read from a file.
You can use methods like nextLine(), nextInt(), next(), etc., to read different types of data.
You can use hasNextLine() to check if there are more lines to read.
Java

   import java.io.File;
   import java.io.FileNotFoundException;
   import java.util.Scanner;

   public class ReadFile {
       public static void main(String[] args) {
           File file = new File("your_file.txt"); // Replace with your file path
           try (Scanner scanner = new Scanner(file)) {
               while (scanner.hasNextLine()) {
                   String line = scanner.nextLine();
                   if (line.contains("search_term")) { // Replace with your search term
                       System.out.println("Found: " + line);
                   }
               }
           } catch (FileNotFoundException e) {
               System.out.println("File not found: " + e.getMessage());
           }
       }
   }
2. Using BufferedReader:
BufferedReader is efficient for reading text files line by line.
It provides buffering for faster reading.
You can use the readLine() method to read a line at a time and check for null to identify the end of the file.
Java

   import java.io.BufferedReader;
   import java.io.FileReader;
   import java.io.IOException;

   public class ReadFile {
       public static void main(String[] args) {
           String filePath = "your_file.txt"; // Replace with your file path
           try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
               String line;
               while ((line = reader.readLine()) != null) {
                   if (line.contains("search_term")) { // Replace with your search term
                       System.out.println("Found: " + line);
                   }
               }
           } catch (IOException e) {
               System.out.println("Error reading file: " + e.getMessage());
           }
       }
   }
3. Using Files (NIO):
The Files class from the java.nio.file package offers more modern ways to handle files.
Files.readAllLines() reads all lines of a file into a List<String>.
Files.lines() returns a Stream<String>, which can be used for more advanced processing.
Java

   import java.io.IOException;
   import java.nio.file.Files;
   import java.nio.file.Path;
   import java.nio.file.Paths;
   import java.util.List;
   import java.util.stream.Stream;

   public class ReadFile {
       public static void main(String[] args) {
           Path filePath = Paths.get("your_file.txt"); // Replace with your file path
           try {
               // Using readAllLines
               List<String> lines = Files.readAllLines(filePath);
               for (String line : lines) {
                   if (line.contains("search_term")) { // Replace with your search term
                       System.out.println("Found: " + line);
                   }
               }

               // Using lines stream
               try (Stream<String> stream = Files.lines(filePath)) {
                   stream.filter(line -> line.contains("search_term")) // Replace with your search term
                           .forEach(line -> System.out.println("Found: " + line));
               }
           } catch (IOException e) {
               System.out.println("Error reading file: " + e.getMessage());
           }
       }
   }
Key points:
File Path: Replace "your_file.txt" with the actual path to your file.
Search Term: Replace "search_term" with the word or phrase you want to find.
Error Handling: Use try-catch blocks to handle potential FileNotFoundException or IOException
File Existence: You can use File.exists() before attempting to read to check if the file exists.
Resource Management: Use try-with-resources to ensure that resources like Scanner, BufferedReader, and streams are closed automatically.
Choosing the Right Method:
Scanner is good for formatted input or when you need to read tokens/words.
BufferedReader is efficient for line-by-line reading.
Files (NIO) is more modern and flexible, especially for larger files or when you want to use streams.

[JAVA] READ FILE FROM RUN

file in Java involves using classes from the java.io and java.nio.file packages. Here's a breakdown of common approaches:
1. Using BufferedReader:
This is a common way to read a file line by line.
It's efficient for larger text files due to buffering.
You'll need to handle potential IOExceptions. 
Java

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class ReadFile {
    public static void main(String[] args) {
        String filePath = "path/to/your/file.txt"; // Replace with your file path
        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            System.err.println("Error reading file: " + e.getMessage());
        }
    }
}
The try-with-resources statement ensures the reader is closed automatically. 
reader.readLine() reads a line, returning null at the end of the file.
2. Using Files.readAllLines() (Java 7+)
This method reads all lines from a file into a List<String>.
It's convenient for smaller files.
It also requires handling IOExceptions.
Java

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

public class ReadFile {
    public static void main(String[] args) {
        Path filePath = Paths.get("path/to/your/file.txt"); // Replace with your file path
        try {
            List<String> lines = Files.readAllLines(filePath);
            for (String line : lines) {
                System.out.println(line);
            }
        } catch (IOException e) {
            System.err.println("Error reading file: " + e.getMessage());
        }
    }
}
3. Using Scanner:
Scanner can be used to read from various input sources, including files.
It can read line by line or token by token.
Java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class ReadFile {
    public static void main(String[] args) {
        File file = new File("path/to/your/file.txt"); // Replace with your file path
        try (Scanner scanner = new Scanner(file)) {
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                System.out.println(line);
            }
        } catch (FileNotFoundException e) {
            System.err.println("Error reading file: " + e.getMessage());
        }
    }
}
The try-with-resources statement ensures the scanner is closed.
4. Reading Character by Character:
You can use FileReader to read character by character, this method is useful if you need to process the file at a character level.
Java

import java.io.FileReader;
import java.io.IOException;

public class ReadFile {
    public static void main(String[] args) {
        String filePath = "path/to/your/file.txt"; // Replace with your file path
        try (FileReader reader = new FileReader(filePath)) {
            int character;
            while ((character = reader.read()) != -1) {
                System.out.print((char) character);
            }
        } catch (IOException e) {
            System.err.println("Error reading file: " + e.getMessage());
        }
    }
}
Important Considerations:
File Paths: Use correct file paths, relative or absolute.
Error Handling: Always handle potential IOExceptions using try-catch blocks.
Resource Management: Close resources (like readers and scanners) in a finally block or using try-with-resources to prevent resource leaks.
File Encoding: Be mindful of file encoding (e.g., UTF-8) when reading text files. You can specify the character set when creating a FileReader or BufferedReader.
Command Line Arguments: If the file path is provided as a command-line argument, access it through the args array.
Choose the method that best suits your specific needs and file size. BufferedReader and Files.readAllLines() are generally preferred for most cases.

[JAVA] READ FILE EXE

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    
    public class ReadExe {
        public static void main(String[] args) {
            File file = new File("path/to/your/executable.exe");
            try (FileInputStream fis = new FileInputStream(file)) {
                int byteRead;
                while ((byteRead = fis.read()) != -1) {
                    System.out.print(Integer.toHexString(byteRead & 0xFF) + " "); // Print as hex
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    import java.io.File;
    import java.io.IOException;
    
    public class ExecuteExe {
        public static void main(String[] args) {
            String exePath = "path/to/your/executable.exe";
            try {
                Process process = Runtime.getRuntime().exec(exePath);
                process.waitFor(); // Wait for the process to complete
                System.out.println("Executable finished with exit code: " + process.exitValue());
            } catch (IOException | InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

[JAVA] READ URL LINK

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

public class ReadFileFromURL {
    public static void main(String[] args) {
        String urlString = "http://www.puzzlers.org/pub/wordlists/pocket.txt"; // Replace with your URL

        try {
            URL url = new URL(urlString);
            InputStream inputStream = url.openStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
            reader.close();
            inputStream.close();
        } catch (Exception e) {
            System.err.println("Error reading from URL: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

[JAVA] CREATE WEB DOMAIN SERVER

URL link in Java, you can utilize the java.net.URL class, which represents a Uniform Resource Locator. Here's how you can work with URLs in Java:
1. Creating a URL Object:
  • You can create a URL object by providing a string representation of the URL.
  • Example:
Java
     try {         URL url = new URL("http://www.example.com");     } catch (MalformedURLException e) {         // Handle the exception if the URL is invalid         e.printStackTrace();     }
  • It's recommended to use java.net.URI to parse or construct a URL instead of the deprecated URL constructors.
2. Connecting to the URL:
  • To establish a connection, use the openConnection() method of the URL object, which returns a URLConnection object.
  • Example:
Java
     try {         URL url = new URL("http://www.example.com");         URLConnection connection = url.openConnection();         connection.connect(); // Initiates the connection     } catch (MalformedURLException | IOException e) {         e.printStackTrace();     }
3. Reading Data from the URL:
  • You can read data from the URL using the getInputStream() method of the URLConnection object, which returns an InputStream.
  • Example:
Java
     try {         URL url = new URL("http://www.example.com");         URLConnection connection = url.openConnection();         InputStream inputStream = connection.getInputStream();         BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));         String line;         while ((line = reader.readLine()) != null) {             System.out.println(line);         }         reader.close();         inputStream.close();     } catch (MalformedURLException | IOException e) {         e.printStackTrace();     }
4. Sending HTTP Requests:
  • For more advanced interactions like sending HTTP GET or POST requests, use HttpURLConnection.
  • Example:
Java
     try {         URL url = new URL("http://www.example.com/api");         HttpURLConnection connection = (HttpURLConnection) url.openConnection();         connection.setRequestMethod("GET"); // Or "POST"         int responseCode = connection.getResponseCode();         if (responseCode == HttpURLConnection.HTTP_OK) {             // Read response         }         connection.disconnect();     } catch (MalformedURLException | IOException e) {         e.printStackTrace();     }
  • Set request properties using setRequestProperty() and handle the response accordingly.
5. Other URL Operations:
  • You can obtain different parts of the URL such as the protocol, host, port, and file using methods like getProtocol()getHost()getPort(), and getFile().
  • You can also extract the reference part (fragment) of the URL using getRef().
6. Working with Local Files:
  • To use a local file as a URL, you can create a URL object using the file path.
  • Example:
Java
     try {         URL fileUrl = new URL("file:///path/to/your/file.txt");     } catch (MalformedURLException e) {         e.printStackTrace();     }
  • Be mindful of path separators and character escaping when dealing with local files.
Important Considerations:
  • Remember to handle MalformedURLException when creating URL objects, and IOException when connecting to or reading from URLs.
  • Consider using libraries like Apache HttpClient for more robust HTTP interactions.
  • When working with server-side applications, web servers like Apache Tomcat can be used to handle requests.

[JAVA] EMAIL SEND

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class EmailSender {
    public static void main(String[] args) {
        String to = "recipient@example.com";
        String from = "sender@example.com";
        String host = "smtp.example.com";
        String username = "your_username";
        String password = "your_password";

        Properties properties = new Properties();
        properties.put("mail.smtp.host", host);
        properties.put("mail.smtp.port", "587"); // or 465 for SSL
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.starttls.enable", "true"); // for TLS

        Session session = Session.getInstance(properties, new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        });

        try {
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            message.setSubject("Test Email");
            message.setText("This is a test email.");

            Transport.send(message);
            System.out.println("Email sent successfully!");
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
}

[JAVA] INHERITANCE

class Animal {
    String name;
    public void eat() {
        System.out.println("Animal is eating");
    }
}

class Dog extends Animal {
    public void bark() {
        System.out.println("Dog is barking");
    }
}

public class Main {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.name = "Buddy";
        dog.eat(); // Inherited from Animal
        dog.bark(); // Specific to Dog
    }
}

[JAVA] PAINT EXAMPLE SIMPLE

import java.util.Arrays;

public class SortString {
    public static void main(String[] args) {
        String inputString = "javaexample";
        char[] charArray = inputString.toCharArray();

        Arrays.sort(charArray);

        String sortedString = new String(charArray);
        System.out.println("Original String: " + inputString);
        System.out.println("Sorted String: " + sortedString);
    }
}

[JAVA] PAUSE AUDIO

import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;

public class AudioPlayer {

    private Clip clip;
    private long clipTime;

    public void loadAudio(String filePath) throws LineUnavailableException, IOException, UnsupportedAudioFileException {
        File audioFile = new File(filePath);
        AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);
        clip = AudioSystem.getClip();
        clip.open(audioStream);
    }

    public void play() {
        clip.start();
    }

    public void pause() {
        clipTime = clip.getMicrosecondPosition();
        clip.stop();
    }

    public void resume() {
        clip.setMicrosecondPosition(clipTime);
        clip.start();
    }

    public void stop() {
        clip.stop();
        clip.close();
    }

    public static void main(String[] args) {
        AudioPlayer player = new AudioPlayer();
        try {
            player.loadAudio("path/to/your/audio.wav"); // Replace with your audio file path
            player.play();

            // Simulate pausing after 2 seconds
            Thread.sleep(2000);
            player.pause();
            System.out.println("Audio paused");

            // Simulate resuming after 2 seconds
            Thread.sleep(2000);
            player.resume();
            System.out.println("Audio resumed");

            // Let the audio play for 5 seconds
            Thread.sleep(5000);
            player.stop();
            System.out.println("Audio stopped");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

[JAVA] SORT by A to Z from String

import java.util.Arrays;

public class SortString {
    public static void main(String[] args) {
        String inputString = "javaexample";
        char[] charArray = inputString.toCharArray();

        Arrays.sort(charArray);

        String sortedString = new String(charArray);
        System.out.println("Original String: " + inputString);
        System.out.println("Sorted String: " + sortedString);
    }
}

[JAVA] JAVA AUTO DRAWING IMAGE FROM IMAGE

import javax.imageio.ImageIO;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class AutoDrawImage {

    public static void main(String[] args) {
        try {
            // Load the source image
            BufferedImage sourceImage = ImageIO.read(new File("path/to/your/source/image.jpg"));

            // Create a destination image
            BufferedImage destinationImage = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);

            // Get the graphics context
            Graphics2D g2d = destinationImage.createGraphics();

            // Draw the source image onto the destination
            g2d.drawImage(sourceImage, 0, 0, null);
            g2d.dispose();

            // Save the result
            ImageIO.write(destinationImage, "png", new File("path/to/your/output/image.png"));
            System.out.println("Image drawn and saved successfully!");

        } catch (IOException e) {
            System.out.println("Error: " + e.getMessage());
        }
    }
}

[JAVA] MAXIMAZE SIZE FORM

     import javax.swing.JFrame;
     import java.awt.Frame;

     public class MaximizeJFrame {
         public static void main(String[] args) {
             JFrame frame = new JFrame("My Frame");
             frame.setSize(400, 300); // Initial size
             frame.setVisible(true);

             // Maximize the frame
             frame.setExtendedState(Frame.MAXIMIZED_BOTH);
         }
     }

     import javax.swing.JFrame;
     import java.awt.Toolkit;
     import java.awt.Dimension;

     public class MaximizeJFrame {
         public static void main(String[] args) {
             JFrame frame = new JFrame("My Frame");
             frame.setVisible(true);

             // Get screen dimensions
             Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
             frame.setSize(screenSize); // Set frame size to screen size
         }
     }

[JAVA] Upload file URL

    import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

public class FileUploader {

    public static void main(String[] args) {
        String uploadUrl = "YOUR_UPLOAD_URL";
        File fileToUpload = new File("YOUR_FILE_PATH");

        try {
            URL url = new URL(uploadUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setDoOutput(true);
            connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");

            try (OutputStream outputStream = connection.getOutputStream();
                 FileInputStream fileInputStream = new FileInputStream(fileToUpload)) {
                
                // Write the multipart form data boundary
                String boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW";
                outputStream.write(("--" + boundary + "\r\n").getBytes());
                outputStream.write(("Content-Disposition: form-data; name=\"file\"; filename=\"" + fileToUpload.getName() + "\"\r\n").getBytes());
                outputStream.write(("Content-Type: application/octet-stream\r\n\r\n").getBytes());

                // Write file content
                byte[] buffer = new byte[4096];
                int bytesRead;
                while ((bytesRead = fileInputStream.read(buffer)) != -1) {
                    outputStream.write(buffer, 0, bytesRead);
                }

                // Write the closing boundary
                outputStream.write(("\r\n--" + boundary + "--\r\n").getBytes());
            }
            
            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);

            if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED) {
                System.out.println("File uploaded successfully.");
            } else {
                System.out.println("File upload failed.");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

[JAVA] CAMERA

import com.github.sarxos.webcam.Webcam;
    import javax.imageio.ImageIO;
    import java.io.File;
    import java.io.IOException;

    public class CameraExample {
        public static void main(String[] args) throws IOException {
            Webcam webcam = Webcam.getDefault();
            webcam.open();
            ImageIO.write(webcam.getImage(), "PNG", new File("capture.png"));
            webcam.close();
        }
    }

[JAVA] VOLUME AUDIO

import javax.sound.sampled.*;

public class VolumeControl {
    public static void main(String[] args) {
        try {
            // Load an audio file
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(VolumeControl.class.getResource("audio.wav"));
            // Get a clip
            Clip clip = AudioSystem.getClip();
            // Open the clip
            clip.open(audioInputStream);
            // Get the master gain control
            FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);

            // Set the volume (example: 50% of the maximum)
            float maxGain = gainControl.getMaximum();
            float minGain = gainControl.getMinimum();
            float range = maxGain - minGain;
            float volume = minGain + (range * 0.5f); // 50%
            gainControl.setValue(volume);

            // Start playing
            clip.start();

            // Keep the program running while the audio plays
            Thread.sleep(clip.getMicrosecondLength() / 1000);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

[JAVA] PROVIDER

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
    }

[JAVA] PROXY

   Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy_host_name", proxy_port_number));
    URL url = new URL("your_url");
    URLConnection urlConnection = url.openConnection(proxy);

[JAVA] READ HEX from File

import java.io.FileInputStream;
import java.io.IOException;

public class HexFileReader {

    public static byte[] readFileBytes(String filePath) throws IOException {
        FileInputStream fis = new FileInputStream(filePath);
        byte[] fileBytes = fis.readAllBytes();
        fis.close();
        return fileBytes;
    }

    public static String bytesToHex(byte[] bytes) {
      StringBuilder hexString = new StringBuilder();
      for (byte b : bytes) {
          hexString.append(String.format("%02x", b & 0xFF));
      }
      return hexString.toString();
    }

    public static void main(String[] args) {
        String filePath = "path/to/your/file.txt"; // Replace with your file path
        try {
            byte[] fileBytes = readFileBytes(filePath);
            String hexString = bytesToHex(fileBytes);
            System.out.println("Hexadecimal representation:\n" + hexString);
        } catch (IOException e) {
            System.err.println("Error reading file: " + e.getMessage());
        }
    }
}

[JAVA] HEX from File

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.apache.commons.codec.binary.Hex;

public class HexFileUtil {

    public static void main(String[] args) {
        String filePath = "path/to/your/file.txt";

        try {
            // Example 1: Read and convert hex string to byte array
            String hexString = Files.readString(Paths.get(filePath)).trim();
            byte[] byteArray = hexStringToByteArray(hexString);
            System.out.println("Byte array from hex string: " + java.util.Arrays.toString(byteArray));

            // Example 2: Read file as bytes and convert to hex string
            byte[] fileBytes = Files.readAllBytes(Paths.get(filePath));
            String hexStringFromFile = byteArrayToHexString(fileBytes);
            System.out.println("Hex string from file bytes: " + hexStringFromFile);


             // Example 3: Read file as bytes and convert to hex string using Apache Commons Codec
             byte[] fileBytes2 = Files.readAllBytes(Paths.get(filePath));
             String hexStringFromBytes = Hex.encodeHexString(fileBytes2);
             System.out.println("Hex string from file bytes using Apache Commons Codec: " + hexStringFromBytes);


            // Example 4: Read file and print it in hex representation using FileInputStream

            printHexStream(new FileInputStream(filePath), 16);

        } catch (IOException e) {
            System.err.println("Error reading file: " + e.getMessage());
        }
    }


    public static void printHexStream(final FileInputStream inputStream, final int numberOfColumns) throws IOException{
         long streamPtr=0;
         while (inputStream.available() > 0) {
             final long col = streamPtr++ % numberOfColumns;
             System.out.printf("%02x ",inputStream.read());
             if (col == (numberOfColumns-1)) {
                 System.out.printf("\n");
             }
         }
    }

    public static byte[] hexStringToByteArray(String hexString) {
        int len = hexString.length();
        byte[] data = new byte[len / 2];
        for (int i = 0; i < len; i += 2) {
            data[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4)
                                 + Character.digit(hexString.charAt(i + 1), 16));
        }
        return data;
    }

    public static String byteArrayToHexString(byte[] bytes) {
        StringBuilder sb = new StringBuilder();
        for (byte b : bytes) {
            sb.append(String.format("%02x", b));
        }
        return sb.toString();
    }
}

[JAVA] PRINT DATA

import java.awt.*;
import java.awt.print.*;

public class PrintExample implements Printable {
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
        if (pageIndex > 0) {
            return NO_SUCH_PAGE;
        }
        Graphics2D g2d = (Graphics2D) graphics;
        g2d.drawString("Hello, Printer!", 100, 100);
        return PAGE_EXISTS;
    }

    public static void main(String[] args) {
        PrinterJob printerJob = PrinterJob.getPrinterJob();
        PrintService[] services = PrinterJob.lookupPrintServices();
        if (services.length > 0) {
            try {
                printerJob.setPrintService(services[0]);
                printerJob.setPrintable(new PrintExample());
                if (printerJob.printDialog()) {
                    printerJob.print();
                }
            } catch (PrinterException e) {
                e.printStackTrace();
            }
        } else {
            System.out.println("No printers found.");
        }
    }
}

[JAVA] SPEEDTEST NETWORK

long download1 = net.getBytesRecv();
long timestamp1 = net.getTimeStamp();
Thread.sleep(2000); //Sleep for a bit longer, 2s should cover almost every possible problem
net.updateNetworkStats(); //Updating network stats
long download2 = net.getBytesRecv();
long timestamp2 = net.getTimeStamp();
System.out.println("prova " + (download2 - download1)/(timestamp2 - timestamp1));
//Do the correct calculations

[JAVA] SERVER CLIENT NETWORK

// Server.java
import java.io.*;
import java.net.*;

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(12345);
        Socket clientSocket = serverSocket.accept();
        PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
        BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            System.out.println("Received: " + inputLine);
            out.println("Server received: " + inputLine);
        }
    }
}

// Client.java
import java.io.*;
import java.net.*;

public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost", 12345);
        PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
        BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        out.println("Hello from client");
        System.out.println("Server response: " + in.readLine());
    }
}

[JAVA] FILL COLOUR from MOUSE

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ColorFromMouse extends JPanel {

    private Color selectedColor = Color.BLACK;
    private int regionWidth = 50; // Example region width

    public ColorFromMouse() {
        addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                int x = e.getX();
                int region = x / regionWidth;

                // Example mapping of regions to colors
                switch (region) {
                    case 0: selectedColor = Color.RED; break;
                    case 1: selectedColor = Color.GREEN; break;
                    case 2: selectedColor = Color.BLUE; break;
                    default: selectedColor = Color.BLACK;
                }
                repaint(); // Trigger redraw with the new color
            }
        });
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(selectedColor);
        g.fillRect(50, 50, 100, 100); // Example filled rectangle
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("Color From Mouse");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(new ColorFromMouse());
        frame.setSize(300, 300);
        frame.setVisible(true);
    }
}

[JAVA] DOWNLOAD DATA FROM PROCESS

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

public class Progressbar {

    public static void main(String[] args) {

        final JProgressBar jProgressBar = new JProgressBar();
        jProgressBar.setMaximum(100000);
        JFrame frame = new JFrame();
        frame.setContentPane(jProgressBar);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(300, 70);
        frame.setVisible(true);

        Runnable updatethread = new Runnable() {
            public void run() {
                try {

                    URL url = new URL("http://downloads.sourceforge.net/project/bitcoin/Bitcoin/blockchain/bitcoin_blockchain_170000.zip");
                    HttpURLConnection httpConnection = (HttpURLConnection) (url.openConnection());
                    long completeFileSize = httpConnection.getContentLength();

                    java.io.BufferedInputStream in = new java.io.BufferedInputStream(httpConnection.getInputStream());
                    java.io.FileOutputStream fos = new java.io.FileOutputStream(
                            "package.zip");
                    java.io.BufferedOutputStream bout = new BufferedOutputStream(
                            fos, 1024);
                    byte[] data = new byte[1024];
                    long downloadedFileSize = 0;
                    int x = 0;
                    while ((x = in.read(data, 0, 1024)) >= 0) {
                        downloadedFileSize += x;

                        // calculate progress
                        final int currentProgress = (int) ((((double)downloadedFileSize) / ((double)completeFileSize)) * 100000d);

                        // update progress bar
                        SwingUtilities.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                jProgressBar.setValue(currentProgress);
                            }
                        });

                        bout.write(data, 0, x);
                    }
                    bout.close();
                    in.close();
                } catch (FileNotFoundException e) {
                } catch (IOException e) {
                }
            }
        };
        new Thread(updatethread).

        start();
    }

}

[JAVA] PROCESS BAR

public class ProgressBar {
    public static void main(String[] args) throws InterruptedException {
        int total = 100;
        for (int i = 0; i <= total; i++) {
            String bar = generateProgressBar(i, total);
            System.out.print("\r" + bar + " " + i + "%");
            Thread.sleep(50);
        }
        System.out.println();
    }

    private static String generateProgressBar(int current, int total) {
        int progressBarLength = 30;
        int filledLength = (int) (progressBarLength * ((double) current / total));
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < progressBarLength; i++) {
            if (i < filledLength) {
                sb.append("=");
            } else {
                sb.append(" ");
            }
        }
        sb.append("]");
        return sb.toString();
    }
}

[JAVA] OPEN FILE TO TEXTAREA

import javax.swing.*;
import java.awt.*;
import java.io.*;

public class FileToTextArea extends JFrame {

    private JTextArea textArea;

    public FileToTextArea() {
        setTitle("File to TextArea");
        setSize(600, 400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        textArea = new JTextArea();
        JScrollPane scrollPane = new JScrollPane(textArea);
        add(scrollPane, BorderLayout.CENTER);

        JButton openButton = new JButton("Open File");
        openButton.addActionListener(e -> openFile());
        add(openButton, BorderLayout.SOUTH);

        setVisible(true);
    }

    private void openFile() {
        JFileChooser fileChooser = new JFileChooser();
        int result = fileChooser.showOpenDialog(this);

        if (result == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();
            try (BufferedReader reader = new BufferedReader(new FileReader(selectedFile))) {
                textArea.setText(""); // Clear existing text
                String line;
                while ((line = reader.readLine()) != null) {
                    textArea.append(line + "\n");
                }
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, "Error reading file: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(FileToTextArea::new);
    }
}

[JAVA] CREATE FILE FROM TEXTAREA

import javax.swing.*;import java.io.*;public class TextAreaToFile { public static void main(String[] args) { JFrame frame = new JFrame("Text Area to File"); JTextArea textArea = new JTextArea("Enter text here."); JButton saveButton = new JButton("Save to File"); saveButton.addActionListener(e -> { String text = textArea.getText(); File file = new File("output.txt"); try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { writer.write(text); JOptionPane.showMessageDialog(frame, "File saved successfully!"); } catch (IOException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(frame, "Error saving file.", "Error", JOptionPane.ERROR_MESSAGE); } }); JPanel panel = new JPanel(); panel.add(new JScrollPane(textArea)); panel.add(saveButton); frame.add(panel); frame.setSize(400, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }}