Java ArrayList class is a part of unified architecture (collection framework) interfaces are present in java.util package and used when we want to change the array size when your Java program run. You know that arrays are that they’re fixed size that must be specified the number of elements when the array created. How to add elements values to an array in java that filled? It’s an easy way to create a more extensive array, and all its elements are copied from the (smaller) source array to the (broader) target array, with the remaining space for new elements. It’s an alternative is to use the ArrayList whose size can change frequently. An instance of Java ArrayList class contains an array that dynamically increased as required so that it relaxes the programmer from the burden of doing this. [Read more…] about Java ArrayList class with Example
Java Generics Tutorial | Java Generics Example
Java Generics are used to enforce type-safety in a program. A type-safe program does not have compilation and run-time errors that can result from using incorrect data types. [Read more…] about Java Generics Tutorial | Java Generics Example
Collections in Java With Examples
The collections framework consists of several interfaces and classes (in the java.util package) that define data structures to store data, search for and retrieve data, and perform other operations on a collection efficiently. An example is the ArrayList class. [Read more…] about Collections in Java With Examples
Singleton Class in Java with Example
What is a Singleton in Java?
Singleton Class in Java: A given class whose object (an instance of the class) is instantiated only once in JVM (Java Virtual Machine) and that only global instance of an object of the class used for every access. Such objects are mainly immutable. [Read more…] about Singleton Class in Java with Example
The four Ps of protection in java
Java provides four levels of protection for methods and instance variables: public, private, protected and package. Before applying protection levels to a program, one should know what each form means and understand the fundamental relationships that a method or variable within a class can have to the other classes in the system. [Read more…] about The four Ps of protection in java
Overriding Constructors in Java
Super-class constructors cannot be overridden as the constructors have the same name as their class. To be able to access a constructor in a sub-class with the same number and data type of arguments as in the super-class, it must be defined in the sub-class itself. When constructors are defined in a sub-class, the corresponding super-class constructors are called during the creation of objects of that sub-class. This ensures that the initialization of inherited parts of the objects takes place similar to the way the super-class initializes its objects. Thus, defining constructors explicitly in the sub-class will override or overload super-class constructors. [Read more…] about Overriding Constructors in Java
Constructor Methods in java
Constructor methods initialize new objects when they are created. Unlike regular methods, constructor methods cannot be called directly. They are called automatically when a new object is created. When an object is created in Java using the keyword new the following things happen: [Read more…] about Constructor Methods in java
Class methods in Java
Apart from class and instance variables, Java also has class and instance methods. The differences between the two types of method are analogous to the differences between class and instance variables. Class methods are available to any instance of the class itself and can be made available to other classes. Therefore, some class methods can be used anywhere, regardless of whether an instance of the class exists or not. [Read more…] about Class methods in Java
Passing Arguments to Methods in Java
There are mainly two ways of passing arguments to methods: [Read more…] about Passing Arguments to Methods in Java
What is a Class in Java? – Definition
Classes are the fundamental building blocks of any object-oriented language.
A class describes the data and behaviour associated with instances of that class. When a class is instantiated, an object is created: this object has properties and behaviour similar to other instances of the same class. The data associated with a class or object is stored in variables. The behaviour associated with a class or object is implemented by means of methods. Methods are similar to the functions or procedures of procedural languages such as C or Pascal. [Read more…] about What is a Class in Java? – Definition
Benefits of OOP in Java
• Code reusability New objects can be derived from old objects, allowing for improvement and refinement of the code at each stage and also preserving parts of the code for other programs. This is used to develop many class libraries using class codes that have already been written, for example, Microsoft Foundation Classes (MFC). [Read more…] about Benefits of OOP in Java
Difference between OOP and Procedure Oriented Programming
Now that we know the basic concepts in OOP, we are in a position to compare it with classical procedure oriented programming. [Read more…] about Difference between OOP and Procedure Oriented Programming
Characteristics of OOP in Java
In early days, programs were collections of procedures acting on data. A procedure is defined as a collection of instructions executed in sequential order. Data were independent of the procedures and programmers have to keep track of functions and the way they modify data. Structured programming is a simpler way to tackle this situation. [Read more…] about Characteristics of OOP in Java
Objects and Classes in Java
Objects and classes are the building blocks of OOP. To understand OOP, first we have to know what objects and classes are. [Read more…] about Objects and Classes in Java
Adding the Contents of Two objects by passing objects as parameter.
Calculate hra,da and gross salary of worker by passing Object as Parameter
Passing student Object as Parameter in Java Example
Example of Super Class By Feeding Employee Detail
Example of Super Class And Calculate Average of Three Variables
Example of Nested Class in Java
Inner class in java with Example
A nested class as the name suggests is a class that is defined inside another class. It is merely a convenient way of grouping two or more classes together into a single unit or module. A class that contains a nested class is known as the enclosing or outer class of the nested class. [Read more…] about Inner class in java with Example
Nested Class in Java Example
Nested class is also defined as a static member in a top level class. And the nested class can be instantiated using its full name and no instance of the enclosing class is required to instantiate a top level nested class. [Read more…] about Nested Class in Java Example
Enter Detail of Worker using Constructor Overloading
Calculate Average of Three Variable using Constructor Overloading
Calculate Area of Rectangle using Constructor Overloading
Constructor Overloading means a class having multiple constructors with the same name, but with different number of arguments or different type of arguments. The compiler differentiates the constructors based on the number of parameters in the list and their types. That means, on the basis of the number and type of the arguments that we pass into the constructor, the compiler determines which constructor to call. [Read more…] about Calculate Area of Rectangle using Constructor Overloading
Enter Student Detail and Print them Using parameterized constructor
Calculate Area of Rectangle using Parameterised Constructor
Calculate Area of Rectangle Using Default Constructor
Constructors are the methods having the same name as that of the class and are automatically executed on defining an object. The main purpose of a constructor is to initialize a new object. [Read more…] about Calculate Area of Rectangle Using Default Constructor
What is abstract data type (ADT)?
A DATA STRUCTURE which is accompanied by a set of ACCESS FUNCTIONS that must be employed to create objects of that type and access their contents, without the programmer being concerned with the internal layout of the data structure. The CLASSES employed in OBJECT-ORIENTED PROGRAMMING are abstract data types whose concealment is actually enforced by the language syntax, but abstract data types may be created in conventional languages such as C, PASCAL and MODULA-2 too, where the concealment is voluntary. [Read more…] about What is abstract data type (ADT)?