Operators in Java

In Java, operators are special symbols that perform operations on variables and values.They can be grouped into several categories: 1. Arithmetic Operators Used for basic mathematical operations. OperatorDescriptionExample (a=10, b=3)Result+Additiona + b13-Subtractiona - b7*Multiplicationa * b30/Divisiona / b3%Modulus (remainder)a % b1++Increment (by 1)a++11--Decrement (by 1)a--9 2. Relational Operators Used to compare two values (result…

0 Comments

enums in java

In Java, enums (short for enumerations) are a special type of class used to define a fixed set of constants. They’re type-safe, more powerful than just using final static constants, and can even have methods, fields, and constructors. 1. Basic Syntax enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY } enum Day…

0 Comments

Arrays in Java

In Java, the Arrays class is a utility class from the java.util package that provides a collection of static methods for working with arrays. It helps you perform common tasks like sorting, searching, comparing, filling, and converting arrays to strings without writing all the low-level loops yourself. Importing import java.util.Arrays; import java.util.Arrays; Common Methods…

0 Comments

Object, Class, Math and System in Java

1. Object Class Package: java.lang Role: The root class of all classes in Java. Every class inherits from Object. Key Methods: toString() Returns a string representation of the object. equals(Object obj) Checks if two objects are equal. hashCode() Returns a hash code for the object. getClass() Returns the runtime Class object of the object.…

0 Comments

Basic interfaces in java.lang

Common Interfaces in java.lang InterfacePurposeKey MethodsAppendableAllows an object to receive appended character sequences. Implemented by classes like StringBuilder, StringBuffer, Writer.append(CharSequence csq), append(char c)CharSequenceRepresents a readable sequence of char values. Implemented by String, StringBuilder, StringBuffer, CharBuffer.length(), charAt(int index), subSequence(int start, int end)CloneableMarks classes whose objects can be cloned using Object.clone(). (Marker interface — no methods).(No…

0 Comments

StringBuffer and StringBuilder in Java

StringBuffer and StringBuilder are both Java classes for creating and manipulating mutable sequences of characters, but they differ in thread safety and performance. Here’s a breakdown: FeatureStringBufferStringBuilderMutabilityMutable (like StringBuilder)Mutable (like StringBuffer)Thread SafetyYes — methods are synchronized, so multiple threads can use the same object without corrupting dataNo — methods are not synchronized, so unsafe…

0 Comments

Method overriding and method overloading

Let’s break down method overriding and method overloading clearly and compare them. These are concepts in object-oriented programming (OOP), commonly in languages like Java, C++, and C#. 1. Method Overriding Definition:Method overriding occurs when a subclass (child class) provides its own implementation of a method that is already defined in its superclass (parent class).…

0 Comments

Primitive type casting in Java

In Java, primitive type casting is converting one primitive data type into another.It’s split into two categories: widening (implicit) and narrowing (explicit) casting. 1. Widening Casting (Implicit) Also called type promotion — smaller types automatically convert to larger types without data loss. Order of promotion:byte → short → int → long → float →…

0 Comments

Pass by value vs pass by reference for methods in Java

In Java, when you talk about "pass by value" vs "pass by reference" for methods, the key point is: Java is always pass-by-value — but what is passed by value depends on the type of variable. 1. Pass-by-Value (for primitives) When you pass a primitive type (int, double, char, boolean, etc.) to a method:…

0 Comments

Wrapper classes in Java

In Java, wrapper classes are special classes that let you treat primitive data types as objects. They "wrap" a primitive value in an object so it can be used where an object is required (for example, in collections like ArrayList that can’t store primitives directly). 1. Primitive Types & Their Wrapper Classes Primitive typeWrapper…

0 Comments

End of content

No more pages to load