ThreadLocal in Java

ThreadLocal in Java is a special class that provides thread-local variables. Each thread that accesses a ThreadLocal variable has its own, independently initialized copy of the variable. This is extremely useful when you want to avoid sharing data between threads, such as in cases of per-thread counters, user sessions, or database connections. Here’s a…

0 Comments

Throw, throws, and finally

In Java, throw, throws, and finally are related to exception handling, but they have very different purposes. 1. throw Purpose: Used inside a method to actually throw an exception object. Syntax: throw new ExceptionType("message"); Key Points: Works with a single exception instance at a time. Control jumps immediately to the nearest matching catch block…

0 Comments

Try catch

In Java, try, catch, and throws are part of the exception handling system. They let you deal with errors without crashing your program. Here’s the breakdown: 1. try A block of code where you write code that might throw an exception. If an exception happens inside try, Java will look for a matching catch…

0 Comments

Checked and unchecked exceptions

In Java, exceptions are broadly divided into three main categories, based on how the compiler and runtime handle them: 1. Checked Exceptions Definition: Exceptions that are checked at compile-time. If your code might throw a checked exception, you must either handle it with a try-catch block or declare it with throws. These are typically…

0 Comments

Nested and Inner Classes

1. Nested Classes in Java A nested class is any class defined inside another class. Java allows classes to be nested for better organization, encapsulation, and readability. There are two main types: A. Static Nested Class Declared static inside another class. Can access only static members of the outer class directly. Does not have…

0 Comments

Java’s history

Java’s history is a mix of big ideas, clever engineering, and a little bit of luck. Here’s the story in a clear timeline form: 1. Origins (1991–1994) – The Green Project In 1991, a small team at Sun Microsystems led by James Gosling, Patrick Naughton, and Mike Sheridan started the Green Project. The original…

0 Comments

Java Versions

YearVersionKey Features1996JDK 1.0First official release; basic core libraries, applets.1997JDK 1.1Inner classes, JDBC, JavaBeans, RMI.1998J2SE 1.2Swing GUI, Collections Framework, JIT compiler.2000J2SE 1.3HotSpot JVM, Java Naming and Directory Interface (JNDI).2002J2SE 1.4assert keyword, NIO (New I/O), logging API, XML parsing.2004J2SE 5.0Generics, annotations, enhanced for loop, autoboxing, varargs.2006Java SE 6Scripting API, improvements in web services, compiler API.2011Java SE…

0 Comments

JVM JDK JRE

1. JVM (Java Virtual Machine) Definition: JVM is the engine that runs Java bytecode. Role: It converts compiled Java bytecode into machine code so your program can run on any device. Key Point: JVM is platform-dependent (different JVMs exist for Windows, Linux, Mac). Example: You write code once, compile it, and JVM allows it…

0 Comments

Access modifiers in Java

In Java, access specifiers (also called access modifiers) define the visibility and accessibility of classes, methods, variables, and constructors. They control which parts of a program can access certain members of a class. Java has four main access specifiers: 1. public Visibility: Everywhere, i.e., from any other class or package. Usage: When you want…

0 Comments

Abstraction in java

In Java, abstraction is the process of hiding the implementation details of a class or method and exposing only the essential features to the outside world.It lets you focus on what an object does rather than how it does it. Why Abstraction? Reduces complexity by hiding unnecessary details. Increases flexibility — implementation can change…

0 Comments

End of content

No more pages to load