Infosys Java Training Material Pdf «ORIGINAL - 2024»

ExecutorService executor = Executors.newFixedThreadPool(10); executor.submit(() -> System.out.println("Task executed by: " + Thread.currentThread().getName()); ); executor.shutdown(); Synchronization public synchronized void increment() count++; // Better: Use AtomicInteger private AtomicInteger count = new AtomicInteger(0); count.incrementAndGet(); 8. File I/O and NIO Traditional I/O try (BufferedReader reader = new BufferedReader(new FileReader("data.txt"))) String line; while ((line = reader.readLine()) != null) System.out.println(line); catch (IOException e) e.printStackTrace();

// Derived class public class PermanentEmployee extends Employee private double baseSalary; private double bonus;

// getters & setters

Four Pillars | Pillar | Java Implementation | |--------|---------------------| | Encapsulation | private fields + public getters/setters | | Inheritance | extends keyword | | Polymorphism | Method overloading & overriding | | Abstraction | abstract class / interface | Example: Encapsulation + Inheritance // Base class public abstract class Employee private String empId; private String name; public Employee(String empId, String name) this.empId = empId; this.name = name; Infosys Java Training Material Pdf

public interface TaxCalculator double calculateTax(double income);

public PermanentEmployee(String empId, String name, double baseSalary, double bonus) super(empId, name); this.baseSalary = baseSalary; this.bonus = bonus;

// for-each (preferred over index loops) for (String name : nameList) System.out.println(name); ExecutorService executor = Executors

public abstract double calculateSalary();

// Method 2: Implement Runnable (preferred) class MyRunnable implements Runnable public void run() /* task */

public class InfosysTaxCalculator implements TaxCalculator @Override public double calculateTax(double income) return income * 0.10; // 10% tax ExecutorService executor = Executors.newFixedThreadPool(10)

@Override public double calculateSalary() return baseSalary + bonus;

List<Employee> list = new ArrayList<>(); list.sort(Comparator.comparing(Employee::getSalary).reversed()); 7. Multithreading & Concurrency Creating Threads // Method 1: Extend Thread class MyThread extends Thread public void run() /* task */

pixel-geo