How to Push to a GitHub Repository in IntelliJ

Image
1. Initialize and Connect the Git Repository # Run in the terminal from the project root git init git remote add origin https://github.com/[user]/[repository].git 2. Configure Git in IntelliJ Select VCS → Enable Version Control Integration . Choose Git and click OK . 3. Connect Your GitHub Account Go to File → Settings (on Windows) or IntelliJ IDEA → Preferences (on macOS). Navigate to Version Control → GitHub . Click Add Account ( + ). Select Log In with Token... and enter your GitHub Personal Access Token. 4. Add and Commit Files Go to VCS → Git → Add (or use the shortcut Ctrl+Alt+A ). Select the files you want to commit. Go to VCS → Commit (or use the shortcut Ctrl+K ). Write a commit message and click Commit . 5. Push Go to VCS → Git → Push (or use the shortcut Ctrl+Shift+K ). Click the Push button. Simpler Method (Using IntelliJ's Built-in Feature) Go to VCS → Share Project on GitHub . Set the repository name to vita-user-...

How Modern Java Improves Exception Handling (Java 21)

java 21 exception handling improvement

In recent Java releases, especially Java 21, exception handling mechanisms have been significantly enhanced to improve both code safety and system reliability.

These improvements help developers write more robust, maintainable, and error-resilient applications.

1. switch Statements Now Handle null and Support Pattern Matching

In Java versions prior to 21, passing a null value to a switch statement would throw a NullPointerException.

Java 21 allows developers to explicitly handle null values inside switch, preventing unexpected crashes.

switch (input) {
    case null -> System.out.println("Input is null.");
    case "YES" -> System.out.println("Yes!");
    default -> System.out.println("Other input.");
}

Benefits

  • Prevents NullPointerException by design
  • Improves clarity and readability

2. Pattern Matching and when Clauses in switch

Java 21 introduces pattern matching for switch, allowing developers to write more concise and type-safe branching logic. It also supports conditional case clauses (when) for fine-grained control.

static void handle(Object obj) {
    switch (obj) {
        case String s when s.isEmpty() -> System.out.println("Empty string");
        case String s -> System.out.println("String: " + s);
        case Integer i when i > 100 -> System.out.println("Integer > 100");
        case null -> System.out.println("Null value");
        default -> System.out.println("Other object");
    }
}

Benefits

  • Cleaner alternative to nested if-else or multiple instanceof checks
  • Enables more accurate and readable exception-related logic

3. More Flexible and Centralized Exception Handling

Java continues to support classic mechanisms such as:

  • try-catch-finally
  • throws declarations
  • Custom exception classes

In Java 21, the use of Thread.setUncaughtExceptionHandler is emphasized for centralized handling of uncaught exceptions.

Thread t = new Thread(() -> {
    throw new RuntimeException("Something went wrong!");
});
t.setUncaughtExceptionHandler((thread, ex) -> {
    System.err.println("Unhandled exception: " + ex.getMessage());
});
t.start();

Benefits

  • Enables centralized logging, alerting, or recovery
  • Especially useful in multi-threaded systems or background task runners

Comments

Popular posts from this blog

Resolving Key Exchange Failure When Connecting with SecureCRT to OpenSSH

SecureCRT] How to Back Up and Restore SecureCRT Settings on Windows

How to Set Up Vaultwarden (Bitwarden) on Synology NAS (Best Free Alternative to LastPass)