🚀 Starting My Java Learning Journey – Day 4 🔹 Topic: Type Casting in Java Sometimes in Java, we need to convert one data type into another. This process is called type casting. There are two types of type casting: 1️⃣ Widening Casting (Implicit Casting) ✅Converting a smaller data type to a larger data type ✅Done automatically by Java Example: Converting int to double class Main { public static void main(String[] args) { int num = 10; System.out.println("The integer value: " + num); double data = num; System.out.println("The double value: " + data); } } Output: The integer value: 10 The double value: 10.0 Conversion order: byte → short → int → long → float → double 2️⃣ Narrowing Casting (Explicit Casting) ✅Converting a larger data type to a smaller data type ✅ Must be done manual Example: Converting double to int class Main { public static void main(String[] args) { double num = 10.99; System.out.println("The double value: " + num); int data = (int) num; System.out.println("The integer value: " + data); } } Output: The double value: 10.99 The integer value: 10 💡 Key Point: Widening → Automatic conversion Narrowing → Manual conversion Understanding type casting helps in data conversion and efficient memory usage in Java programs. #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #TypeCasting
Java Type Casting: Widening and Narrowing Explained
More Relevant Posts
-
Learning Java – Type Casting Basics As part of my Java learning journey, I explored Type Casting — a fundamental concept when working with different data types. What is Type Casting? Type casting is the process of converting one data type into another. 🔹 Types of Type Casting in Java: ✔️ Implicit Casting (Widening) Automatically converts a smaller data type into a larger one Example: int → double ✔️ Explicit Casting (Narrowing) Manually converts a larger data type into a smaller one Example: double → int Key Takeaways: • Implicit casting is safe and automatic • Explicit casting may lead to data loss • Essential for handling different data types in calculations Example: (1) int a = 10; double b = a; (2) double x = 10.5; int y = (int) x; Step by step, building a strong foundation in Java #Java #JavaProgramming #LearnJava #CodingJourney #ProgrammingBasics #TypeCasting #SoftwareDevelopment
To view or add a comment, sign in
-
-
Day 43/200 - Java Learning Journey 🌱 ✨ Sharing what I learned today in Java. 🔆Dream big, start small, act now. 📚 Today I learned about Conditional Statements in java. Today's Topic: Conditional Statements (else-if) 📍 Else-if: 👉 It will be used when we have more than 2 condition to be checked. 👉 If the first if condition is false, Java checks the else if condition. 👉 Syntax: if(condition1) { // Executes if condition1 is true } else if(condition2) { // Executes if condition1 is true } else if(condition3) { // Executes if condition1 is true } else { // Executes if all above conditions are false } 👉 In if-else ,else-if "else" is an optional but better to follow for readability purpose. 👉 In both if-else ,else-if block "if" block is mandatory. Example: Grade Checker public class GradeCheck { public static void main(String[] args) { int marks = 75; 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 if (marks >= 40) { System.out.println("Grade: D"); } else { System.out.println("Grade: F (Fail)"); } System.out.println("End of program."); } } Ouput: Grade: B End of program. #Java#DailyLearning#Consistency#Else-if#ConditionalStatements#Meghana M#10000 Coders#
To view or add a comment, sign in
-
🚀 I completed Day 3 of my Java learning using the W3Schools platform.Today, I studied about java Operators, Strings, and Type Casting.” This helped me understand how Java handles data transformation and manipulation. First, I learned about Type Casting, which is used to convert one data type into another. I understood that Java is a strictly typed language, so data must be converted carefully when moving between different types. I also learned about automatic casting (widening) such as converting "int" to "double", and manual casting (narrowing) where a larger type like "double" is converted to a smaller type like "int", which may cause loss of decimal values. Next, I explored operators in Java, which act as the logic engine of a program. These include arithmetic operators ("+ - * / %"), assignment operators, comparison operators ("==, >, <, >=, <="), and logical operators ("&&, ||, !"). I also learned how the “+” operator can be used not only for arithmetic calculations but also for string concatenation. Another important concept I studied was Strings in Java. I learned that strings are objects with built-in methods that allow us to analyze and manipulate text. Some useful string methods include "length()", "charAt()", "indexOf()", and "toUpperCase()" which help in processing text data effectively. Finally, I saw how these concepts work together in a practical example where operators, type casting, and string concatenation are used to calculate and display a score percentage in a program. #Java #Programming #LearningJourney #SoftwareDevelopment #W3schools
To view or add a comment, sign in
-
## DSA with C++ vs Java vs Python — Which is Best? 🤔 If you're starting your **Data Structures & Algorithms (DSA)** journey, one of the most common questions is: **Which programming language should I use — C++, Java, or Python?** The truth is: **DSA logic is language-independent**, but the language you choose can affect your speed, understanding, and performance. Let’s compare 👇 ### 🔹 DSA with C++ — Best for Performance & Competitive Coding **Why choose C++?** * Extremely **fast execution speed** ⚡ * Powerful **Standard Template Library (STL)** * Preferred in **competitive programming** * Better control over **memory management** **Best for:** ✔ Competitive programming ✔ Performance-critical applications ✔ Deep understanding of memory and optimization **Challenge:** * Syntax can feel complex for beginners * Requires careful memory handling --- ### 🔹 DSA with Java — Best for Structured Development **Why choose Java?** * Strong **object-oriented programming (OOP)** structure * Automatic **memory management (Garbage Collection)** * Widely used in **enterprise-level systems** * Good built-in **data structures library** **Best for:** ✔ Students focusing on **software development careers** ✔ Backend and enterprise applications ✔ Developers comfortable with OOP **Challenge:** * Slightly slower than C++ * More verbose syntax --- ### 🔹 DSA with Python — Best for Beginners & Rapid Learning **Why choose Python?** * **Simple and readable syntax** 🧠 * Faster to write and test solutions * Huge ecosystem and community support * Great for learning **problem-solving quickly** **Best for:** ✔ Beginners starting DSA ✔ Interview preparation ✔ Rapid prototyping **Challenge:** * Slower execution speed than C++ and Java * Not ideal for very performance-heavy tasks --- ## 🏆 So, Which One is Best? **Choose C++** 👉 If you aim for **competitive programming** or need maximum performance. **Choose Java** 👉 If your goal is **enterprise development** and strong OOP concepts. **Choose Python** 👉 If you're a **beginner** or want faster learning and implementation. 💡 **My Take:** The best language is the one you **can practice consistently**. Once you master DSA concepts, switching languages becomes much easier. --- ## 🚀 Final Thought **DSA is not about the language — it's about the logic.** Focus on understanding patterns, problem-solving strategies, and algorithm efficiency. The language is just a tool. --- #DSA #Programming #Coding #Python #Java #CPP #SoftwareDevelopment #CodingJourney #TechCareers #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 22 of Learning Java 📘 Built-in Methods in Strings Today, I explored some important String methods in Java that make text manipulation easier and more efficient. 🔹 Key Methods Covered: ✔️ "length()" – Returns the length of the string ✔️ "charAt(index)" – Returns character at given index ✔️ "toLowerCase()" – Converts string to lowercase ✔️ "toUpperCase()" – Converts string to uppercase ✔️ "indexOf()" – Finds first occurrence of a character ✔️ "lastIndexOf()" – Finds last occurrence of a character ✔️ "startsWith()" – Checks starting characters ✔️ "endsWith()" – Checks ending characters ✔️ "equals()" – Compares two strings (case-sensitive) ✔️ "equalsIgnoreCase()" – Compares without case sensitivity ✔️ "replace()" – Replaces characters in string ✔️ "substring()" – Extracts part of string ✔️ "split()" – Splits string into array ✔️ "trim()" – Removes extra spaces ✔️ "compareTo()" – Compares strings lexicographically 💻 Example Code: String s = "TapAcademy"; System.out.println(s.length()); System.out.println(s.charAt(3)); System.out.println(s.toUpperCase()); System.out.println(s.toLowerCase()); System.out.println(s.indexOf('A')); System.out.println(s.substring(3,7)); 🎯 What I Learned: ✨ Strings are immutable in Java ✨ Built-in methods simplify coding ✨ Very useful for real-world applications #Java #CodingJourney #100DaysOfCode #Programming #Learning #JavaDeveloper #Tech
To view or add a comment, sign in
-
-
📘 Java Learning – Multithreading (Part 3: Runnable Interface, Thread Names & Priorities) 🚀🎯 Continuing my learning journey into Java Multithreading. In this post, I explored how to define threads using the Runnable interface, along with concepts like thread names and priorities. 🔰 Defining a Thread using Runnable Interface A thread can also be defined by implementing the Runnable interface, which is present in the java.lang package and contains only one method: • run() 📌 Two Approaches to Define a Thread 1️⃣ Extending Thread class 2️⃣ Implementing Runnable interface 📌 Example – Runnable Implementation class MyRunnable implements Runnable { public void run() { System.out.println("Child Thread"); } public static void main(String[] args) { MyRunnable r = new MyRunnable(); Thread t = new Thread(r); t.start(); System.out.println("Main Thread"); } } ✔ Output may appear in mixed order because execution depends on the Thread Scheduler. 🔰 Best Approach to Define a Thread Between the two approaches, implementing Runnable is recommended. Reason: • If a class extends Thread, it cannot extend any other class • If a class implements Runnable, it can still extend another class ✔ This provides better flexibility in design. 🔰 Common Thread Constructors Some commonly used constructors of the Thread class: Thread() Thread(Runnable r) Thread(String name) Thread(Runnable r, String name) Thread(ThreadGroup g, String name) Thread(ThreadGroup g, Runnable r) Thread(ThreadGroup g, Runnable r, String name) Thread(ThreadGroup g, Runnable r, String name, long stackSize) 🔰 Getting and Setting Thread Name Every thread in Java has a name (default or programmer-defined). Methods used: • getName() • setName(String name) Example: System.out.println(Thread.currentThread().getName()); // main Thread.currentThread().setName("first thread"); System.out.println(Thread.currentThread().getName()); To get the current executing thread reference: Thread.currentThread() 🔰 Thread Priority Every thread has a priority ranging from 1 (lowest) to 10 (highest). Standard constants: • Thread.MIN_PRIORITY • Thread.NORM_PRIORITY • Thread.MAX_PRIORITY If two threads have the same priority, the execution order depends on the Thread Scheduler. 🔰 Default Priority • Default priority of main thread → 5 • Child threads inherit priority from the parent thread Methods used: • getPriority() • setPriority(int p) Example: t.setPriority(5); t.setPriority(10); t.setPriority(100); // IllegalArgumentException ⭐ Key Takeaways • Threads can be created using the Runnable interface • Implementing Runnable offers better design flexibility • Every thread has a name and priority • Priority range: 1 to 10 Learning multithreading step by step while strengthening Java fundamentals ☕💻 #Java #CoreJava #Multithreading #JavaDeveloper #Concurrency #LearningJourney
To view or add a comment, sign in
-
🚀 Exploring Built-in Methods of ArrayList in Java As part of my continuous learning in Java, I explored the powerful built-in methods of ArrayList that make data handling efficient and flexible. Understanding these methods is essential for writing clean and optimized code. Here’s a quick overview of some commonly used ArrayList methods 👇 🔹 1. add() Adds an element to the list list.add("Java"); 🔹 2. add(index, value) Inserts an element at a specific position list.add(1, "Python"); 🔹 3. addAll() Adds all elements from another collection list.addAll(otherList); 🔹 4. retainAll() Keeps only common elements between two collections list.retainAll(otherList); 🔹 5. removeAll() Removes all elements present in another collection list.removeAll(otherList); 🔹 6. set() Replaces an element at a specific index list.set(0, "C++"); 🔹 7. get() Retrieves an element by index list.get(0); 🔹 8. size() Returns the number of elements list.size(); 🔹 9. trimToSize() Trims capacity to match current size list.trimToSize(); 🔹 10. isEmpty() Checks if the list is empty list.isEmpty(); 🔹 11. contains() Checks if an element exists list.contains("Java"); 🔹 12. indexOf() Returns the first occurrence index list.indexOf("Java"); 🔹 13. lastIndexOf() Returns the last occurrence index list.lastIndexOf("Java"); 🔹 14. clear() Removes all elements from the list list.clear(); 🔹 15. subList(start, end) Returns a portion of the list list.subList(1, 3); 💡 Key Takeaway: Mastering these built-in methods helps in efficiently managing collections and solving real-world problems with ease. Consistency in practicing such concepts builds a strong foundation in Java development 💻✨ #Java #ArrayList #CollectionsFramework #Programming #Developers #LearningJourney #CodingSkills #KeepGrowing TAP Academy
To view or add a comment, sign in
-
-
🚀 Day 30 | Core Java Learning Journey 📌 Topic: Map Hierarchy in Java Today, I explored the Map Hierarchy in Java Collections Framework — understanding how different Map interfaces and classes are structured and related. 🔹 What is Map in Java? ✔ Map is an interface that stores key-value pairs ✔ Each key is unique and maps to a specific value ✔ It is part of java.util package 🔹 Map Hierarchy (Understanding Structure) ✔ Map (Root Interface) ⬇ ✔ SortedMap (extends Map) ⬇ ✔ NavigableMap (extends SortedMap) ⬇ ✔ TreeMap (implements NavigableMap) 🔹 Important Implementing Classes ✔ HashMap • Implements Map • Does NOT maintain order • Allows one null key ✔ LinkedHashMap • Extends HashMap • Maintains insertion order ✔ TreeMap • Implements NavigableMap • Stores data in sorted order • Does NOT allow null key ✔ Hashtable • Implements Map • Thread-safe (synchronized) • Does NOT allow null key/value 🔹 Key Differences ✔ HashMap → Fast, no ordering ✔ LinkedHashMap → Maintains insertion order ✔ TreeMap → Sorted data ✔ Hashtable → Thread-safe but slower 📌 When to Use What? ✅ Use HashMap → when performance is priority ✅ Use LinkedHashMap → when insertion order matters ✅ Use TreeMap → when sorting is required ✅ Use Hashtable → when thread safety is needed 💡 Key Takeaway: Understanding Map hierarchy helps in choosing the right data structure based on use-case rather than just coding blindly. 🙏 Special thanks to Vaibhav Barde Sir for the guidance! 🔥 #CoreJava #JavaLearning #JavaDeveloper #Map #HashMap #TreeMap #LinkedHashMap #Hashtable #JavaCollections #Programming #LearningJourney
To view or add a comment, sign in
-
-
🚀 Starting My Java Learning Journey – Day 6 🔹 Topic: Loops in Java Loops in Java are used to execute a block of code repeatedly until a certain condition is met. Java mainly provides three types of loops: 1️⃣ for Loop Used when the number of iterations is known. Example: public class Main { public static void main(String[] args) { for(int i = 1; i <= 5; i++) { System.out.println(i); } } } 2️⃣ while Loop Used when the number of iterations is not known beforehand. Example: public class Main { public static void main(String[] args) { int i = 1; while(i <= 5) { System.out.println(i); i++; } } } 3️⃣ do-while Loop The do-while loop executes the code at least once even if the condition is false. Example: public class Main { public static void main(String[] args) { int i = 1; do { System.out.println(i); i++; } while(i <= 5); } } 💡 Key Point: Loops help automate repetitive tasks and make programs more efficient. #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #JavaLoops
To view or add a comment, sign in
-
Day 35/200 - Java Learning Journey 🌱 ✨ Sharing what I learned today in Java. 🔆 The more that you read, the more things you will know. 📚 Today I learned about Instance of Operator and Type Casting Operator in Java. Today's Topic: Instance of Operator and Type Casting Operator. 📍 Instance of operator: 👉 It is used to check whether the object belongs to the class or not. 👉 The Result is in the form of Boolean Values. 👉 If object belongs to the class -It returns true value. Otherwise, it returns false. Example: class Animal { } class Dog extends Animal { } public class InstanceofExample { public static void main(String[] args) { Dog d = new Dog(); System.out.println(d instanceof Dog); // true System.out.println(d instanceof Animal); // true } } 📍Type Casting Operator: 👉Converting from one data type into another data type. 👉 If we store the big data type data into small data type, data is lost. 👉 There are two types of type casting : 1. Widening/Implicit Type Casting 2.Narrowing/Explicit Type Casting 🔸 1.Implicit Type Casting: 👉 Automatically it will convert from one data type to another. 🔸 2.Explicit Type Casting: 👉 Converting manually from one data type into another data type. 🔹Disadvantage: Data lost Example: public class TypeCastingExample{ public static void main(String [ ] args){ int a= 10; double b=a; //Implicit Type Casting System.out.println(b); double c=9.78; int d=(int)c;//Explicit Type Casting System.out.println(d); } } #Java#DailyLearning#Operators#TypeCastingOperators#InstanceofOperator#Consistency#Meghana M#10000 Coders#
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