🌟 Day 5 of 10 – Core Java Recap: Arrays & Strings 🌟 Continuing my 10-day Java revision journey 🚀 Today I revised Arrays and Strings in Java, which are very important for programming and interviews. 📚 1️⃣ Arrays in Java An array is a container object that stores multiple values of the same data type in a fixed size. Java is not 100% object-oriented because it also supports primitive data types like int, char, etc. Example: int arr[] = new int[5]; Key Points: Stores fixed number of values Same data type elements Index starts from 0 Default values: int → 0, boolean → false, object → null 🔹 Types of Arrays ✔ Single Dimensional Array (1D) Used to store elements in a single row. Example: int arr[] = {1, 2, 3, 4, 5}; ✔ Multi-Dimensional Array (2D) Array of arrays (rows and columns). Example: int arr[][] = new int[2][3]; ✔ Jagged Array Array where each row can have different number of columns. Example: int arr[][] = new int[3][]; arr[0] = new int[2]; arr[1] = new int[3]; arr[2] = new int[1]; 🔁 Iterating Arrays Using for loop: for(int i = 0; i < arr.length; i++){ System.out.println(arr[i]); } Using for-each loop: for(int num : arr){ System.out.println(num); } 🧵 2️⃣ Strings in Java A String is a sequence of characters and is a class in Java. Strings are immutable (cannot be changed after creation). Example: String s1 = "Hello"; String s2 = new String("Hello"); ⚖ Difference Between == and equals() == → Compares memory address (reference) equals() → Compares actual content (value) Example: s1 == s2 // compares address s1.equals(s2) // compares value 🛠 Common String Methods length() → returns length of string charAt() → returns character at index indexOf() → finds position of character substring() → extracts part of string toUpperCase() → converts to uppercase toLowerCase() → converts to lowercase trim() → removes extra spaces split() → splits string into array replace() → replaces characters isEmpty() → checks if string is empty equalsIgnoreCase() → compares ignoring case 🔄 Conversion Array to String: Arrays.toString(arr); String to Array: String s = "Java"; char ch[] = s.toCharArray(); 💡 Key Learnings Today: Understood array types (1D, 2D, Jagged) Learned array traversal using loops Understood String as a class and immutability Learned important string methods used in real programs Building strong Java fundamentals step by step 💻🔥 #Java #CoreJava #Arrays #Strings #JavaLearning #CodingJourney
Java Arrays & Strings Recap: Arrays, Types, Iteration & String Methods
More Relevant Posts
-
Most Java developers have hit this bug at least once. 🐛 You call nextInt(), then nextLine()... and get an empty string. No error. No warning. Just silence. Here's what's actually happening under the hood 👇 When you type "42" and press Enter, the input buffer receives: 42\n nextInt() reads the "42" — and stops right there. The \n is still sitting in the buffer, "un-tou-ched". Then nextLine() comes along, looks for a line terminator... finds \n immediately, and returns an empty string. "I'll be back." — and so will that \n, every single time. 🤖 That's not a bug. That's by design. ⚡ Two paradigms, one class — that's the real issue. Scanner mixes two different reading models: → Token-based: nextInt(), nextDouble(), next() — reads until a delimiter (whitespace by default) → Line-based: nextLine() — reads until \n and consumes it Mixing them without understanding the difference is the #1 Scanner trap. 💡 The Fix (when you must mix both): int option = scanner.nextInt(); scanner.nextLine(); // 👈 "Hasta la vista, \n" 🤖 String name= scanner.nextLine(); // now works correctly 🎯 Rule of thumb: → Only nextInt() calls? → Fine, use it. → Mixing nextInt() + nextLine()? → Use Integer.parseInt(scanner.nextLine()) exclusively. → Need full control? → Drop Scanner entirely, use BufferedReader. Scanner's designers put both paradigms in one class for convenience. BufferedReader is more honest — lines only, you handle the parsing. Less magic. Fewer surprises. Have you fallen into this trap before? Drop a comment 👇 📊 Oracle Java SE 8 Docs — Scanner Class (2024) https://lnkd.in/eXPrFx58 📊 Baeldung — Integer.parseInt vs Scanner.nextInt() (2024) https://lnkd.in/eytwsPYv 📊 Baeldung — Java Scanner (2024) https://lnkd.in/esxb7JuK 📊 Medium — Reading a Full Line of Input Using Scanner in Java (2025) https://lnkd.in/eMRCBRGv #Java #SoftwareEngineering #BackendDevelopment #JavaDeveloper #CleanCode #Programming #SpringBoot #100DaysOfCode
To view or add a comment, sign in
-
Day 49 – Java 2026: Smart, Stable & Still the Future Difference Between Static and Non-Static Initializers in Java In Java, initializer blocks are used to initialize variables during the class loading or object creation phase. There are two types: Static Initializer Non-Static (Instance) Initializer Understanding their difference helps in learning how JVM memory management and class loading work. 1. Static Initializer A static initializer block is used to initialize static variables of a class. It executes only once when the class is loaded into memory by the ClassLoader. class Example { static int a; static { a = 10; System.out.println("Static initializer executed"); } public static void main(String[] args) { System.out.println(a); } } Key idea: It runs once during class loading. 2. Non-Static Initializer A non-static initializer block is used to initialize instance variables. It executes every time an object is created. class Example { int b; { b = 20; System.out.println("Non-static initializer executed"); } Example() { System.out.println("Constructor executed"); } public static void main(String[] args) { new Example(); new Example(); } } Key idea: It runs every time an object is created. 3. Key Differences FeatureStatic InitializerNon-Static InitializerKeywordUses staticNo keywordExecution timeWhen class loadsWhen object is createdRuns how many timesOnce per classEvery object creationVariables initializedStatic variablesInstance variablesMemory areaMethod AreaHeapExecution orderBefore main()Before constructor4. Execution Flow in JVM When a Java program runs: ClassLoader loads the class Static initializer executes main() method starts Object is created Non-static initializer executes Constructor executes Flow: Program Start ↓ Class Loaded ↓ Static Initializer ↓ Main Method ↓ Object Creation ↓ Non-Static Initializer ↓ Constructor Key Insight Static initializer → class-level initialization (runs once) Non-static initializer → object-level initialization (runs every object creation) Understanding these concepts helps developers clearly see how JVM manages class loading, memory, and object initialization. #Java #JavaDeveloper #JVM #OOP #Programming #BackendDevelopment
To view or add a comment, sign in
-
🚀 Day 6/100 — Methods in Java 🔧 As programs grow bigger, repeating the same code again and again becomes messy. This is where methods help. A method is a reusable block of code that performs a specific task. Instead of rewriting logic multiple times, you write it once and call it whenever needed. This follows the DRY principle — Don't Repeat Yourself. 🔹 Basic Method Syntax returnType methodName(parameters){ // method body } Example: public static void greet(){ System.out.println("Hello Java!"); } Calling the method: greet(); Output: Hello Java! 🔹 Method with Parameters Parameters allow methods to work with different inputs. Example: public static void add(int a, int b){ int sum = a + b; System.out.println(sum); } add(5, 3); Output: 8 🔹 Method with Return Value Sometimes a method needs to return a result. Example: public static int square(int num){ return num * num; } int result = square(4); System.out.println(result); Output: 16 🔹 Method Overloading Java allows multiple methods with the same name but different parameters. This is called method overloading. Java automatically chooses the correct method based on the arguments. Example: public static int add(int a, int b){ return a + b; } public static int add(int a, int b, int c){ return a + b + c; } Usage: System.out.println(add(5,3)); // calls first method System.out.println(add(5,3,2)); // calls second method 🔴 Live Example — Max of 3 Numbers public static int max(int a, int b, int c){ if(a >= b && a >= c){ return a; } else if(b >= a && b >= c){ return b; } else{ return c; } } public static void main(String[] args){ int result = max(10, 25, 15); System.out.println("Maximum number is: " + result); } Output: Maximum number is: 25 🎯 Challenge: Write a method to find the maximum of 3 numbers and test it with different inputs. Drop your solution in the comments 👇 #Java #CoreJava #100DaysOfCode #JavaMethods #ProgrammingJourney
To view or add a comment, sign in
-
-
🚀 Day 4/100 — If-Else & Switch in Java 🚦 Conditions are the brain of a program. They help your program make decisions based on different situations. In Java, the most common decision-making statements are if, else if, else, and switch. 🔹 If-Else Statement Used when a program needs to execute code based on a condition. Example: int age = 20; if(age >= 18){ System.out.println("Eligible to vote"); }else{ System.out.println("Not eligible to vote"); } ✔ If the condition is true, the first block runs. ✔ If it's false, the else block runs. 🔹 Else If Ladder Used when there are multiple conditions. ⚠️ Important: Java checks conditions top to bottom, and once one condition becomes true, the rest are skipped. Example: int marks = 85; if(marks >= 90){ System.out.println("Grade A"); } else if(marks >= 75){ System.out.println("Grade B"); } else if(marks >= 60){ System.out.println("Grade C"); } else{ System.out.println("Grade D"); } 🔹 Switch Statement Used when comparing one variable with multiple values. Example: int day = 3; switch(day){ case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wednesday"); break; default: System.out.println("Invalid day"); } ⚠️ Important: If you forget break, Java will execute all cases after that one (called fall-through). Example without break: int num = 1; switch(num){ case 1: System.out.println("One"); case 2: System.out.println("Two"); case 3: System.out.println("Three"); } Output: One Two Three 🔴 Mini Example — Pass or Fail int marks = 40; if(marks >= 35){ System.out.println("Pass"); }else{ System.out.println("Fail"); } 🎯 Challenge: Build a Grade Calculator using if-else. Example logic: 90+ → Grade A 75–89 → Grade B 60–74 → Grade C Below 60 → Grade D Drop your solution in the comments 👇 #Java #CoreJava #100DaysOfCode #JavaLearning #ProgrammingJourney
To view or add a comment, sign in
-
-
🚀Day 20 of #75DaysOfLeetCode LeetCode 2215 – Find the Difference of Two Arrays | Java | HashSet Approach Today I solved an interesting array + hashing problem that focuses on finding distinct elements between two arrays. 🔹 Problem Statement Given two integer arrays nums1 and nums2, return: answer[0] → all distinct integers in nums1 not present in nums2 answer[1] → all distinct integers in nums2 not present in nums1 The order of elements in the result does not matter. 📌 Example Input: nums1 = [1,2,3] nums2 = [2,4,6] Output: [[1,3], [4,6]] ✔️ 1 and 3 are in nums1 but not in nums2 ✔️ 4 and 6 are in nums2 but not in nums1 💡 Approach Instead of using nested loops (which would be inefficient), we can use HashSet: 1️⃣ Convert both arrays into sets to remove duplicates. 2️⃣ Check elements of set1 that are not in set2. 3️⃣ Check elements of set2 that are not in set1. 4️⃣ Store results in a list of lists. ⏱ Time Complexity: O(n + m) 📦 Space Complexity: O(n + m) 💻 Java Solution import java.util.*; class Solution { public List<List<Integer>> findDifference(int[] nums1, int[] nums2) { Set<Integer> set1 = new HashSet<>(); Set<Integer> set2 = new HashSet<>(); for(int n : nums1) set1.add(n); for(int n : nums2) set2.add(n); List<Integer> list1 = new ArrayList<>(); List<Integer> list2 = new ArrayList<>(); for(int n : set1){ if(!set2.contains(n)){ list1.add(n); } } for(int n : set2){ if(!set1.contains(n)){ list2.add(n); } } List<List<Integer>> result = new ArrayList<>(); result.add(list1); result.add(list2); return result; } } 🔑 Key Takeaway: Using HashSet simplifies the problem by removing duplicates and providing O(1) lookup time. #LeetCode #Java #DSA #CodingPractice #HashSet #Arrays #ProblemSolving #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Day 10 — Restarting My Java Journey with Consistency How Arrays Actually Work in Java (Memory Level Understanding) Most of us write: int[] arr = new int[5]; But what really happens behind the scenes? 🔹 1️⃣ Stack vs Heap — What is Actually Stored? When we create an array: ->The array object is created in Heap memory ->The variable arr is stored in the Stack ->arr does NOT store the actual elements ->It stores a reference (address) pointing to the array in heap So internally: Stack → arr → (reference) → Heap → [10, 20, 30, 40, 50] This cleared a major misconception. 🔹 2️⃣ Why Array Access is O(1) — The Address Formula Arrays support random access because of direct memory calculation. Conceptually: arr[i] = base_address + (size_of_datatype × i) For int (4 bytes): arr[3] = 100 + (4 × 3) = 112 That’s why accessing any index takes constant time — No traversal needed. 🔹 3️⃣ Why Java Throws ArrayIndexOutOfBoundsException consider arr.length <=100 In languages like C, accessing arr[100] might give garbage value. But Java internally performs a bounds check: if( index < 0 || index >= arr.length ) throw ArrayIndexOutOfBoundsException; That’s one of the reasons Java is considered safer. 🔹 4️⃣ Boolean Size — Interesting JVM Detail Officially, Java does NOT define a fixed size for boolean. It depends on JVM implementation. In HotSpot (Oracle/OpenJDK): ->Boolean is typically stored as 1 byte ->Even though logically it needs only 1 bit Reason? modern CPUs are byte-addressable and optimized for byte-aligned memory access. 🔹5️⃣ 2D array - Array of Arrays The Array stores the refences of Arrays means the each element of the Array is a Reference variable What is the size of a reference in Java? It depends on the JVM and system architecture: On a 32-bit JVM → a reference is typically 4 bytes On a 64-bit JVM → a reference is typically 8 bytes However ⚠️ In modern 64-bit JVMs, Compressed OOPs (Ordinary Object Pointers) are enabled by default. With this optimization, object references are compressed and effectively use 4 bytes, even on a 64-bit system. 🔹 6️⃣ String Arrays — Important Concept When we write: String[] names = new String[3]; The array stores references, not actual String objects. Each names[i] holds a reference to a String object in heap. New insight for me today: Also interesting: ->Before JDK 9, String internally used a char[], meaning each character consumed 2 bytes (UTF-16), even for simple English text. ->From JDK 9 onwards, Java introduced Compact Strings, where String uses a byte[] plus a small encoding flag. ->If the text contains only Latin characters, it uses 1 byte per character otherwise, it switches to UTF-16 (2 or 4 bytes). ->This significantly reduces memory usage without changing the String API (String class method calls). Learning daily with Coder Army and Aditya Tandon Bhaiya and Rohit Negi Bhaiya #Day10 #Java #Consistency #BackendDevelopment #LearningJourney #SoftwareEngineering #CoderArmy
To view or add a comment, sign in
-
-
🚀 Day 2 – Java Collections Deep Dive: List & ArrayList (Backend Focused) Today, I revised List interface and ArrayList implementation in detail — covering internal working, constructors, methods, and real backend usage. 📌 List Interface List is a sub-interface of Collection (java.util.List) It is an ordered collection It is index-based Allows duplicate elements Allows multiple null values Can store heterogeneous objects Supports index-based operations like add(index, obj) & get(index) Implementing classes: ArrayList LinkedList Vector Stack 📌 ArrayList Defined in java.util package Implements List interface Underlying Data Structure → Resizable / Growable Array Introduced in JDK 1.2 🔹 Default Capacity Default capacity = 10 When full, capacity increases by 50% of current capacity (Dynamic resizing) 📌 Constructors of ArrayList 1️⃣ ArrayList() → Creates empty list with default capacity (10) 2️⃣ ArrayList(int initialCapacity) → Creates list with specified capacity 3️⃣ ArrayList(Collection c) → Creates list & initializes it with elements of passed collection 📌 Important Operations Practiced 🔹 Add Operations add(Object o) add(int index, Object o) addAll(Collection c) addAll(int index, Collection c) 🔹 Remove Operations remove(int index) remove(Object o) removeAll(Collection c) retainAll(Collection c) clear() 🔹 Access Operations get(int index) 🔹 Search Operations contains(Object o) containsAll(Collection c) indexOf(Object o) → returns first occurrence lastIndexOf(Object o) → returns last occurrence Returns -1 if element not found 🔹 Miscellaneous Methods isEmpty() size() toArray() 💻 Backend Perspective ✔ Used to store database query results ✔ Maintains insertion order (important for API responses) ✔ Allows duplicates (useful in transaction logs) ✔ Dynamic resizing handles variable DB records ✔ contains() used in validation logic ✔ retainAll() used in role-based filtering ✔ indexOf() helps in search-based logic 📌 Key Learning: ArrayList is fast for: Data retrieval (O(1) for get) Sequential processing But slower for: Middle insertions/deletions (due to shifting) Understanding internal behavior helps write optimized backend code and answer interview questions confidently. #Java #BackendDeveloper #ArrayList #JavaCollections #SpringBoot #SoftwareEngineering #LearningInPublic #InterviewPreparation
To view or add a comment, sign in
-
🚀One of the most important core Java concepts: 🔹 Arrays 🔹 Strings (Immutable vs Mutable) 🔹 Memory Allocation (Stack & Heap) 🔹 String Pool 🔹 == vs equals() These concepts look simple… but they are very important in interviews and real-time projects. 📌 1️⃣ Arrays in Java ✔ Arrays store homogeneous data (same data type) ✔ Stored in contiguous memory locations ✔ Fixed size (cannot grow or shrink) ✔ Created in Heap memory ✔ Reference stored in Stack Example: Java 👇 int[] arr = new int[5]; If we need dynamic size → we use ArrayList. 📌 2️⃣ Strings in Java String is: A sequence of characters An object in Java Immutable Example: Java 👇 String s1 = "JAVA"; String s2 = "JAVA"; Here both s1 and s2 point to the same memory in the String Constant Pool. But: Java 👇 String s3 = new String("JAVA"); This creates a new object in Heap. 📌 3️⃣ Important Difference 🔹 == Compares reference (memory address) 🔹 equals() Compares values (content) Example: Java 👇 String a = "JAVA"; String b = new String("JAVA"); System.out.println(a == b); // false System.out.println(a.equals(b)); // true 📌 4️⃣ Why String is Immutable? ✔ Security ✔ Performance (String Pool reuse) ✔ Thread safety ✔ Used in networking, database URLs, file paths 💡 Real-Time Example 🔹 Login System When a user logs in: Java 👇 String username = "admin"; String inputUser = new String("admin"); if(username.equals(inputUser)) { System.out.println("Login Successful"); } If we use ==, login may fail ❌ So we always use .equals() for value comparison. 🎯 Interview Important Points ✔ Arrays are fixed size ✔ Arrays use contiguous memory ✔ String is immutable ✔ String literals stored in String Pool ✔ == → reference comparison ✔ equals() → value comparison ✔ Use ArrayList for dynamic size 💬 Mastering core concepts like Arrays & Strings builds strong programming foundation. TAP Academy #Java #CoreJava #String #Programming #Learning #Developers
To view or add a comment, sign in
-
-
💡 Java Internals: How HashMap Actually Works Many developers use HashMap every day, but very few understand what actually happens internally. Here is the complete flow in 5 core concepts: 0️⃣ Implementation of HashMap HashMap is one of the main implementations of the Map interface. public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable Key facts: • Stores key–value pairs • Allows 1 null key and multiple null values • Not thread-safe 1️⃣ Internal Structure (Nodes & Buckets) Internally HashMap stores entries as Nodes. Each Node contains four components: • Key → identifier used to retrieve value • Value → actual stored data • Hash → hash value derived from key • Next pointer → link to the next node in case of collision All nodes are stored in an array called the bucket table Node<K,V>[] table Each index in this array is called a bucket 2️⃣ How Data is Stored in HashMap Insertion happens in three steps: Step 1 - Hashing the key hash = key.hashCode() Java improves distribution internally: hash = h^(h>>>16) Step 2 — Calculating the index index = (n - 1)&hash where n = array size. HashMap keeps capacity as a power of 2 to make this fast. Step 3 — Store in bucket If bucket is empty → entry stored directly. If not → collision occurs 3️⃣ Collision Handling A collision happens when multiple keys map to the same bucket index. Example: map.put("apple",50) map.put("orange",80) Both may land in the same bucket. Handling differs by Java version. Before Java 8 Bucket → Linked List Worst-case search: O(n) After Java 8,If bucket size exceeds 8 entries: Linked List → Red Black Tree New complexity:O(log n) This process is called Treeification,happens only when table size ≥ 64 4️⃣ HashMap Resizing (Rehashing) HashMap automatically resizes to maintain efficiency. Default values: Initial Capacity = 16 Load Factor = 0.75 Resize condition: size > capacity × loadFactor Example: 16×0.75 = 12 The 13th insertion triggers resizing 5️⃣ What Happens During Resizing 🌟 Array size doubles 16 → 32 → 64 → 128 🌟 All existing entries are rehash redistributed 🌟 Each entry moves to its new bucket position Performance Summary Average case: get() → O(1) put() → O(1) Worst case: Before Java 8 → O(n) After Java 8 → O(log n) Interesting HashMap Facts 🔹 HashMap capacity is always a power of 2 so (n - 1) & hash can replace slower modulo operations. 🔹 Treeification occurs only when bucket size ≥ 8 AND table size ≥ 64 🔹 During resizing, entries do not require full rehash computation Because the capacity doubles, each entry either: stays in the same index or moves to index + oldCapacity This clever optimization makes resizing much faster than expected. HashMap is a great example of how arrays, hashing, linked lists, and trees combine to build a highly efficient data structure. #Java #HashMap #JavaCollections #SoftwareEngineering #BackendDevelopment #JavaInterview #InterviewPreparation
To view or add a comment, sign in
-
𝗗𝗔𝗬 𝟯 – 𝗦𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲 𝗼𝗳 𝗮 𝗝𝗮𝘃𝗮 𝗣𝗿𝗼𝗴𝗿𝗮𝗺 + 𝗝𝗮𝘃𝗮 𝗧𝗼𝗸𝗲𝗻𝘀 𝗜𝗻 𝘁𝗵𝗲 𝗹𝗮𝘀𝘁 𝘁𝘄𝗼 𝗽𝗼𝘀𝘁𝘀 𝘄𝗲 𝘂𝗻𝗱𝗲𝗿𝘀𝘁𝗼𝗼𝗱: • Why Java is Platform Independent • How JDK, JRE, and JVM work together to run a Java program Now it's time to move from 𝘁𝗵𝗲𝗼𝗿𝘆 → 𝗮𝗰𝘁𝘂𝗮𝗹 𝗰𝗼𝗱𝗲. 𝗟𝗲𝘁’𝘀 𝘄𝗿𝗶𝘁𝗲 𝗮 𝘀𝗶𝗺𝗽𝗹𝗲 𝗝𝗮𝘃𝗮 𝗽𝗿𝗼𝗴𝗿𝗮𝗺. ``` 𝚙𝚞𝚋𝚕𝚒𝚌 𝚌𝚕𝚊𝚜𝚜 𝙷𝚎𝚕𝚕𝚘𝚆𝚘𝚛𝚕𝚍 { 𝚙𝚞𝚋𝚕𝚒𝚌 𝚜𝚝𝚊𝚝𝚒𝚌 𝚟𝚘𝚒𝚍 𝚖𝚊𝚒𝚗(𝚂𝚝𝚛𝚒𝚗𝚐[] 𝚊𝚛𝚐𝚜) { 𝚂𝚢𝚜𝚝𝚎𝚖.𝚘𝚞𝚝.𝚙𝚛𝚒𝚗𝚝𝚕𝚗("𝙷𝚎𝚕𝚕𝚘 𝚆𝚘𝚛𝚕𝚍"); } } ``` At first glance this may look confusing. But if we break it down, the structure becomes very simple. 𝗦𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲 𝗼𝗳 𝗮 𝗝𝗮𝘃𝗮 𝗣𝗿𝗼𝗴𝗿𝗮𝗺 Every Java program generally contains: 1️⃣ 𝗖𝗹𝗮𝘀𝘀 𝗗𝗲𝗰𝗹𝗮𝗿𝗮𝘁𝗶𝗼𝗻 𝚙𝚞𝚋𝚕𝚒𝚌 𝚌𝚕𝚊𝚜𝚜 𝙷𝚎𝚕𝚕𝚘𝚆𝚘𝚛𝚕𝚍 In Java, everything starts with a class. The filename must match the class name. Example: 𝙷𝚎𝚕𝚕𝚘𝚆𝚘𝚛𝚕𝚍.𝚓𝚊𝚟𝚊 2️⃣ 𝗠𝗮𝗶𝗻 𝗠𝗲𝘁𝗵𝗼𝗱 𝚙𝚞𝚋𝚕𝚒𝚌 𝚜𝚝𝚊𝚝𝚒𝚌 𝚟𝚘𝚒𝚍 𝚖𝚊𝚒𝚗(𝚂𝚝𝚛𝚒𝚗𝚐[] 𝚊𝚛𝚐𝚜) This is the entry point of every Java program. When we run a program, the JVM starts execution from the 𝗺𝗮𝗶𝗻() 𝗺𝗲𝘁𝗵𝗼𝗱. 3️⃣ 𝗦𝘁𝗮𝘁𝗲𝗺𝗲𝗻𝘁𝘀 𝚂𝚢𝚜𝚝𝚎𝚖.𝚘𝚞𝚝.𝚙𝚛𝚒𝚗𝚝𝚕𝚗("𝙷𝚎𝚕𝚕𝚘 𝚆𝚘𝚛𝚕𝚍"); This statement simply prints output on the console. 𝗡𝗼𝘄 𝗹𝗲𝘁’𝘀 𝘂𝗻𝗱𝗲𝗿𝘀𝘁𝗮𝗻𝗱 𝘀𝗼𝗺𝗲𝘁𝗵𝗶𝗻𝗴 𝘃𝗲𝗿𝘆 𝗶𝗺𝗽𝗼𝗿𝘁𝗮𝗻𝘁 𝗶𝗻 𝗝𝗮𝘃𝗮. 𝗝𝗮𝘃𝗮 𝗧𝗼𝗸𝗲𝗻𝘀 Tokens are the smallest building blocks of a Java program. Java programs are basically made up of tokens. 𝗧𝗵𝗲𝗿𝗲 𝗮𝗿𝗲 𝗺𝗮𝗶𝗻𝗹𝘆 𝟱 𝘁𝘆𝗽𝗲𝘀: • 𝗞𝗲𝘆𝘄𝗼𝗿𝗱𝘀 → public, class, static, void • 𝗜𝗱𝗲𝗻𝘁𝗶𝗳𝗶𝗲𝗿𝘀 → names of variables, classes, methods • 𝗟𝗶𝘁𝗲𝗿𝗮𝗹𝘀 → actual values (10, "Hello", true) • 𝗦𝗲𝗽𝗮𝗿𝗮𝘁𝗼𝗿𝘀 → { } ( ) [ ] ; , • 𝗢𝗽𝗲𝗿𝗮𝘁𝗼𝗿𝘀 → + - * / = == Example identifier rules: ✔ Cannot start with a number ✔ Cannot use Java keywords ✔ No spaces allowed ✔ Can use letters, numbers, _ and $ Once you understand structure + tokens, reading Java code becomes much easier. If you look at the Java program again, you’ll now notice: It is simply a combination of tokens working together. Once you understand tokens and structure, reading Java code becomes much easier. 𝗧𝗼𝗺𝗼𝗿𝗿𝗼𝘄 (𝗗𝗮𝘆 𝟰) 𝗪𝗲’𝗹𝗹 𝗴𝗼 𝗱𝗲𝗲𝗽𝗲𝗿 𝗶𝗻𝘁𝗼 𝗼𝗻𝗲 𝗼𝗳 𝘁𝗵𝗲 𝗺𝗼𝘀𝘁 𝗶𝗺𝗽𝗼𝗿𝘁𝗮𝗻𝘁 𝘁𝗼𝗽𝗶𝗰𝘀 𝗶𝗻 𝗝𝗮𝘃𝗮: • Data Types • Variables • Primitive vs Non-Primitive types • Memory basics behind variables Because before writing real programs, understanding how Java stores data is critical. 𝗦𝗲𝗲 𝘆𝗼𝘂 𝗶𝗻 𝗗𝗮𝘆 𝟰. #Java #BackendDevelopment #Programming #LearnInPublic #Day3
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