Interface

Hello everybody! Good day, how are you? well i’m just fine. Last time we talked about abstraction, basically abstraction is a process that hides the details of the code from the users that use it, and will only show it’s functionality (you can see my last post about abstraction). An example of abstraction is like a postman, we don’t need to know how the postman will send our letter, we only knew that the postman will send us our letter. Today we’ll talk about Interface, because it’s still a part of Abstraction.

Do you wonder what is an Interface is? if you do, good thinking. Interfaces is a way to achieve a full abstraction, which is needed to hide anything that the users doesn’t need to know. But for now let’s get the meaning of Interface, can you tell me what it is? well more or less it’s like this :
Interface is a reference type in Java, it is similar to class but a bit different, an Interface is a collection of Abstraction or by default is abstract(it have an empty body and only a method signature). A class can implements more than one Interface, but a class can’t extends more than one class.

Just think of this, your tv power button. It’s an Interface between you and the electrical wire on the inside or in the other side of the tv, using that button you turn on and off the tv.
Let’s take a common example of an interface, basically interface is a group of related methods with empty bodies. Look at this bicycle’s behavior, if specified as an interface, the code might appear as follows:

 
interface Bicycle {

void changeGear(int newValue);

void speedUp(int increment);

void applyBrakes(int decrement);
  }

if you want to implements it to a new class bicycle, you can name the bicycle into anything you want, but for now let’s name it tandem bike. If you want to implement it to your tandem bike class you need to make a declaration of the interface after the class name itself, and if you put it into a working code, it would look like the following :

class TandemBike implements Bicycle {

int speed = 20;
int gear = 2;

/*The compiler will now require that methods
changeCadence, changeGear, speedUp, and applyBrakes
all be implemented. Compilation will fail if those
*/ methods are missing from this class.

void changeGear(int newValue) {
gear = newValue;
}

void speedUp(int increment) {
speed = speed + increment;
}

void applyBrakes(int decrement) {
speed = speed - decrement;
}

void printStates() {
System.out.println("speed: " +
speed + " gear: " + gear);
}
}

This will output the following of :

speed: 2 gear: 2

Conclusions

  •  Interfaces is a way to achieve a full abstraction.
  •  Interface is a reference type in Java, it is similar to class but a bit different, an Interface is a collection of Abstraction or by default is abstract(it have an empty body and only a method signature).
  •  A class can implements more than one Interface, but a class can’t extends more than one class. 
  • If you want to implement it to your tandem bike class you need to make a declaration of the interface after the class name itself.

Abstraction

Hello, how are you doing? well i am fine indeed.On my last post we talked about Encapsulation, encapsulation is basically a way to make our code hidden, this means that the code inside the class can only be accesed inside that class itself and other class couldn’t. Today let’s talk about Abstraction because it’s another important prospect . Lets be done with the chit-chat and lets begin.

Abstraction… hmm you may wonder and wonder and wonder… what is abstraction, what is abstract. Hella good question, abstract means something that is not a material object or is general and not based on specific examples, or in other word something that is seperate from something or anything else. Well on today post we’ll talk about something a bit different,
abstraction in programming is any process of hiding  object or a thing implementation details from the user that uses it, the thing that will only be provided is its functionality. In other words the code will tell the users what the object does instead of how it does it.

Just think about a potoffice, when you’re going to send a mail you just need to give it to the postman and he will send it to anyone you’re sending the mail with, the postoffice will not tell you how the postman send you mail, they will just tell you that  what the postman do is to send your mail. That’s the simple explanation about abstraction in normal life. Well the postman thing doesn’t have anything related with coding but it’s just an example to make your understanding better.

If we’re talking about abstraction we must talk about abstract class. Abstract class are the class that contains the keyword abstract in its declaration. Here are the characteristic of an abstract class :

  • Abstract classes may or may not contain abstract methods ie., methods with out body ( public void get(); )
  • But, if a class have at least one abstract method, then the class must be declared abstract.
  • If a class is declared abstract it cannot be instantiated.
  • To use an abstract class you have to inherit it from another class, provide implementations to the abstract methods in it.
  • If you inherit an abstract class you have to provide implementations to all the abstract methods in it.
Those characteristic Content are from tutorialspoint
Conclusions 
  • Abstraction in programming is any process of hiding  object or a thing implementation details from the user that uses it, the thing that will only be provided is its functionality.
  • Abstract class are the class that contains the keyword abstract in its declaration.

Encapsulation

Hello, how are you doing? well i am fine indeed.On my last post we talked about a bug and a way to debug it, it’s basically a failure inside a code that makes the program to do the things it’s not suppose to do or instead it do something else. Today we’ll talk about Encapsulation in java to protect our program
. First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

What is a encapsulation? does any of you know what is a encapsulation? because this is another important things in OOP or Object Oriented Programming. O.k… if you don’t know what it is, let me just tell you
Encapsulation is one amongs of the four of the OOP concepts. The other three are inheritance, polymorphism, and abstraction. here is the definition, Encapsulation is just the way that Java use as its mechanism to wrap data (variable) and code acting on data (methods) all together in one unit. In encapsulations mechanism all of the variables of any class will be hidden from any other class, and can and could only be accesed through the methods of their current class and therefore encapsulation is called as data hiding.class, therefore it is also known as data hiding.

these are the example of data hiding :

/* File name : EncapTest.java */
public class EncapTest{

private String name;
private String idNum;
private int age;

public int getAge(){
return age;
}

public String getName(){
return name;
}

public String getIdNum(){
return idNum;
}

public void setAge( int newAge){
age
= newAge;
}

public void setName(String newName){
name
= newName;
}

public void setIdNum( String newId){
idNum
= newId;
}
}

you see how the variable is written in private, this means that the variable can only be accesed or used inside the EncapTest class only, and could not be accesed outside the EncapTest class.

conclusions

  • Encapsulation is one amongs of the four of the OOP concepts. The other three are inheritance, polymorphism, and abstraction.
  • Encapsulation is just the way that Java use as its mechanism to wrap data (variable) and code acting on data (methods) all together in one unit.
  • The variable can only be accesed or used inside the EncapTest class only, and could not be accesed outside the EncapTest class.
 

Bug and Debugging it!

Hello, how are you doing? well i am fine indeed.On my last post we talked about function in OOP, it’s basically a named sections of a program that do specific tasks for us the operator. Today we’ll talk about bug (In coding) and how coders debug it which is frequently called debugging. First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

Have you ever seen  a program that has errors or glitch? of course you have! every program have at least one bug inside its written code. It’s rather frustating for a coder that it’s core codes is full of bugs, of course they will try to fix it, and we’ll take a peak on how they do things just like that!. But first before we get to that let’s find out what’s the meaning of bug itself
(remember everything that is written in here is about coding except a couple of things). A bug is an error, flaw, failure or fault inside a computer program or software that will cause a program to produce a false, incorrect or any unexpected results, or to behave in unintended ways that the operator or the users doesn’t want.

Now that we have a strong grip of what the meaning of a bug is, we’ll be able to go further into debugging. Does anyone has heard the word “Debugging” ? well some of you may but some of you may not, it’s simply is a way to fix a bug inside a program or a software, for the full definition, here it is: Debugging is the process that the writers of the code do to find and to resolve of defects that will prevent the program or software to work correctly.

After we understand what bug and debugging means, you might wonder, how does coders debug their program or software?. Good question there, they usually use a Debugger tools which will enable the programmer or coder to monitor all of the execution of a program or software, he can stop it, restart it, set any breakpoints, and could change the values that is inside the memory. The word “Debugger” can also refer to a person that is doing the debugging, usually this is the creator of the program itself.

Hight-level programming language like Java, C++ etc… can make debugging activity easier, because most of them have features like exception handling that make real sources of erratic behaviour easier to spot with the coders eyes. In some programming language like CC or assembly, the bugs can create a silent problems such like memory corruption, and it is often hard to spot where the initial problem was happening. In case that happens to you, you can use memory debugger tools.

Conclusions

  •  A bug is an error, flaw, failure or fault inside a computer program or software that will cause a program to produce a false, incorrect or any unexpected results, or to behave in unintended ways that the operator or the users doesn’t want.
  •  Debugging is the process that the writers of the code do to find and to resolve of defects that will prevent the program or software to work correctly.
  • The word “Debugger” can also refer to a person that is doing the debugging, usually this is the creator of the program itself.

Function Definitions

Hello, how are you doing? well i am fine indeed.On my last post we talked about A Methods meaning, the its definitions in general and its definition inside coding world, because it is one of the most important chunk of code inside a class(see my last post abou Methods meaning). First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

Just like always, before we start talking, first we’ll get the definition of function itself… which is this : an activity or purpose natural to or intended for a person or thing. It seems that it doesn’t have any connection with programing… well it’s because it doesn’t have any connection. That’s just the function definition in general, before we go farther away from programming… let’s just get the definition of a function, but this time… inside programming, here it is :
In programming a function is a named section of a program that performs a specific task. The simple meaning is that a function is a procedure or a routines, most programming language will seperate or make a distinction beetwen a function that will returns a value, and a procedure, that will perform some operation but will not returns a value.

Most of the programming language that exists, it will come with a prewritten or build-in set of function that are kept inside a library. And besideMost programming languages come with a prewritten set of functions that are kept in a library. And beside that, you also can make your own written function inside your program that can do specialized tasks.

Here is an example of function:

Integer two = add1.apply(1); //yields 2 
String answer = concat1.apply("0 + 1 = "); //yields "0 + 1 = 1"
 

So, as you can see every function has a method apply that we use to invoke it and pass it an argument.
And what if I already have a method that does that, can I use it as a function?
Yes, since an alternative way to create functions is by using methods we had already defined and that are compatible with our function definition.

Suppose that we have the following class definition with methods as defined below:

public class Utils {
   publicstatic Integer add1(Integer x) { return x + 1; }
   publicstatic String concat1(String x) { return x + 1; }
}
 

As you can see the methods in this class are compatible with our original function definitions, so we could use them as “method references” to create the same functions we did before with lambda expressions.

Function<Integer,Integer> add1 = Utils::add1; 
Function<String,String> concat1 = Utils::concat1;
 

These two are just the same thing as the ones we did before.

Conclusions

  • In General, An activity or purpose natural to or intended for a person or thing.
  • In programming, a function is a named section of a program that performs a specific task. 

A Methods Meaning

Hello, how are you doing? well i am fine indeed.On my last post we talked about class in programming, today we’ll talk about Methods because methods are one of the most important chunk of code inside a class(check out my last post about Classes). First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

Methods… hmmm… methods, I wonder what it is, and what does it have to do with classes and objects. To get the answer let’s take a look at methods definion? well here it is
: a methods is a particular form of procedure  for accomplishing or approaching something, especially a systematic or established one.


You might wonder, what the heck does that suppose to mean? well… first… you’re tricked, this is not the real definition of methods in programming, this is a methods definition in general (haha!). I feel bad doing this, so I’ll just give you the definition of methods in programming, and here it is : A method in OOP is a programmed procedure that is defined as a part of a class and will be included in any object in that class.

How to call or execute a method? that is easy, well it took me some time to understand it but you will to eventually, here is how to call a method : 

Let’s take a look at an example of a methods :

/** the snippet returns the minimum between two numbers */ public static int minFunction(int n1, int n2) {
      int min;
      if (n1 > n2) min = n2;
      else min = n1; 
      return min; 
}

 There are actually two ways in which a method is called i.e. method returns a value or returning nothing (no return value). The process of method calling is simple. When a program invokes a method, the program control gets transferred to the called method. This called method then returns control to the caller in two conditions, when: 

  • return statement is executed.
  • reaches the method ending closing brace.

Easy right? you’ll get yourself better at it within time and within a lot of practicing. 

How about now? feeling better understanding this? well I hope you do, if you’re feeling better… let’s get to one of the most important method capabilities that is provided is methods overriding. The same name (e.g., area) can be used for multiple different kinds of classes. This allows the sending objects to invoke behaviors and to delegate the implementation of those behaviors to the receiving object. Methods inside Java programming will set the behaviour of the class object. For example, an object can send an area message to another object and the appropriate formula’s that is created will be invoked whether the receiving object is a rectangle, circle, triangle, or something else etc…
 
 Conclusions

  • A methods is a particular form of procedure  for accomplishing or approaching something, especially a systematic or established one. (In General).

  • A method in OOP is a programmed procedure that is defined as a part of a class and will be included in any object in that class.
  • This called method then returns control to the caller in two conditions, when: 
    • return statement is executed.
    • reaches the method ending closing brace. 

 

What is a Class in Coding?

Hello, how are you doing? well i am fine indeed.On my last post we talked about Reference data types, today we’ll talk about Classes in coding, what is it definition, example etc… because classes is one of the important things in OOP(see my last post about Reference Data Types). First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

What is a class? is it the place that you go to every morning when school day? well it is but that’s when you’re talking about it’s general meaning. Here we’ll talk about classes in coding, first… let’s get a grip of the meaning of the class itself,
a class in coding is a blue print from which individual objects are created. Just think of one bycicle, there must be thousands of the same kind of bycicle that exist in this world, but think… all of those bycicle will have the same blue print that is used to make it, and will have the same component for its creation. In object-oriented-programming terms, we should say that your bicycle is an instance of the class of objects known as bicycles. A class is the blueprint from which individual objects are created.

A sample of a class is given below:

public class Lion{
String maleorfemale;
int ageC
String color;

void roaring(){
}

void hungry(){
}

void sleeping(){
}
}

A class could contain any of the following variable, types :

  • Local variables: Variables that is defined inside the class methods, constructors or blocks are called local variables. The variable that is created will be declared and initialized within the method inside the class and the variable will be destroyed when the method has completed.
  • Instance variables: Instance variables are variables within a class but outside any other method. These variables will and are initialized when the class is instantiated. Instance of the variables can be accessed from inside any method, constructor or blocks that exist from that particular class.
  • Class variables: Class variables are variables declared with in a class, outside any method, with the static keyword.

A class can have any number of methods to access the value of various kinds of methods. In the above example, roaring(), hungry() and sleeping() are methods

Conclusions :

  • A class in coding is a blue print from which individual objects are created. 
  • A class could contain any of the following variable types : 
    • Local variables
    • Instance variables
    • Class variables

Reference Data Types

Hello, how are you doing? well i am fine indeed.On my last post we talked about Primitive data types, it’s still within the OOP and so the one that we’ll be talking right now, today we’ll talk about Reference Data Types(see my last post about Primitive Data Types). First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

First thing first, let’s get a definition of what Reference data types means itself, here is my definition : A Reference data types is a data types that are based out of class rather than based of  a primitive types that is built into the java language. The class that’s mentioned can be a class that Java API class library provides or it can be a class that you made yourself.


Well either way, when you create an object from a class that you or the java api class librabry made, Java will allocates the total memory that the object requires to store the object. And then, if you put or assign the object to a variable, the variable that is assigned is a reference to the object, not the object itself. This reference is the address of the memory location where the object is stored.
If you want to declare a variable that will use a reference type, you need to simply list the class name as the data type. For example, the following statement defines a variable that can reference objects created from a class named Bike:

Bike b;
after that you need to import to tell Java where to find the class. If you want to create an instance of an object from a class, you need to use the new keyword along with the class name, example :

Bike b = new Bike();

One of the key concepts that you always need to remember in working with reference types is the fact that a variable of a particular type doesn’t actually contain an object of that type. Instead, it contains a reference to an object of the correct type. An important side effect is that two variables can refer to the same object.

Consider these statements:

Ball b1 = new Ball();
Ball b2 = b1;
 

Here, both b1 and b2 refer to the same instance of the Ball class.

conclusions 

  • Reference data types is a data types that are based out of class rather than based of  a primitive types that is built into the java language.
  • If you want to create an instance of an object from a class, you need to use the new keyword along with the class name.
  • Two variables can refer to the same object.

Primitive Data Types

Hello, how are you doing? well i am fine indeed.On my last post we talked about object inheritance, an inheritance in the viewside of coding. Today, we’ll still talk about OOP because there is so much we need to cover, now we’ll talk about Primitivedata types in Java. First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

Java programming language is statically-typed, which means that all variables must be declared before they can be used, so this will involve stating the variable’s type and name just like you already know :

int = 1;

You see… this will relate to primitive data types, “why?” you might ask, it’s because that int is one the 8 primitive data types that the Java language use, before we’ll get to the 8 of the primitive data types, let’s find the definition of primitive data types itself.
Primitive data types is a data types that directly contains value, now like refference data types, that reffers to an object(we’ll talk about that later).

Now that we know its definitions let’s find out the 8 primitive data types, here is the list with its explanation :

  • byte: The byte data type is an 8-bit signed two’s complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable’s range is limited can serve as a form of documentation.
  • short: The short data type is a 16-bit signed two’s complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same guidelines apply: you can use a short to save memory in large arrays, in situations where the memory savings actually matters.
  • int: By default, the int data type is a 32-bit signed two’s complement integer, which has a minimum value of -231 and a maximum value of 231-1. In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 232-1. Use the Integer class to use int data type as an unsigned integer. See the section The Number Classes for more information. Static methods like compareUnsigned, divideUnsigned etc have been added to the Integer class to support the arithmetic operations for unsigned integers.
  • long: The long data type is a 64-bit two’s complement integer. The signed long has a minimum value of -263 and a maximum value of 263-1. In Java SE 8 and later, you can use the long data type to represent an unsigned 64-bit long, which has a minimum value of 0 and a maximum value of 264-1. Use this data type when you need a range of values wider than those provided by int. The Long class also contains methods like compareUnsigned, divideUnsigned etc to support arithmetic operations for unsigned long.
  • float: The float data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead. Numbers and Strings covers BigDecimal and other useful classes provided by the Java platform.
  • double: The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.
  • boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its “size” isn’t something that’s precisely defined.
  • char: The char data type is a single 16-bit Unicode character. It has a minimum value of 'u0000' (or 0) and a maximum value of 'uffff' (or 65,535 inclusive).
The example and definition of those Primitive data types are obtained from Java documentary
 Conclusions 
  • Java programming language is statically-typed. 
  • All variables must be declared before they can be used
  •  Primitive data types is a data types that directly contains value, now like refference data types, that reffers to an object(we’ll talk about that later).
  • Java documentary 
 

Object Inheritance

Hello, how are you doing? well i am fine indeed.Since we talked about OOP much lately, let’s just get into one more important thing that OOP provides for us programmers or coders, which is an inheritance.We’ll get into it’s deep meaning and we’ll understands it more. First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

 Okay, there is one more important thing in OOP that i want to talk about, which is an object inheritance, before we get to coding object inheritance, let’s just get the general explanation for inheritance.
Inheritance is all part of a person’s estate/assets that is given to an heirs once the person is deceased or dead. An Inheritance basically is a cash endowments that is given to it’s younger heirs from the people that are deceased. If at the time of death a will is not in place, determining the rightful heirs can be a much more complicated matter.

Wait!! we’ve gone to far now! Pheww, I lost my tracks. Let’s get back to coding, now we’ve understand what inheritance in general means, let’s get to OOP inheritance. If an inheritance in general lead to cash endowment or assets, coding inheritance is a bit different, just imagine a bycicle superclass is bycicle then after that comes another placements, types of bycicle, there are mountain bike, tandem bike etc… now the types of the bycicle are the class that inherits from bycicle, both of them had their own properties but will, have the properties that is passed down from superclass Bycicle, if you’re confused just read this, in coding an inheritance is when an object is based from a prototype of another object, using the same implementation (inheriting from object or class) specifying implementation of the object to maintain the behavior to be similar.

There we go! now that’s a coding inheritance, in coding we won’t be confused with an heirs and assets(haha). Now that we know what inheritance in coding is, let’s get some more information about object inheritance, there are 5 types of inheritance that I know, which is :

  • Single inheritance: Where the subclasses of an object will inherit the features of one superclass. A class acquires the properties of another class.
  • Multiple inheritance: Where one class can have more than one superclass and the object will inherit features from all parent classes.
  • Multilevel inheritance: The class A serves as a base class for the derived class B, which in turn serves as a base class for the derived class C. The class B is known as intermediate base class because it provides a link for the inheritance between A and C. The chain that we got from A, B and C is usually well known as an inheritance path
  • Hierarchical inheritance: Where one class of an object will serves as a superclass (base class) for more than one sub class.
  • Hybrid inheritance: A mix of two or more of the above types of inheritance.

Conclusions

  • General : Inheritance is all part of a person’s estate/assets that is given to an heirs once the person is deceased or dead.
  • Coding :  inheritance is when an object is based from a prototype of another object, using the same implementation (inheriting from object or class) specifying implementation of the object to maintain the behavior to be similar.