⭐𝐄𝐱𝐩𝐥𝐨𝐫𝐢𝐧𝐠 𝐚𝐛𝐨𝐮𝐭 𝐭𝐡𝐞 𝐓𝐨𝐤𝐞𝐧𝐬 𝐢𝐧 𝐉𝐚𝐯𝐚: In Java, tokens are the smallest meaningful elements of a program that the compiler can understand. They act as the fundamental building blocks of a Java program. Here's a breakdown of the types of tokens in Java: ➜ 1. Keywords: Reserved words in Java with predefined meanings. Examples: class, public, static, if, else, while, return, etc. Cannot be used as identifiers (e.g., variable names). ➜ 2. Identifiers: Names used to identify variables, methods, classes, or objects. • 𝐑𝐮𝐥𝐞𝐬: Must begin with a letter, _, or $. Cannot be a keyword. Case-sensitive. • 𝙀𝙭𝙖𝙢𝙥𝙡𝙚𝙨: myVariable, calculateSum. ➜ 3. Literals: Constant values directly used in the program. • 𝐓𝐲𝐩𝐞𝐬: Integer literals: 10, -5 Floating-point literals: 3.14, -0.01 Character literals: 'A', '9' String literals: "Hello", "Java" Boolean literals: true, false ➜ 4. Operators: Symbols used to perform operations on variables and values. • 𝐓𝐲𝐩𝐞𝐬: Arithmetic operators: +, -, *, /, % Relational operators: ==, !=, <, >, <=, >= Logical operators: &&, ||, ! Assignment operators: =, +=, -=, etc. ➜ 5. Separators (Delimiters): Characters used to separate tokens in a program. • 𝙀𝙭𝙖𝙢𝙥𝙡𝙚𝙨: 𝐏𝐚𝐫𝐞𝐧𝐭𝐡𝐞𝐬𝐞𝐬: () 𝐂𝐮𝐫𝐥𝐲 𝐛𝐫𝐚𝐜𝐞𝐬: { } 𝐒𝐞𝐦𝐢𝐜𝐨𝐥𝐨𝐧: ; 𝐂𝐨𝐦𝐦𝐚: , #java #Day3 #Corejava #Codegnan Thanks to my mentor: Anand Kumar Buddarapu Saketh Kallepu Uppugundla Sairam
Understanding Tokens in Java: A Breakdown
More Relevant Posts
-
Java Multithreading Threads don’t “see” each other’s actions instantly. Yet somehow, your volatile, synchronized, and AtomicInteger code works perfectly. 🤔 The reason? 👉 The Happens-Before Relationship — the hidden rule of the Java Memory Model. It defines how one thread’s actions become visible and ordered for another. If one action happens-before another, then the first’s effects are guaranteed to be seen by the second. Example 👇 Thread 1: count = 42; Thread 2: print(count); If there’s no happens-before relationship → Thread 2 may print 0. If there is (via volatile or synchronized) → Thread 2 will print 42. Some common rules: ✅ Writing to a volatile variable happens-before reading it. ✅ Exiting a synchronized block happens-before another thread enters it. ✅ Thread start happens-before its run() method executes. So when your code “just works,” it’s this invisible contract that makes it possible. Without happens-before, even volatile wouldn’t mean much. “Concurrency isn’t about APIs — it’s about understanding what the CPU is allowed to reorder.” ⚙️ If you enjoyed this, follow me — I’m posting Java Multithreading concept every day in simple language. And if this topic finally made sense, drop a 💬 below — I’d love to hear it! #Java #Multithreading #Concurrency #HappensBefore #MemoryModel #BackendDevelopment #SpringBoot #Placement #Microservices #Coding #Learning
To view or add a comment, sign in
-
☕ Day 5 of my 30-day Core Java journey! Today, I explored Operators in Java — the building blocks for performing calculations and comparisons in every program. Operators allow us to manipulate data and control logic easily. 💡 Types of Operators in Java 1️⃣ Arithmetic Operators → Used for mathematical operations + , - , * , / , % 🧩 Example: int a = 10, b = 3; System.out.println(a + b); // 13 System.out.println(a % b); // 1 2️⃣ Relational Operators → Compare two values == , != , > , < , >= , <= 🧩 Example: int x = 5, y = 8; System.out.println(x > y); // false 3️⃣ Logical Operators → Combine conditions && , || , ! 🧩 Example: int age = 20; System.out.println(age > 18 && age < 30); // true 4️⃣ Assignment Operators → Assign values = , += , -= , *= , /= , %= 5️⃣ Unary Operators → Work with single operands ++ , -- , + , - , ! 6️⃣ Ternary Operator → Short form of if-else 🧩 Example: int age = 18; String result = (age >= 18) ? "Adult" : "Minor"; System.out.println(result); 🎯 Takeaway: Operators make Java logical and mathematical. They form the foundation for expressions and decision-making in programs. #CoreJava #JavaLearning #PasupathiLearnsJava #JavaOperators #ProgrammingBasics
To view or add a comment, sign in
-
-
☕ Day 7 – Java 2025: Smart, Stable, and Still the Future 💡 🔹 Topic: ASCII Value in Java 🧩 What is ASCII Value? ASCII stands for American Standard Code for Information Interchange. It is a numerical representation of characters — where every letter, number, or symbol is assigned a specific numeric value between 0 and 127. For example, 'A' → 65, 'a' → 97, '0' → 48. --- ⚙️ How We Can Use ASCII Values in Java In Java, each character (char) has an internal ASCII code. You can easily get this value by type casting a character to an integer. This helps programmers perform character comparisons, sorting, encryption, and pattern logic. --- 🎯 Purpose of ASCII Values 1️⃣ Character Comparison: To check which character comes first or is greater based on ASCII order. Example: 'A' < 'a' because 65 < 97. 2️⃣ Encoding & Data Transmission: When sending text over systems or networks, ASCII ensures characters are universally understood. 3️⃣ Sorting and Logic Building: Used in string sorting algorithms or validation logic (e.g., checking if a character is uppercase, lowercase, or a number). 4️⃣ Mathematical Operations on Characters: You can perform arithmetic operations like converting uppercase to lowercase using ASCII difference. --- 💻 Simple Example char ch = 'A'; int ascii = (int) ch; // Type casting char to int System.out.println("ASCII value of " + ch + " is: " + ascii); Output: ASCII value of A is: 65 --- 🧠 Extra Insight 'A' to 'Z' → 65 to 90 'a' to 'z' → 97 to 122 '0' to '9' → 48 to 57 ASCII makes Java programs language-neutral and machine-readable for text processing tasks. --- ✨ #Day7OfJava #Java2025 #LearnJava #ASCIICode #JavaBasics #JavaCharacters #JavaForBeginners #CodeWithSneha #ProgrammingConcepts #100DaysOfJava #TechLearning #DeveloperJourney
To view or add a comment, sign in
-
-
🧠 Today’s Java Insight: Understanding Static Methods Today, I explored one of the most important concepts in Java — Static Methods and how they differ from object members. Here’s what I learned 👇 ⚙️ Static Methods ✅ Can be called without creating an object → ClassName.methodName(); ✅ Declared using the static keyword. ✅ Used when a method’s logic is common for all objects. ✅ Belongs to the class, not any specific object. 💻 Example: class MathUtils { static int square(int n) { return n * n; } } public class Main { public static void main(String[] args) { System.out.println(MathUtils.square(5)); } } 🧩 Static Members (Class Members) Class Members (static): Shared by all objects and can be accessed directly using the class name.(Everyone can access) 🔹static variables 🔹static methods 🔹static blocks 🔹static nested classes 🧱 Object Members (Instance Members) Object Members (non-static): Each object has its own copy and can only be accessed through an instance.(By instance can Access only ) 🔹instance variables 🔹instance methods 🔹constructors 🔹instance blocks ⚡ Dynamic Nature of Java Java is a dynamic programming language — 👉 The JVM loads classes only when needed, making execution efficient and memory-friendly. ✨ Key Takeaway: Use static when something should be shared among all objects and does not depend on instance data. Comment What will be the Output for these codes? #Java #OOP #StaticKeyword #Programming #JVM #JavaLearning #LearningJourney #Developers
To view or add a comment, sign in
-
-
🖊️ My Java Learning Series: Exploring Built-in Checked Exceptions in Java ⚙️ Today, I explored one of the most essential parts of Java’s exception hierarchy - Built-in Checked Exceptions. These are predefined exceptions provided by Java that handle recoverable issues which may occur due to external or system-related causes. ✨ What Are Built-in Checked Exceptions? Checked exceptions are those that the compiler checks at compile-time. They indicate problems that a program should anticipate and handle, rather than ignore. These exceptions help make Java applications more stable and predictable by forcing developers to prepare for potential failures. 💡 Common Built-in Checked Exceptions: 1️⃣ ClassNotFoundException – Thrown when an application tries to load a class using its name but the class definition cannot be found. 2️⃣ InterruptedException – Occurs when a thread is interrupted while it’s waiting, sleeping, or performing a long-running operation. 3️⃣ IOException – A general input/output failure such as when reading or writing files, or when a network communication error occurs. 4️⃣ FileNotFoundException – A subclass of IOException, thrown when an attempt to access a file that doesn’t exist or is unavailable is made. 5️⃣ InstantiationException – Thrown when an application tries to create an instance of an abstract class or an interface. 6️⃣ SQLException – Triggered during database access errors, invalid queries, or connection failures with the database. 🧠 Final Thought: Built-in Checked Exceptions represent Java’s commitment to safe coding. They remind developers that not all problems can be foreseen, but with proper handling, every problem can be managed gracefully. #Java #LearningJourney #CheckedExceptions #ExceptionHandling #Programming #TechLearning #CleanCode
To view or add a comment, sign in
-
-
💡 How Generics Make Object Comparison in Java Safer & Cleaner One of the most underrated benefits of Java Generics is how they simplify and secure the way we use Comparable and Comparator while comparing objects. Before Generics (pre-JDK 1.5), comparison logic often involved: ✔️ Storing objects as Object ✔️ Downcasting them manually ✔️ Hoping the cast doesn’t fail at runtime 😅 But with Generics, Java gives us compile-time type safety and eliminates unnecessary upcasting/downcasting. --- 🔍 What Problem Did Generics Solve? Without generics: class Student implements Comparable { int marks; public int compareTo(Object o) { Student s = (Student) o; // ❌ Risky downcast return this.marks - s.marks; } } Problems: You must cast from Object to Student. ⚠️ No compile-time checking — mistakes explode at runtime. Code becomes cluttered and unsafe. --- ✅ With Generics – Cleaner, Type-Safe, and Zero Casting class Student implements Comparable<Student> { int marks; public int compareTo(Student s) { // ✔️ No casting needed return this.marks - s.marks; } } And with Comparator: Comparator<Student> sortByName = (s1, s2) -> s1.name.compareTo(s2.name); Benefits: No upcasting to Object No downcasting back to original types Comparator & Comparable work with the specific type you intend Compiler ensures type correctness → safer & cleaner code --- 🎯 Why This Matters in Real Projects When working with large domain models (Employee, Product, Order, etc.), using generics avoids subtle runtime bugs. Collections like TreeSet, TreeMap, or Collections.sort() work perfectly with type-safe comparators. Your IDE offers better autocomplete because it knows the type you’re working with. --- 🚀 In short: Generics transformed the way we compare objects in Java—by replacing unsafe casting with clean, type-checked logic. Less boilerplate, more safety. #CleanCode #CodeQuality #SoftwareDevelopment #ProgrammingTips #LearnCoding
To view or add a comment, sign in
-
-
*"Happy to share that I’ve learned about *Polymorphism in Java*! 🎉 Polymorphism allows *one interface to be used for multiple forms*, making code flexible and reusable. There are *two types*: 1. *Compile-time Polymorphism (Method Overloading)* – Same method name, different parameters. 2. *Runtime Polymorphism (Method Overriding)* – Subclass provides a specific implementation of a method defined in parent class. Excited to implement these concepts in real Java projects! 💻✨ #Java #OOP #Polymorphism #LearningJourney"*
To view or add a comment, sign in
-
-
🧠 Inside Java’s Map: How It Really Works! Ever wondered what happens under the hood when you put a key-value pair into a Map in Java? 🤔 Let’s peel back the layers and see how the magic happens! ⚙️ 🔍 What is a Map? A Map in Java stores data as key-value pairs — where each key is unique and maps to a specific value. Common implementations include: HashMap LinkedHashMap TreeMap ConcurrentHashMap But the real star of the show is HashMap — the most commonly used one! 🌟 ⚙️ How HashMap Works Internally When you call: map.put("Apple", 10); Here’s what happens step by step 👇 ➡️ Hashing the Key The hashCode() of the key ("Apple") is computed. The hash value is processed (via a hashing algorithm) to find the bucket index in the underlying array. ➡️ Storing in a Bucket Each bucket is a linked list (or tree after Java 8). If no key exists in that bucket, a new Node is created and stored there. ➡️ Handling Collisions If two keys map to the same bucket, they form a linked list (chaining). In Java 8+, if the list grows beyond 8 elements, it’s converted into a balanced Red-Black Tree — improving lookup time from O(n) to O(log n)! ➡️ Retrieval During get(key), Java again computes the hash and goes to the right bucket. It compares keys using equals() to find the exact match. 🧩 Key Methods Used hashCode() → Generates hash for locating the bucket equals() → Ensures uniqueness of keys resize() → Expands the array when load factor (default 0.75) is exceeded 💡 Fun Fact: HashMap’s design balances speed, memory efficiency, and collision handling — a masterpiece of data structure engineering! 📘 In short: HashMap = Array + Linked List + Red-Black Tree + Hashing = ⚡Fast Key-Value Lookup #Java #HashMap #DataStructures #JavaDeveloper #Coding #SoftwareEngineering #Internals #Performance
To view or add a comment, sign in
-
Day - 52 #120DaysOfLearning | Java Full Stack ☑️ 𝐓𝐨𝐩𝐢𝐜: 𝐉𝐚𝐯𝐚 𝟖 𝐅𝐞𝐚𝐭𝐮𝐫𝐞𝐬 — Functional Interface, Lambda Expression, Higher Order Function & Iterator Method in Collections. 🌟 Learning modern Java 8 concepts that make code more functional, readable, and efficient — plus mastering how to iterate cleanly using Java Collections. ☑️ Functional Interface : 🔅 A Functional Interface contains exactly one abstract method 🔅 It may include any number of default and static methods 🔅 Use @FunctionalInterface annotation to prevent adding more abstract methods 🧾 Syntax: @FunctionalInterface interface MyInterface { void myMethod(); } ☑️ Lambda Expressions : 🔅 Lambda Expressions are anonymous functions 🔅 Used to eliminate boilerplate code 🔅 Can be passed where a functional interface is expected 🧾 Syntax: (parameters) -> { // body } 🔷 Example: MyInterface ref = () -> System.out.println("Hello from Lambda!"); ref.myMethod(); ☑️ Higher Order Function : 🔅 A Higher Order Function accepts another function as an argument 🧾 Syntax Example : void executeFunction(MyInterface ref) { ref.myMethod(); } 🔷 Here, executeFunction() is a higher-order function ☑️ Iterator Method in Collections : 🔅 Used to traverse elements in collections like List, Set, etc. 🔷 Key Methods: 1️⃣ iterator() → Gets the Iterator object 2️⃣ hasNext() → Checks for remaining elements 3️⃣ next() → Retrieves next element 4️⃣ remove() → (Optional) Removes current element 🧾 Syntax : Iterator<String> it = list.iterator(); while(it.hasNext()) { System.out.println(it.next()); } 🫶 Special Thanks to : #DestinationCodegn.. Anand Kumar Buddarapu Sir , Saketh Kallepu Sir , Uppugundla Sairam Sir. #Java8 #FunctionalInterface #LambdaExpressions #HigherOrderFunction #Iterator #JavaCollections #120DaysOfLearning #JavaFullStack #CleanCode #CodeBetter #LearnJavaDaily
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development