Here is the listing of Java programming examples on Classes.
1. Java Examples on Classes
A class can be defined as a template that describes the behavior that the object of its type support. Class is declared by use of the class keyword. The data or variables, defined within a class are called instance variables. Java inner class or nested class is a class which is declared inside the class or interface. Member Inner class created within class and outside method. A class created within method is called Local Inner Class. Static Inner class creates within a class. A class created for implementing interface or extending class. Its name is decided by the java compiler is called Anonymous Inner Class. Abstract class is used to provide abstraction in java. This section contains Java programs on classes like abstract class, instance inner class, static inner class and anonymous inner class. This section also contains programs to check whether given class is inner class, local class or anonymous class.
Java Program to Illustrates Use of Abstract Class and Method
Java Program to Illustrates Use of Instance Inner Class
Java Program to Illustrates Use of Static Inner Class
Java Program to Illustrates Use of Referencing the Object from Inner Class
Java Program to Illustrates Use of Anonymous Inner Class
Java Program to Illustrate Use of All Features of Abstract Class
Java Program to Check if a Given Class is Inner Class
Java Program to Check if a Given Class is Local Inner Class
Java Program to Check if a Given Class is Anonymous Class
Java Program to Design a Class Using Abstract Methods and Classes
2. Java Examples on Methods
Method is a collection of statements that are grouped together to perform an operation. Parameter is a value that you can pass to a method. getChar() method is used to get characters from given given string. split() is used to divide the given string into array of strings depending upon the positions of blank spaces. This section contains Java programs on usage of methods, illustrate a method without parameters and with or without return types. It also explains the uses of methods in class, getchar() and split() methods.
3. Java Examples on Strings
String is a sequence of characters. In Java, strings are objects. String class is used to manipulate character strings that cannot be changed. String class with Methods are used to concat, compare, touppercase, tolowercase, trim, length, equals, split etc. Important methods of string class are UpperCase() and Lowercase() methods. StringBuffer class is used to represent characters that can be modified. This section contains Java programs on important methods of string class like upper and lower case, searching a string using equalsIgnoreCase() methods, usage of StringBuffer class methods and checks whether given string is palindrome or not.
Java Program to Check whether a String is a Palindrome
Java Program to Create Strings and How to Use Some Important Methods of String Class
Java Program to Search for a Given String in an Array of Strings Using equalsIgnoreCase() Methods
Java Program to Illustrate Use of StringBuffer Class Methods
Java Program to Find the Areas of Square and Rectangle by Deriving them from Shape
4. Java Examples on Constructor
Constructor initializes an object immediately upon creation. Calling a constructor from the another constructor of same class is known as Constructor chaining. Constructor with arguments is known as Parameterized constructor. This section contains Java programs on use of constructor, creating a objects and assigning values by using constructors, usuage of chaining constructor, initialization of classes and strings using constructor, parameterized constructor, use of constructor overload and method overload.
Java Program to Illustrate Use of Constructor
Java Program to Illustrate Use of Chaining Constructor
Java Program to Create the Object for Class and to Assign Value in the Object Using Constructor
Java Program to Allocate and Initialize Super Class Members Using Constructor
Java Program Which has 2 Classes Which Initializes a String in Its Constructor
Java Program to Illustrates Use of Chaining Constructor
Java Program to Initialize the Instance Variables of Employee Class, Using Parameterized Constructor
Java Program to Illustrate Use of Constructor Overload and Method Overload
Java Program to Show How to Class will be Loaded Using Constructor
5. Java Examples on Super Class
Superclass is a class which gives a method or methods to a Java subclass. A Java class may be either a subclass, superclass or both. Super keyword is used to refer the objects of immediate parent class. Subclass inherits state and behavior in the form of variables and methods from its superclass. This section contains Java programs on accessing the super class method and instance variable with or without using super keywords. It also contains programs on super class constructors.
6. Java Examples on Variables
Variables are the identifier of the memory location, which is used to save data temporarily. it is necessary to declare the variable before being used. A variable which is declared inside the class but outside the method, is called instance variable. It is not declared as static. This section contains Java programs on accessing the static or non static variable, usage of instance and static variables in text class, initializing the instance variables in classes.
Java Program to Test whether a Static Method can Access the Static or Non-Static Variable
Java Program to Demonstrate Usage of an Instance Variable x in the Test Class
Java Program to Demonstrate Usage of a Static Variable x in the Test Class
Java Program to Accepts a Group of Numbers and Returns Bigger Number Using Method with Variable Arguments
Java Program to Initialize the Student Class Instance Variables in Demo Class
Java Program to Initialize the Instance Variables Directly Within the Person Class
7. Java Examples on Static Method
Static method call is the method name followed by its arguments, separated by commas and enclosed in parentheses. Variable which is declared inside the class but outside the method, is called instance variable. It is not declared as static. Variable that is declared as static is called static variable. This section contains Java programs on static method which accepts data and returns the result, checks whether static block or static method will executes first. It also checks whether a static method can access the instance or static variables.
Java Program to Check Whether Which One is Executed First, Static Block or the Static Method
Java Program for a Static Method that Accepts Data and Returns the Result
Java Program to Check Whether a Static Method Can Access the Instance Variable
Java Program to Check Whether a Static Method Can Access the Static Variable
8. Java Examples on Methods and Reference in Classes
Hash code is an unique id number allocated to an object by JVM. Calling a method by passing a value is called as call by value. This section contains Java programs to call cube() method, finding the arguments provided at runtime, use of hashcode() method, creation of reference classes, displaying gregoriancalendar using mutator, usage of call by value and call by reference.
Java Program to Illustrate the Use of HashCode() Method
Java Program to Make Shape as an Interface and Implement it Using Circle and Rectangle Class
Java Program to Split into Pieces Wherever a Space is Found
Java Program to Illustrate Call By Value and Call By Reference
Java Program to Create the Reference of Class Two in Class One Using this Reference
Java Program to call cube() Method in Class One
Java Program to Display GregorianCalendar Using Mutator and Accessor Methods
Java Program to Find the Number of Arguments Provided at Runtime
9. Java Examples on Real time Applications
This section contains Java programs on real time applications like displaying the inventory items in store, designing class account to display all bank functions, creation of outer class bank account and inner class interest. accepting persons name and age and display whether person is young or not.
Java Program to Create the Outer Class BankAcct and Inner Class Interest
Java Program to Display the Inventory of Items in a Store
Java Program to Design a Class Account that Show all Function of Bank
Java Program to Create the Outer Class Bank Account and the Inner Class Interest in it
Java Program to Create Person Class and an Object Raju to Person Class. Let Us Display the Hash Code Number of the Object
Java Program to Accept a Person’s Name and Age Through Command Line Arguments and Display If He is Young
10. Java Examples on Objects and Static Blocks
An entity that has state and behavior is known as an object. Static block is used for initializing the static variables. Static block gets executed when the class is loaded in the memory. The Java programs in this section illustrates the values inside an object, use of instance and static blocks, program to interchange the objects by using swap() method.
Java Program to Interchange Two Employee Objects by Passing them to Swap() Method
Java Program to Interchange the Values Inside an Object
Java Program to Illustrates Use of Instance and Static Blocks
Java Program to Show Work Class Loading and Static Blocks Execution Using Static Modifier
Java Program to Illustrate Class Loading and Static Blocks in Inheritance Concept
11. Java Examples on Package Creation
Package is a group of similar types of classes, interfaces and sub-packages. There are two types of packages user defined and built-in packages. This section contains Java programs on creation of packages and accessing the members of external class.
Java Program to Create a Package that Access the Member of External Class as well as Same Package
Java Program that Import the User Define Package and Access the Member Variable of Classes that Contained by Package
Java Program to Create a Package that Access the Member of External Class as well as Same Package