Posts

Showing posts with the label Java Keywords

Static Import in Java: Definition, Syntax, Advantages, and Examples

📘 Static Import in Java Static Import is a feature introduced in JDK 1.5 that allows programmers to access static members (variables and methods) of a class, abstract class, or interface without using the class name. It helps make the code shorter, cleaner, and more readable, especially when static members are used frequently. 🔹 Why Use Static Import? Normally, static members are accessed using the class name. With static import, the class name is not required. ✔️ Benefits : Reduces code verbosity Improves readability Makes frequently used static members easy to access 🧩 Syntax of Static Import import static packageName.ClassName.staticMember; OR (to import all static members) import static packageName.ClassName.*; 🧠 What Can Be Imported Using Static Import? Static variables Static methods Static constants 📌 Applicable to: Class Abstract class Interface 🌍 Real-Life Example Think of static import like saving a contact number: Without static import → You dial the full number every...

Basics of Java Programming: Keywords, Literals, and Identifiers

Basics of Java Program The basics of a Java program include keywords, literals, and identifiers. These are the fundamental building blocks used while writing Java code. 1. Keywords Keywords are reserved words in Java that have predefined meanings and functionality for the Java compiler. Key points: Keywords must be written in lowercase. Java has 50 reserved keywords. Out of these, 48 keywords have predefined meaning and functionality. The remaining 2 reserved words (goto and const) are not used and have no functionality. Examples of Java keywords: class static final public void Keywords cannot be used as variable names, method names, or identifiers. 2. Literals Literals are fixed values that are directly stored in a Java program. Java supports five types of literals: Integer Literals: Eg:- 1, 25, 100 Floating-Point Literals: Eg:- 1.5, 2.75 Character Literals: Eg:- 'a', 'Z' String Literals: Eg:- "Java", "Programming" Boolean Literals: Eg:- true, false...