












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













Chapter Objectives: Class and object Notion of class and object Class declaration Declarations of attributes and methods Types of variables (primitives and objects) Reference concept The builders Object Oriented Design & JAVA Programming
Election Management System OOP: Class identification Classes are the fundamental components of OOP It is a basic unit of object oriented programming and represents real life entities. Candidate Citizen Vote
The concept of using classes and objects is to encapsulate state and behavior in a single programming unit. Java objects are similar to real world objects. For example, we can create a car class in Java, which will have properties such as current speed and registration; and behavior like: rolling and changing Tire…. Car Class and object concept
When you create a java class, you must follow this rule: the file name and the class name must be the same. Car written with a capital V is not the same as car written with a lowercase v. Class concept: Class name
An object is therefore "resulting" from a class, it is the product that comes out of a mould. In reality we say that an object is an instantiation of a class A class is made up of two parts: Attributes (sometimes called member data): this is the data representing the state of the object Methods (sometimes called member functions): these are the operations applicable to objects object = instance Class concept: Class name
JAVA keywords Avoid java reserved words such as:
Variable declaration We declare a constant with the final word The name of the constant must be in uppercase. If the name is composed of several words, we use _ for the separation of words Constant: Example: final int CAPACITY=2000; Example: final int SIZE; final int MAX_STOCK;
Primitive variables Declaration of a primitive variable Reservation of memory space. int age; boolean inscrit; char genre; age Variable declaration inscrit genre Value assignment Variable will be stored in the reserved memory space. age=18; inscrit=true; genre=‘M’; age inscrit genre 18 true M
Minimum value Maximum value coded on byte - 128 127 8 bits short - 32 768 32767 16 bits int - 2147 483 648 2 147 483 647 32 bits long
4775808 9223372036854 775807 64 bits **Minimum value Maximum value coded on float 1.4E45 3.4028235E38 4 octets double 4.9E
7E 8 octets Variable declaration** Integer types The real types
Variable declaration The char character type char gender='M'; The boolean type boolean Registered=true; The string type String String message = ''Hello Word'';
Class Instantiation To instantiate a class, that is to say to create an object from a class, it is a question of using the new operator. In fact, the new operator, when used, calls a special method of the class: the constructor.
The constructor a constructor has the same name as the class in which it is defined a constructor has no return type (not even void) a constructor can have arguments defining a constructor is not required when it is not needed
Using This