Day 14:- Strings A Journey with Frontlines EduTech (FLM) and Fayaz S ✒️ All String objects are store in Heap Area. Strings are write in two ways:- 1. Literals String s = "Tharun"; 2. Object:- ClassName objectName = new ClassName(); String s = new String("Tharun"); ✒️The literals are stored in String constant pool. ✒️The object is store in Head area. ✒️The string constant pool is a special memory area inside the heap where Java stores string literals to save memory and improves performance. ✒️When multiple Strings have the same value, Java stores only one copy in the pool. ✒️The string constant pool saves memory, increases performance and avoids duplicate string object. Day 15:- Type Casting :- ✒️The Type Casting in java means converting one data type into another data type. There are two types:- 1. Implicit type casting 2. Explicit type casting 1. Implicit type casting:- ✒️Converting a smaller data type into a larger data type automatically by java Ex:- byte->short->int->long->float->double 2. Explicit type casting:- ✒️converting a larger data types in to a smaller data type manually using casting. #Strings #java #corejava
Java Strings and Type Casting Explained
More Relevant Posts
-
Stack vs Heap Memory in Java – Where Does Your Data Live? 🧠 Stack Memory: ▸ Method calls + local variables ▸ LIFO (Last In, First Out) ▸ Very fast, auto-cleared after method ends ▸ Each thread has its own stack Heap Memory: ▸ Stores objects & instance variables ▸ Shared across threads ▸ Managed by Garbage Collector ▸ Slower than Stack, can throw OutOfMemoryError Example: void demo() { int x = 10; String s = new String("Java"); } ▸ x → Stack ▸ s (reference) → Stack ▸ "Java" object → Heap Rule: → Primitives → Stack → References → Stack → Objects → Heap #Java #SpringBoot #BackendDevelopment #Memory #JavaDeveloper
To view or add a comment, sign in
-
-
Stack vs Heap Memory in Java – Where Does Your Data Live? 🧠 Stack Memory: ▸ Method calls + local variables ▸ LIFO (Last In, First Out) ▸ Very fast, auto-cleared after method ends ▸ Each thread has its own stack Heap Memory: ▸ Stores objects & instance variables ▸ Shared across threads ▸ Managed by Garbage Collector ▸ Slower than Stack, can throw OutOfMemoryError Example: void demo() { int x = 10; String s = new String("Java"); } ▸ x → Stack ▸ s (reference) → Stack ▸ "Java" object → Heap Rule: → Primitives → Stack → References → Stack → Objects → Heap #Java #SpringBoot #BackendDevelopment #Memory #JavaDeveloper
To view or add a comment, sign in
-
-
Day16:- Arrays A Journey with Frontlines EduTech (FLM) and Fayaz S ✒️An array in Java is a data structure used to store multiple values of the same data type in a single variable. ✒️Instead of creating many variables, we store them in one array. Without array:- int a = 10; int b = 20; int c = 30; With array:- int [] numbers = {10,20,30}; Syntax:- dataType[] = new new dataType [size]; Array Initialization and access:- ✒️Arrays can also be initialized with values directly. int[] num = {1,2,3,4,5}; ✒️You can access elements using their index (string Index 0) Looping through arrays:- ✒️You can use loops to traverse arrays. ✒️ Commonly using for or enhanced for loops. ex:- int [] arr = {10,20,30,}; for(int i = 0; i<arr.lenght; i++) { System.out.println(arr[i]); } Advantages of Arrays:- ✒️Arrays allow random access of elements using index. ✒️Arrays are easy to traverse and manipulate using loops. ✒️Arrays help in efficient memory allocation when the size is known. ✒️They store multiple values in a single variable, reducing code complexity. ✒️Arrays are faster in accessing and modifying data compared to some data structures. Two-Dimensional Arrays :- ✒️2D arrays are arrays of arrays. They are useful for matrix-like data representation. Syntax:- dataType[][] arrayName = new dataType[rows][columns]; #arrays #corejava #java #2darrays
To view or add a comment, sign in
-
-
𝗧𝗵𝗲 𝗝𝗮𝘃𝗮 𝘀𝘄𝗶𝘁𝗰𝗵 𝘀𝘁𝗮𝘁𝗲𝗺𝗲𝗻𝘁 𝘁𝘂𝗿𝗻𝗲𝗱 𝟯𝟬 𝘁𝗵𝗶𝘀 𝘆𝗲𝗮𝗿 Here's the short version: What started as a C-style branching construct is now a declarative data-matching engine — and the JVM internals behind it are genuinely fascinating. What I learned going deep on this: → Early switch relied on jump tables — fast, but fall-through bugs were silent and destructive → Java added definite assignment rules, preventing uninitialized variables from slipping through → The JVM picks between tableswitch (O(1)) and lookupswitch (O(log n)) based on how dense your cases are → String switching since Java 7 uses hashCode + equals internally — it's not magic, it's two passes → Java 14 made switch an expression, which killed fall-through at the language level → Modern Java (21+) adds pattern matching with type binding and null handling — code reads like a description of data → invokedynamic enables runtime linking, replacing rigid compile-time dispatch tables → Java 25 enforces unconditional exactness in type matching — no more silent data loss • The real shift isn't syntax. It's the question switch answers. Old: "Where should execution go?" New: "What is the shape of this data?" That's not just a feature upgrade. That's a change in how you think about branching. Which of these surprised you most? Drop it in the comments. A special thanks to Syed Zabi Ulla sir at PW Institute of Innovation for their clear explanations and continuous guidance throughout this topic. #Java #Programming #SoftwareEngineering #JVM #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
#Post4 In the previous post, we understood how request mapping works using @GetMapping and others. Now the next question is 👇 How does Spring Boot handle data sent from the client? That’s where @RequestBody comes in 🔥 When a client sends JSON data → it needs to be converted into a Java object. Example request (JSON): { "name": "User", "age": 25 } Controller: @PostMapping("/user") public User addUser(@RequestBody User user) { return user; } 👉 Spring automatically converts JSON → Java object This is done using a library called Jackson (internally) 💡 Why is this useful? • No manual parsing needed • Clean and readable code Key takeaway: @RequestBody makes it easy to handle request data in APIs 🚀 In the next post, we will understand @PathVariable and @RequestParam 🔥 #Java #SpringBoot #BackendDevelopment #RESTAPI #LearnInPublic
To view or add a comment, sign in
-
🚀 Exchanger in Java – Why It’s Important 🔄 In multithreading, sometimes threads don’t just wait — they exchange data efficiently. That’s where Exchanger from Java comes in 💡 🔹 Why it matters? ✅ Direct data swap between two threads 🤝 ✅ No extra queues or shared memory 🧠 ✅ Faster & cleaner communication ⚡ ✅ Ideal for paired thread tasks 👯 💡 Easy Real-Time Example 😄 Think of a chef 👨🍳 and waiter 🧑🍽️: 🍳 Chef prepares food 🍽️ Waiter serves food 👉 Chef gives dish 🍲 👉 Waiter returns empty tray 🧺 👉 Work continues instantly ⚡ 🔥 Fast | Clean | Efficient 💡 Another Simple Tech Example 💻 🧵 Thread A → Writing logs 📝 🧵 Thread B → Saving logs to file 💾 🔄 They exchange buffers: ➡️ One gives filled buffer ➡️ Other returns empty buffer No delay ⏱️ No extra memory overhead 📉 🛠️ Code Example import java.util.concurrent.Exchanger; Exchanger<String> exchanger = new Exchanger<>(); new Thread(() -> { try { String data = "🍔 Food"; data = exchanger.exchange(data); System.out.println("Chef got: " + data); } catch (Exception e) {} }).start(); new Thread(() -> { try { String data = "🧺 Tray"; data = exchanger.exchange(data); System.out.println("Waiter got: " + data); } catch (Exception e) {} }).start(); ⚡ Final Thoughts 💭 ✨ Sometimes the simplest tools create the biggest impact ✨ Clean thread communication = better performance ⚡ ✨ Less complexity = fewer bugs 🐞 ✨ Right synchronizer at the right place = scalable systems 📈 ✨ Small concepts like this can level up your system design thinking 🧠🔥 #Java #Multithreading #Concurrency #JavaDeveloper #BackendDevelopment #SoftwareEngineering #SystemDesign #Coding #TechLearning #Performance 🚀
To view or add a comment, sign in
-
🚀 Day 19 – map() vs flatMap() in Java Streams While working with Streams, I came across a subtle but important difference: "map()" vs "flatMap()". --- 👉 map() Transforms each element individually List<String> names = Arrays.asList("java", "spring"); names.stream() .map(String::toUpperCase) .forEach(System.out::println); ✔ Output: JAVA, SPRING --- 👉 flatMap() Flattens nested structures List<List<Integer>> list = Arrays.asList( Arrays.asList(1, 2), Arrays.asList(3, 4) ); list.stream() .flatMap(Collection::stream) .forEach(System.out::println); ✔ Output: 1, 2, 3, 4 --- 💡 Key insight: - "map()" → 1-to-1 transformation - "flatMap()" → 1-to-many (and then flatten) --- ⚠️ Real-world use: "flatMap()" is very useful when dealing with: - Nested collections - API responses - Complex data transformations --- 💡 Takeaway: Understanding when to use "flatMap()" can make your stream operations much cleaner and more powerful. #Java #BackendDevelopment #Java8 #Streams #LearningInPublic
To view or add a comment, sign in
-
🚨 𝗧𝗵𝗲 𝗦𝗶𝗹𝗲𝗻𝘁 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 𝗞𝗶𝗹𝗹𝗲𝗿 𝗶𝗻 𝗦𝗽𝗿𝗶𝗻𝗴 𝗕𝗼𝗼𝘁 — 𝗡+𝟭 𝗤𝘂𝗲𝗿𝘆 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 Everything works fine… Until your API suddenly becomes slow in production 😅 That’s when many discover the N+1 Query Problem. 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗡+𝟭? You fetch 1 parent entity Then Hibernate runs N additional queries for child entities 👉 Total queries = N + 1 👉 Performance = 📉 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 Fetching Departments with Employees: Instead of 1 query, Hibernate runs: • 𝟭 𝗾𝘂𝗲𝗿𝘆 → Fetch departments • 𝗡 𝗾𝘂𝗲𝗿𝗶𝗲𝘀 → Fetch employees for each department Boom 💥 Performance issue. 𝗖𝗼𝗺𝗺𝗼𝗻 𝗠𝗶𝘀𝘁𝗮𝗸𝗲 A common instinct is to switch to EAGER loading to fix it. But… ❌ EAGER can also cause N+1 ❌ More memory usage ❌ Less control 𝗕𝗲𝘁𝘁𝗲𝗿 𝗦𝗼𝗹𝘂𝘁𝗶𝗼𝗻𝘀 ✅ ✔️ JOIN FETCH Fetch everything in a single query ✔️ EntityGraph Cleaner and more flexible approach ✔️ Batch Size Reduces queries for large datasets ✔️ DTO Projection Best for read-only APIs and performance Understanding this early can save hours of debugging in production 🚀 #connections #SpringBoot #Hibernate #Java #Backend #Performance #JPA #SoftwareEngineering #interviewPrep #interviewQuestion
To view or add a comment, sign in
-
-
One trace. 572,789 spans. 62% of all trace data in a five-minute sample, from a single service. This was a batch processing job. The #OpenTelemetry Java auto-instrumentation agent created a span for every database call inside a loop. The agent does not have a built-in span count cap per trace. It instruments what it finds, and a batch job iterating over hundreds of thousands of records will produce hundreds of thousands of spans. The trace was unusable. No backend renders half a million spans in a waterfall view. The cost was astronomical, and the four largest traces in the sample had no root span metadata, suggesting missing or disconnected parent spans. Most originated from batch or scheduled tasks like `https://lnkd.in/dBWthabm`. This organization runs 3,532 services, all on Java auto-instrumentation v1.33.6. The agent works well for request-response services. It was never designed for uncapped iteration over data. The fix depends on the batch pattern. For jobs that process items independently, use span links instead of parent-child relationships. Each item gets its own trace, linked back to the batch trace. This keeps individual traces small and queryable while preserving the connection to the batch context. For specific instrumentation that generates noise, the agent supports suppression flags. Setting `otel.instrumentation.common.experimental.suppress-messaging-receive-spans=true` eliminates receive spans for messaging consumers. Similar flags exist for JDBC, Redis, and other libraries. Review which instrumentations fire inside your loops and suppress the ones that add volume without insight. Auto-instrumentation assumes your services handle requests. When your workload does not fit that model, you need guardrails. The agent will not set them for you. And about last Friday's quiz: what does `stability: stable` mean for an OpenTelemetry semantic convention attribute? The answer is that it follows semver deprecation rules. A stable attribute is not frozen. It can still be deprecated, but the project must provide a migration path and maintain backward compatibility for a defined period. An `experimental` attribute carries no such guarantee and might be renamed or removed between releases. If you build dashboards or code generation around an experimental attribute, you accept the risk of breakage on upgrade.
To view or add a comment, sign in
-
What is var? var lets the compiler infer the data type of a local variable from the assigned value. With Java’s Local Variable Type Inference (var), we can write cleaner and more readable code — but only if we understand its boundaries. According to Oracle Docs: 🔗 https://lnkd.in/dzPr83eS Here are 8 practical rules every Java developer must know 1. Works with Different Data Types var name = "Alok"; // String var age = 19; // int var salary = 50000.5; // double Compiler infers the type at compile time. 2. Only for Local Variables public void demo() { var x = 10; // ✅ valid } var is limited to local scope only. 3. Not for Instance or Global Variables class Test { var x = 10; // ❌ compile-time error } 4. Not a Generic Type var list = new ArrayList<String>(); // ✅ var<String> list = new ArrayList<>(); // ❌ 5. No Explicit Generic Declaration with var You can’t mix var with explicit type parameters. ⚠️ 6. Must Be Initialized var x; // ❌ error Compiler needs a value to infer the type. 7. Not Valid for Lambda (Without Target Type) var f = () -> {}; // ❌ error Lambdas require a target type. 8. Not for Method Parameters or Return Types public var getData() { } // ❌ 💡 Key Insight: var reduces boilerplate but Java is still strongly typed — the type is inferred at compile time, not dynamic. Pro Tip: Use var when the type is obvious → avoid it when readability suffers. A big thank you to my mentor Syed Zabi Ulla & PW Institute of Innovation for continuous support and guidance. Your insights and encouragement have played a huge role in shaping my learning journey. #Java #Programming #Developers #Coding #JavaTips #SoftwareEngineering #Learning
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