Saturday, June 8, 2019

DATA TYPES - JAVA PROGRAMMING

Anu K Joy


In this blog, you learn the data types available in Java programming language.




In Java program, you cannot even declare a variable without specifying its data type.The data type specifies the size and type of values that can be stored in an identifier. 


There are two types of data types in java :

1. Primitive data types

2. Non-Primitive data types



Primitive Data Types




There are 8 primitive data types in java 

Integer Data Types


  • Integer  - Represents integers using byte, short, int and long.

    byte data type    



            

short data type




Int data type



Long data type



Note :  

             If you need to store a small data, you must use the byte data type and if you use any other data types other than byte, it allocates extra memory space and leads to increase in execution time.


Floating- Point Data Types


  • Floating - Represents Fractional numbers...float and double data types.



Note :

  •  you should end the value with an "f" - Float data type
  • you should end the value with an "d"- Double data type           
The float data type can represent a maximum of 7 digits after decimal while, the double data type can represent 15 digits.


Character Data Types


  • Character - Represents char.
  • An example of char data type is,
                        char dis = 'A';

Boolean Data Types



  • Boolean - Represents two logical values denoted by true or false.
  • Example is,
                                  boolean x = true;


Non Primitive Data Types



  • Sometimes called "reference variables," or "object references. Because, they refer to objects
  • Examples of non-primitive data types are Strings, Arrays, Classes, Interface etc..
we will learn more in detail about Data types in Java programming in coming blog.


Blogger
SEO Analyst
Digital Marketing Consultant


You can also visit my blogs ; 


OOP CONCEPTS - JAVA PROGRAMMING


Friday, June 7, 2019

OOP CONCEPTS - JAVA PROGRAMMING

Anu K Joy        
                             OOP  CONCEPTS
 (Object Oriented Programming)
                     
oops_java

The basic concepts of OOP are as follows :

  • Object
  • Class
  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism

1. Object

  • In Object-Oriented programming, Object is a basic unit and it represents the real life entities.
An Object consist of       

 -  Identity  (unique name to an object)

  - State ( represents the properties of an object)

   - Behavior(methods of an object)

Example of an object : Bicycle



2. Classes


  • In Object-Oriented programming, a class is a blueprint of  an object.
  • A class is a collection of objects of similar type.
  • For example : car,bike,scooter are members of the vehicle class.

3.Abstraction


  • Abstraction is representing important features by hiding  the implementation details.
  • The advantage of abstraction is that, the user can work only with the required data and does not need to view unwanted data and it helps to reduce programming  complexity and effort. 
Example of  Abstraction to understand the concept,
                                            A lady is driving a car, she only knows  that the accelerators will increase the speed of the car or applying brakes will stop the car but she doesn't know the inner mechanism of the accelerator  and the brake.This is what Abstraction is..

4.Encapsulation

  • Encapsulation means, binding variables and methods under single entity.
For Example a capsule which is mixed of several medicines.



5.Inheritance

  • Inheritance means, acquiring  the properties of one class to another class.
  • A class that is inherited from another class is called subclass or derived class or child class.
  •  The class from which the subclass is inherited is known as the superclass or the base class or parent class.



Now, let's look at figure.... Here, Class A is superclass and Class B is sub class.The subclass is derived from superclass that contains the combined features of both the classes.


There are  various types of inheritance in Java :

  1. Single Inheritance
  2. Multiple Inheritance
  3. Multilevel Inheritance
  4. Hierarchical Inheritance

6.Polymorphism

  • The term ' Polymorphism ' comes from two Greek words that is poly, meaning many and morphs meaning forms.
  • Therefore, polymorphism means, ' many forms'.

In Object-Oriented programming, polymorphism allows you to perform same method in different operation.

  • Polymorphism are of two types :

                                           1. Compile time polymorphism
                                           2. Run time polymorphism                                                   
The method Overriding is an example of Run time polymorphism and method Overloading is an example of Compile time polymorphism.


Hope you get the basic concepts of OOP. So we will discuss each concept in detail in coming blog.

If else statement in java ( with examples) - Java World

In this article, you will learn to use two selection statements: if and if else to the statements which alter the flow of  your program’s ...