This program enters users details (name, address, city, date of birth, phone number, email Id). It then maps phone numbers to names with the help of HashMap. Finally, it tells the name of the user which is searched by entering the phone number.
Prerequisite
Java is an object-oriented programming language. It allows you to divide complex problems into smaller sets by creating objects and objects having similar behavior and properties are grouped together in a single unit called class.
Java class
Before you create objects in Java, you need to define a class. A class is a user defined blueprint or prototype from which objects are created. It represents the set of properties or methods that are common to all objects of one type.
Java Object
An object is a basic unit of Object Oriented Programming and represents the real life entities. An object is an instance of a class. A class is a template or blueprint from which objects are created. So, an object is the instance(result) of a class. A typical Java program creates many objects, which as you know, interact by invoking methods.
Code
Explanation
Java Class Types
Model class- Model class is a class which represents data object which can be used for transferring data in java application. It encapsulates direct access to data in object and ensures all data in object is accessed via getter methods. Here class User is a model class.
Service class- A Service class is used by a client to interact with some functionality in your application.The general pattern for a service method is to extract information from the request, access external resources, and then populate the response, based on that information. In this program, UserService is the service class.
Application class- application class acts as a coordinator which calls the service class so that it is able to perform its task by invoking the model class.
HashMap
Java HashMap is a hash table based implementation of Java’s Map interface. A Map, as you might know, is a collection of key-value pairs. It maps keys to values.
Running the code
Feel free to post queries.
2 thoughts on “User Management Program in Java”