In this article, we’ll explore: Java program structure & syntax Variables in Java Data types (Primitive & Non-Primitive) Type casting Java naming conventions These are fundamental concepts you must master before moving into logic and problem-solving. https://lnkd.in/gemKfKjJ
Mastering Java Fundamentals: Variables, Data Types & Syntax
More Relevant Posts
-
📌 Understanding the this Keyword in Java (with a simple example) In Java, the this keyword is a reference to the current object of a class. It’s commonly used to differentiate instance variables from method or constructor parameters when they share the same name. Let’s look at a simple example 👇 class Employee { String name; int age; // Constructor Employee(String name, int age) { this.name = name; this.age = age; } void display() { System.out.println("Name: " + this.name); System.out.println("Age: " + this.age); } public static void main(String[] args) { Employee emp = new Employee("Vishnu", 28); emp.display(); } } 🔍 What’s happening here? this.name refers to the instance variable of the current object. name (without this) refers to the constructor parameter. Without this, Java would get confused between the two variables. Using this makes the code clear, readable, and bug-free. ✅ Why this is important? Avoids variable shadowing Improves code clarity Helps in constructor chaining and method calls Essential for writing clean object-oriented code Mastering small concepts like this builds a strong Java foundation 💪 #Java #OOP #Programming #Backend #Learning #CleanCode
To view or add a comment, sign in
-
📘 Core Java Day 34| What Are Cursors in Java? Before enhanced for-each loops and Streams, Java used cursors to iterate over collections. A cursor is an object used to traverse elements one by one from a collection. What Is a Cursor? - In Java, a cursor is an iterator-like mechanism that allows us to: - Access elements sequentially - Traverse a collection safely - Perform read or remove operations during iteration Types of Cursors in Java - Java provides three types of cursors: 1 ) Enumeration (Legacy Cursor) Used with legacy classes like Vector and Stack Can only read elements Does not support element removal Works only in forward direction Considered outdated and limited. 2) Iterator (Most Common) Applicable to all collection classes Supports element removal Forward-only traversal Replaced Enumeration in modern Java This is the most commonly used cursor in interviews and real projects. 3) ListIterator (Advanced Cursor) - Works only with List implementations - Supports forward and backward traversal - Allows add, update, and remove operations - Provides index-based navigation
To view or add a comment, sign in
-
-
📘 Core Java Day 30 | What Is the transient Keyword and Why Is It Used? In Java, when an object is converted into a byte stream for storage or transmission, the process is called serialization. Converting that byte stream back into an object is called deserialization. This is where the transient keyword becomes important. 🔹 What Does transient Do? - transient is used with instance variables - It tells the JVM not to include that variable during serialization - The marked variable is skipped from the byte stream transient prevents sensitive or unnecessary data from being serialized. Why Do We Need transient? - Some data should not be stored or transferred, such as: - Passwords - Security tokens - Temporary or calculated values Serializing such data can cause security risks or unwanted persistence. What Happens During Deserialization? - Transient variables are not restored - They get their default values - null for objects - 0 for numbers - false for boolean - transient works only with serialization - It has no effect on normal object behavior - Static variables are not serialized, even without transient - Commonly used with Serializable interface
To view or add a comment, sign in
-
I’ve written an article explaining different reference types available in Java and how they are tied to garbage collection. It also touches on two references that are often overlooked by developers — SoftReference and PhantomReference — and explains where they actually fit in real applications. https://lnkd.in/ddANB9Tr
To view or add a comment, sign in
-
🚀 Variables & Constants in Java | Core Java Basics 💡 Variables and Constants are the building blocks of any Java program. Understanding them clearly helps you write clean, efficient, and bug-free code. 🔹 Variables in Java A variable is a container used to store data that can change during program execution. ✅ Types of Variables in Java: Local Variable – Declared inside a method Instance Variable – Declared inside a class (non-static) Static Variable – Shared across all objects of a class 📌 Example: int count = 10; 🔹 Constants in Java A constant is a variable whose value cannot be changed once assigned. ✅ Created using the final keyword 📌 Example: final double PI = 3.14159; 🔒 Constants improve: Code readability Safety Maintainability 🔍 Key Difference Variables Constants Value can change Value cannot change Flexible Fixed No final keyword Uses final keyword 🎯 Why This Matters? ✔ Strong foundation for OOP ✔ Avoids logical errors ✔ Frequently asked in Java interviews 📘 Learning Java step by step makes you a better developer. 🚀 Follow MD AZMAT RAZA for beginner-to-advanced Java & coding resources. #Java #CoreJava #JavaBasics #Programming #Coding #SoftwareEngineering #LearnJava
To view or add a comment, sign in
-
-
📘 Core Java Day 14 | Different Ways to Create Objects in Java In Java, creating objects is not limited to just using the new keyword. While new is the most common ways is there, Here are the main ones: 1 Using new keyword - The standard way to create an object by calling a constructor. 2 Using Factory / Static Factory Methods - Object creation logic is moved to a method, which helps in loose coupling and better design. Example: Integer.valueOf() 3 Using Cloning - Creates a copy of an existing object without calling the constructor. 4 Using Reflection - Objects are created at runtime using class metadata. Commonly used in frameworks. 5 Using Deserialization - Objects are created from a stream (file or network), bypassing constructors. object creation in Java is about design, flexibility, and control
To view or add a comment, sign in
-
-
Until now, our Java programs knew all the values in advance. But real programs become useful only when they can listen to the user. Think about real life: 📝 A form is meaningful only when someone fills it. 🏧 An ATM works only after you enter details. A Java program also needs a way to listen 👂. That’s where user input comes in. 🛠️ 𝐔𝐬𝐞𝐫 𝐈𝐧𝐩𝐮𝐭 𝐢𝐧 𝐉𝐚𝐯𝐚 (𝐔𝐬𝐢𝐧𝐠 𝐒𝐜𝐚𝐧𝐧𝐞𝐫) Java provides a built-in class called Scanner to read input from the user while the program is running. There’s a simple flow involved: -->𝘐𝘮𝘱𝘰𝘳𝘵 𝘵𝘩𝘦 𝘚𝘤𝘢𝘯𝘯𝘦𝘳 𝘤𝘭𝘢𝘴𝘴 Before using Scanner, Java must be told where it comes from.This is done using import java.util.Scanner; -->𝘊𝘳𝘦𝘢𝘵𝘦 𝘢 𝘚𝘤𝘢𝘯𝘯𝘦𝘳 𝘰𝘣𝘫𝘦𝘤𝘵 The Scanner object is created using System.in , which means input will be read from the keyboard ⌨️. -->𝘙𝘦𝘢𝘥 𝘶𝘴𝘦𝘳 𝘪𝘯𝘱𝘶𝘵 Different methods are used based on the data type: • nextLine() → text • nextInt() → whole numbers • nextDouble() → decimal values -->𝘜𝘴𝘦 𝘵𝘩𝘦 𝘪𝘯𝘱𝘶𝘵 Once the input is stored in variables, the program can display it, compare it, or apply logic ⚙️. -->𝘊𝘭𝘰𝘴𝘦 𝘵𝘩𝘦 𝘚𝘤𝘢𝘯𝘯𝘦𝘳 Closing the Scanner releases the input resource after the program finishes ✅. This small setup is what transforms a static program into an interactive one ✨. I’ve also attached a simple Java program that takes input from the user and uses it - feel free to go through it for better understanding. #Java #CoreJava #JavaBasics #LearningJourney #Programming #BuildInPublic
To view or add a comment, sign in
-
-
Day 4 - 💻 Java main() Method The main() method is the entry point of every Java program. When we run a program, the JVM starts execution from main(). ✅ Syntax: public static void main(String[] args) 🔹 public → JVM can access from anywhere 🔹 static → no need to create object to call 🔹 void → returns nothing 🔹 main → fixed method name searched by JVM 🔹 String[] args → used for command-line inputs 📌 If main() is missing, Java program won’t run.
To view or add a comment, sign in
-
-
Basics about Strings in Java: Declaration: The syntax for declaring a string is as simple as any other data type in Java. String name = "Ashutosh" ; Memory representation: The reference variable "name" is stored in Stack memory and it points to an Object with value "Ashutosh" which is created in a "string pool" in heap memory. String pool is a memory structure in heap where string objects are stored. If 2 objects have the same value, instead of creating 2 different objects, both the reference variables point at the same object. This saves a lot of heap memory.
To view or add a comment, sign in
-
-
Day - 3 : Methods in Java A method is a function written inside the class. Since Java is the object oriented programming language, we need to write the method inside same class. ● Calling a method : A method can be called by creating the object of the class in which the method exists followed by the method call. ● Void return type : When we don't want our method to return anything, we use void as the return type. ● Static Keyword: Static keyword is used to Associate a method of a given class with the class with the class rather than the object . Static method in a class is shared by all objects. ● Syntax : datatype name( ) { // method body; } ● Example : class java { static void add(int a, int b) { System.out.println("Sum = " + (a + b)); } public static void main(String[] args) { add(10, 20); } } #Java #CoreJava #Arrays #MultidimensionalArray #FullStackJava #LearningInPublic EchoBrains
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