Войти
  • 29502Просмотров
  • 11 месяцев назадОпубликованоBro Code

Learn Java threading in 10 minutes! 🧵

#java #javatutorial #javacourse import ; public class Main { public static void main(String[] args) { // Threading = Allows a program to run multiple tasks simultaneously // Helps improve performance with time-consuming operations // (File I/O, network communications, or any background tasks) // How to create a Thread // Option 1. Extend the Thread class (simpler) // Option 2. Implement the Runnable interface (better) Scanner scanner = new Scanner( ); MyRunnable myRunnable = new MyRunnable(); Thread thread = new Thread(myRunnable); (true); // This thread will end when Main thread finishes (); ("You have 10 seconds to enter your name"); ("Enter your name: "); String name = (); ("Hello " + name); (); } }