Programming – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Wed, 13 Mar 2024 18:12:19 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg Programming – Programmerbay https://programmerbay.com 32 32 Difference between While and Do While loop in Tabular Form https://programmerbay.com/difference-between-while-and-do-while-loop/ https://programmerbay.com/difference-between-while-and-do-while-loop/#respond Mon, 11 Mar 2024 16:17:31 +0000 https://programmerbay.com/?p=6343 In this article we’ll be discussing the difference between while and do while loop and how they work.

Control statements provide an ability to execute a particular set of statements in a controlled manner. Basically, these statements are powerful statements that can mange the flow of a program.

Every programming language supports a basic form of Iteration statements that are known as loops, for example, While, Do-While and For loop.

 

While and do while loop

Iteration statements are categorised as the control statements. It allows us to iterate through a piece of code repeatedly.

The goal of all looping statements is to run a particular block of statements frequently until a specific condition is met. However, Do-While and While loop follows a completely different approach to looping around a statement. Both types of loops are different from each other when it comes to their order of execution and condition evaluation.

What is a loop?

A loop can be defined as a control statement that enables repetitive execution of a block of code until a given condition turns out to be false. It provides capability to write a block of code and execute it repeatedly for specific number of times. Suppose, if a block of code needs to be executed repeatedly, in such case, we must use loops, instead of writing the same code multiple times.

Normally a looping statement comprises of following components:

  • Control or counter variable initialization
  • Condition evaluation
  • Loop body execution
  • Counter variable updation

There are primarily three types of loops  :
1) while loop
2) do while loop
3) for loop

The main difference between While and Do-While loop is that one evaluates condition first and then executes the loop body, whereas, other one executes the loop body first and then checks for the condition.

Difference between While and Do While Loop in Tabular form

BasisWhile LoopDo-While Loop
DefinitionIn this, the given condition is evaluated first, and then loop body is executedIn this, the given loop body is executed first and then after the given condition is checked
Loop TypeIt is an entry-controlled loopIt is an exit-controlled loop
Loop ExecutionThe loop body would be executed, only if the given condition is trueThe loop body would be executed at least once, even if the given condition is evaluated as false
Counter Variable Intialization It allows initialization of counter variable before entering loop bodyIt allows initialization of counter variable before and after entering loop body
SemicolonNo semicolon is used as a part of syntax,
while(condition)
Semi-colon is used as a part of syntax,

while(condition);
UsageIt is used when condition evaluation is required to be evaluated first, before executing loop bodyDo-While is used when one needs to enter into the loop body before evaluating condition. For example, Menu driven programs
SyntaxSyntax:

while( condition )
{
// loop body
}
do
{
// loop body
}while( condition );

While Loop

While Loop can be defined as the loop where the condition is evaluated first and then after the loop body is executed. It is an entry controlled loop.

Syntax:

while(condition)
{
// body
}

How while loop works?

  • Counter or control variable initialization
  • Then, condition would be checked
  • If it is evaluated as true, then
  • loop body would be executed
  • Otherwise, the loop gets terminated

Entry Controlled Loop

A Program example for While loop:

Example 1. C program to demonstrate working of while loop

Program

#include <stdio.h>

int main ()
{

  int i = 1;
  while (i < 5)
    {
      printf ("Print :: %d \n", i);
      i++;
    }
  return 0;
}

Output:

Print :: 1 
Print :: 2 
Print :: 3 
Print :: 4 

Explanation:

In the above example, we are simply initializing counter variable i with 1. And iterating using while loop until the condition  having i is less than 5 becomes false. In loop body, we are printing a message and incrementing counter variable on very next line.

Example 2. C program to show the approach difference of while loop with do-while

#include<stdio.h>
void main()
{
int i=10;
while(i<10)
{
printf("I will not be executed as it is entry controlled loop");
i++;
}
getch();
}

Explanation:

Since, condition would be evaluated as false at very first place , no output would be printed. In this, counter variable ‘i’ was holding value 10. And at the entry point of while loop, when condition got evaluated for ‘i< 10’, it turned out to be false. As a result, the loop terminated.

Do-While Loop

Completely opposite to While loop, Do-While is a looping statement in which condition is checked after the execution of the loop body. It is a type of exit controlled loop.

Syntax:

do
{
// loop body

}whie(condition);

How do-While works?

  • Counter or control variable initialization
  • Loop body gets executed first and then-after the condition is evaluated
  • If the condition is evaluated as true, then loop would proceed to next iteration
  • Otherwise, it gets terminated

Exit Controlled Loop

A  Program example of Do-While loop

Example 1. C program to demonstrate working of do while loop

Program:

#include <stdio.h>

int main ()
{
  int i = 1;
  do
    {
      printf ("Print :: %d \n", i);
      i++;
    }while (i < 5);
  return 0;
}

Output:

Print :: 1 
Print :: 2 
Print :: 3 
Print :: 4 

Explanation:

In the above example, we are initializing counter variable i with 1. And iterating using do while loop until i is less than 5. In loop body, we are printing a message and incrementing counter variable on very next line. Lastly, we’re checking the condition and iterate accordingly.

Example 2. C program to show the approach difference of do-while loop with while

#include<stdio.h>
void main()
{
  int i=10;
  do
  {
  printf("I will be executed at once as it is exit controlled loop");
  i++;
  }while(i<10);
  getch();
}

Explanation:

Print statement would be executed at once, even though the condition is false. In this, counter variable ‘i’ was 10. In this, the loop body got executed first which resulted in print statement execution. And lastly, condition got evaluated for ‘i< 10’, it turned out to be false. As a result, the loop terminated.

Exit Controlled and Entry Controlled Loop

A loop that executes the loop body first and then checks for a condition is known as an exit controlled loop. For example Do-While loop.

On the other hand, a loop that checks for condition first and run the loop body can be categorized as entry controlled loop. For example, While loop, and For loop.

]]>
https://programmerbay.com/difference-between-while-and-do-while-loop/feed/ 0
30 Best Programming or Coding Memes That Will Make You Laugh https://programmerbay.com/best-programming-or-coding-memes-that-will-make-you-laugh/ https://programmerbay.com/best-programming-or-coding-memes-that-will-make-you-laugh/#respond Wed, 24 Mar 2021 08:12:07 +0000 https://programmerbay.com/?p=6371 We all usually spend most of the time fixing bugs and other code-related stuff. However, programming memes are one of the sources that provide us relief from stress and make us laugh.

The listed below programming or coding memes are extremely funny and would definitely let you forget your stress while reading them.

  • When a part of the project is done by new trainee developer

  • Who is the Messiah

 

  • React.js or Angular.js?

  • What gives people feeling of power?

  • Too much coffee

  • Experience Vs My coding

  • Compiler and Logical Error hide & seek

  • Exception.Coding.Me

  • When you write an optimised code but no one understands it enough to appreciate it

  • Tehc

  • Interviewer’s expectations

  • Programmers with their girlfriends

  • This is how you look like when you test your own code

W

  • When someone else tests your code Vs no bug is found

  • Successful code execution

  • Overthinking

  • Me and My friends when we all work together on a single module together

  • Compiler and Me

  • What Google thinks about us

  • How I and my friend react after fixing bugs in each other’s code

  • Can you count to 10 ?

 

 

  • When you’re backend developer and your tech lead asks you to develop user interface by EOD

  • Stop Using ‘i’ in for loop

  • The Google developer who deployed the code to the production

  • My Bois, After buying project online for Final Submission

  • Average full stack developer Vs Average Front-End developer

  • Unreachable Object Vs Garbage Collector

  • Everyone After code crash at Production Server, Me who merely did one one of change before deployment

  • After Solving a bug

  • Me trying to develop a feature without going through requirement document

Comment below your favourite programming or coding memes.

]]>
https://programmerbay.com/best-programming-or-coding-memes-that-will-make-you-laugh/feed/ 0
Difference between submit() and execute() method in Java with Tabular form https://programmerbay.com/difference-between-execute-and-submit-in-java/ https://programmerbay.com/difference-between-execute-and-submit-in-java/#respond Tue, 01 Dec 2020 06:08:27 +0000 https://programmerbay.com/?p=6193 Both execute() and submit() methods are used to send a set of tasks to the Executor interface having a thread pool.

The Hierarchy goes like this, Java gives us an ExecutorService interface (having submit() method ) which is a sub-interface of Executor (interface), consisting of a method called execute() defined in it.

Difference between submit() and execute() method in Tabular form

BasisSubmit MethodExecute Method
FunctionalityIt submits tasks to the Executor that would handle them for usRuns the task with the main thread
Return It returns a future object which can be used to interrupt the thread in futureIt just starts the task and returns void
DeclarationIt is declared in the ExecutorService interfaceIt is declared in the Executor interface
AcceptanceIt accepts both Runnable and Callable as a parameterIt expects a Runnable as a parameter
Exception HandlerIf submit throws an exception it becomes an integral part of the return value of the taskIf Execute throws an exception it will go to the uncaught exception handler
Use CaseBeneficial when thread being called requires output from the task it is executingExecute is used most of the time when we just want to submit the task in the thread pool and don’t want to alter it further

execute() Method

• execute() runs the task with the main thread.

//execute() Action
ExecutorService executor = Executors.newFixedThreadPool(2);
for (int i = 0; i < 5; i++) {
executor.execute(someTask(i));
}

Java code example to demonstrate the working of execute() method

import java.util.concurrent.*;
class task implements Callable<Integer>{
@Override
public Integer call() throws Exception {
System. out .println("Returning Integer using Callable Interface ");
return 10;
}
}
public class CollableExample {
public static void main(String[] args) throws ExecutionException,
InterruptedException {
ExecutorService pool = Executors.newFixedThreadPool(1);
task obj = new task();
System. out .println("Task submitted ");
Future<Integer> future = pool.submit(obj);
Integer result = future.get();
System. out .print("Printing using user : ");
System. out .println(result);
}
}

Example: A simple code that would simply output the returned future object.

submit() Method

• submit() is used to submit tasks to the Executor that would handle them for us.

//submit in action
ExecutorService executor = Executors.newFixedThreadPool(2);
for (int i = 0; i < 5; i++) {
executor.submit(someTask(i));
}

Seeing the above example one can say that both of these provide similar outputs but there are some subtle differences in both of their behaviors.

Advantages of using submit() method:

• submit() method returns a future object which can be used to interrupt the thread in future.
• The returned future object can be used for 2 major things:
◦ Canceling the task with cancel().
◦ Wait for the task for completion using get().

Java code example to demonstrate the working of submit() method

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
class Even implements Runnable {
@Override
public void run() {
for(int i=1;i<=10;i++){
if(i%2==0){
System. out .println(Thread.currentThread().getName()+"
Even "+i+",");
}
}
}
}
class Odd implements Runnable{
@Override
public void run() {
for(int i=1;i<=10;i++){
if(i%2!=0){
System. out .println(Thread.currentThread().getName()+"
Odd "+i+",");
}
}
}
}
class ThreadPoolCreater{
public static void main(String[] args) {
ExecutorService executorService= Executors.newFixedThreadPool(2);
executorService.submit(new Even());
executorService.submit(new Odd());
executorService.shutdown();
}
}

Explanation: The above program would create a Thread pool where one Thread would print even numbers and others will print odd numbers

Implementation Comparision between submit() and execute() Methods :

• The submit() method is declared in the ExecutorService interface while the execute() method is declared in the Executor interface.
• execute() expects a Runnable as a parameter.
• submit() can accept both Runnable and Callable as a parameter.
• If execute() throws an exception it will go to the uncaught exception handler.
• If submit() throws an exception it becomes an integral part of the return value of the task.
• submit() method is just a wrapper around the execute().

/ / implementation of submit() in java docs.
public Future<?> submit(Runnable task) {
    if (task == null) throw new NullPointerException();
    RunnableFuture<Void> ftask = newTaskFor(task, null);
    execute(ftask);
    return ftask;
}

Key Differences:

• execute() method just starts the task and returns void.
• submit() method returns a Future object which can be further used for manipulating the task in later stages of our business logic.

Real World Use Case

execute() method :

• execute() is used most of the time when we just want to submit the task in the thread pool and don’t want to alter it further.
• A Real-world use case could be sending a do-not-reply email where you do not expect a response from the user.

submit() method :

• Beneficial when thread being called requires output from the task it is executing.
• A real-world use case could be order confirmation after validating the response received from the payment gateway.

This article is contributed by Shiva Tiwari.

]]>
https://programmerbay.com/difference-between-execute-and-submit-in-java/feed/ 0
ForEach in Java 8 with Example https://programmerbay.com/foreach-method-in-java-8/ https://programmerbay.com/foreach-method-in-java-8/#respond Wed, 17 Jun 2020 10:57:02 +0000 https://programmerbay.com/?p=6435 In Java 8, forEach is introduced that provides an efficient way to iterate through collections ( List, Sets, and more) and Streams.

In Collection hierarchy, the iterable interface is the root interface in which a new feature has added namely forEach(). It allows iterating a collection of elements until the last element is processed.

It accepts consumer (functional interface) as an argument, meaning one needs to define a lambda expression that would take a single input and return nothing.

default void forEach(Consumer<? super T> action)

Functionality wise, forEach and enhanced for-loop are similar, but the new forEach is a type of internal loop. Meaning, the iterator handles iteration behind the scene, as a result, programmers don’t have to worry about the iteration behaviour.

Code Example:

Iterating over List:

import java.util.List;

public class ForEachExample {
public static void main(String[] args) {
List nameList = new ArrayList();
nameList.add("Programmer");
nameList.add("ProgrammerBay");
nameList.add("coders");

nameList.forEach(singleItem -> System.out.println(singleItem));
}
}

Output

Programmer
ProgrammerBay
coders

Iterating over Map:

import java.util.*;

public class ForEachExample {
public static void main(String[] args) {
Map nameList = new LinkedHashMap();
nameList.put(1,"Programmer");
nameList.put(2,"ProgrammerBay");
nameList.put(4,"coders");

nameList.forEach((key,value) -> System.out.println("This is my key : "+key +" and value : "+value));
}
}

 

Output:

This is my key : 1 and value : Programmer
This is my key : 2 and value : ProgrammerBay
This is my key : 4 and value : coders

Iterating over Stream of elements :

public class CreateStreams {
    public static void main(String[] args) {
        String[] stringArr = new String[]{"This", "is", "Example", "of", "Stream"};
        // Creating Stream of Array
        Stream<String> arrayStream = Stream.of(stringArr);
        arrayStream.forEach(singleString -> System.out.print(singleString + " "));
    }
}

Output:

This is Example of Stream

Point to remember about forEach:

  • Java 8, forEach is an internal loop
  • It makes code clean and more readable
  • It is less error-prone
  • It is a default method

]]>
https://programmerbay.com/foreach-method-in-java-8/feed/ 0
Static methods & Default Methods in Java 8 https://programmerbay.com/static-methods-default-methods-in-java-8/ https://programmerbay.com/static-methods-default-methods-in-java-8/#respond Sun, 14 Jun 2020 15:50:12 +0000 https://programmerbay.com/?p=6433 An interface describes what a class should look like but not describe how, closely related to class but can’t be instantiated. Before Java 8. Java interface can have abstract method (without method definition) only, but Java 8 onwards, two new features were introduced namely Default method and Static method within interface.

Default Method

-A default method allows to add a new methods in existing interface without affecting the implementing classes.

-It uses default modifier

– It must have a complete method definition. Basically, a dummy body.
– It is not compulsory for implementing class to override a default method but one can.

Reason to introduce it

Prior to Java 8, a class that implements an interface mandatorily had to provide implementation to abstract methods of that particular interface.

However, it was not a big deal, but Java developers noticed that if there is an existing interface which has implemented by quite a large number of classes and there a need arises of adding another method. Then it would need to be overridden by other classes. This would break the code if any of the class omit to implement it.

Therefore, default method came in to picture, now one can add any new feature to existing interface without affecting behaviour of other implementing classes.

Problem:

Before adding new Feature:

No error

After adding new Feature:

error 3

 

Solution

For example:

interface MyInterface {
    default void display() {
        System.out.println("This is dummy definition");
    }
}

public class DefaualtMethodExample implements MyInterface {

    public static void main(String[] args) {
        DefaualtMethodExample obj = new DefaualtMethodExample();
        obj.display();
    }
}

Output:

This is dummy definition

Static method

– Java 8 also supports static method within an interface.

-Method body should be provided to the static method at the time of its declaration.

-It can’t be overridden in implementing classes

-It uses static modifier

– By default, static methods cannot be available in implementing classes. Therefore one need to call it by InterfaceName.methodName()

 

For example:

interface MyInterface {
    static void display() {
        System.out.println("This is static definition");
    }
}

public class DefaualtMethodExample implements MyInterface {

    public static void main(String[] args) {
        MyInterface.display();
    }
}

Output:

This is static definition

 

]]>
https://programmerbay.com/static-methods-default-methods-in-java-8/feed/ 0
Predefined Functional Interface in Java 8 https://programmerbay.com/predefined-functional-interface-in-java-8/ https://programmerbay.com/predefined-functional-interface-in-java-8/#respond Sun, 14 Jun 2020 15:48:47 +0000 https://programmerbay.com/?p=6431 Java provides a bunch of predefined functional interfaces that come under java.util.function package. Each and every predefined functional interface has its own characteristics. Some of the major ones are : predicate, consumer, supplier and function.

Predicate

– It accepts a single input and always returns a boolean value as an output
– In other words, it is used for conditional checks
– It supports a single abstract method named test()
– it always return a boolean type

For example:

import java.util.function.Predicate;

public class InBuiltFunctionalInterfaceExamples {

    public static void main(String[] args) {
        Predicate<Integer> ageTester = (x) -> x>18;
        if(ageTester.test(15))
        {
            System.out.println("You can vote");
        }
        else
        {

            System.out.println("You are too young");
        }
    }
}

Output:

You are too young

 

Function

– It is used for performing logic on given input.
– It takes two arguments first is to represent input and second is for output.
– It supports a single abstract method named apply()
– Its return type can be varied

For example:

import java.util.function.Function;

public class InBuiltFunctionalInterfaceExamples {

    public static void main(String[] args) {
        Function<Integer,Integer> calculator = (x) -> 4*4;
        System.out.println("Square : "+calculator.apply(4));
    }
}

Output:

Square: 16

Function chaining: Combining two or more functions to form more complex function is known as function chaining.

 

Consumer

– It accepts a single input argument but returns nothing
– It supports a single abstract method named accept()
– It doesn’t have any return type

For example:

import java.util.function.Consumer;

public class InBuiltFunctionalInterfaceExamples {

    public static void main(String[] args) {
        Consumer<Integer> display = (x) -> System.out.println("I am displaying "+ x);
       display.accept(10);
    }
}

Output:

I am displaying 10

 

Supplier

– It accepts no argument but returns a value
– It must return something
– It supports a single abstract method named get()

For example:

import java.util.Date;
import java.util.function.Supplier;

public class InBuiltFunctionalInterfaceExamples {

    public static void main(String[] args) {
        Supplier<Date> date = () -> new Date();
        System.out.println("Date : "+date.get());

    }
}

Output:

Date : Mon Jun 15 16:31:22 IST 2020

Other functional Interfaces

There are more predefined functional interfaces:-

  • Interfaces that accepts two arguments:
    -BiFunction
    -BiPredicate
    -BiConsumer
  •  Interfaces that accept a specific datatype:
    DoubleSupplier
    DoubleConsumer
    IntPredicate
    IntSupplier
    and more
  • Other intefaces are BinaryOperator, UnaryOperator

]]>
https://programmerbay.com/predefined-functional-interface-in-java-8/feed/ 0
What is Functional Interface in Java 8 https://programmerbay.com/functional-interface-in-java-8/ https://programmerbay.com/functional-interface-in-java-8/#respond Sun, 14 Jun 2020 15:48:03 +0000 https://programmerbay.com/?p=6430 Programming languages such as Python, Scala that support functional programming , require few lines to complete a particular functionality, therefore, they are concise, on the flip side, Java can do the same thing but requires more lines of code.

In other words,one of the drawback of Java was that even a single functionality one require to create a method and that method is intended to be invoked by a class object. That certainly increases the length of the code.

To compete with other languages, Java developers decided to have functional programming as a new feature in Java.

To achieve this, Functional interface, Lambda Expressions (other alternatives such as Method reference and constructor references ) and many other features were introduced.

Functional Interface

A functional interface can be defined as an interface that consists exactly a single abstract method. However, it can have any number of static or default methods.

In order to use or implement Lambda expression, it is compulsory to use functional interface. A functional Interface is responsible for invoking Lambda expressions.

We cannot write Lambda expression without providing functional interface.

Functional Interface Annotation

@FunctionalInterface annotation is used to explicitly tell the compiler that a particular interface is intended to be a functional interface. A compiler triggers an error when a particular interface doesn’t satisfy the criteria of having a functional interface.

Runnable,Collable, Comparable are some examples of Functional interface.

A functional interface uses lambda expressions, method references or constructor references as one of the ways of its instance creation.

@FunctionalInterface
interface MyFunctionInterface{
        boolean compareMe(int a,int b);
        }



public class FunctionInterfaceExample {
    public static void main(String[] args) {
        int num=9,num1=8;
        MyFunctionInterface i = (a,b) ->  a>b;
       if(i.compareMe(num,num1))
           System.out.println(num+" is greater than "+num1);
       else
        System.out.println(num+" is smaller than "+num1);
    }
}

Output:

ouput

]]>
https://programmerbay.com/functional-interface-in-java-8/feed/ 0
Lambda expression in Java 8 https://programmerbay.com/lambda-expression-in-java-8/ https://programmerbay.com/lambda-expression-in-java-8/#respond Sun, 14 Jun 2020 15:47:03 +0000 https://programmerbay.com/?p=6429 Lambda expression is one of the core feature introduced in Java 8 as it provides a way to achieve functional programming in an object oriented programming language. It is anonymous function without having modifiers and return type. In other words, it simply provides a definition to a single abstract method defined within an interface called as Functional interface.

Point to remember:

– It provides a way to achieve functional programming in Java

-A Lambda expression is anonymous function having no modifiers and return type.

– It uses functional interfaces as its base to implement functional programming in Java. Without functional interface it cannot be implemented.

-It uses arrow operator or lambda operator to tell the compiler it is a Lambda expression

Syntax:

lambda expressions

These are following features of a lambda expression:

another lambda
No return type: Unlike function, in lambda expression, we don’t provide the return type. We simply write () -> {}

No Modifiers: Another important aspect of Lambda expression is, no modifier is required to mention.

The above two aspects indirectly depends on abstract method of a functional interface. Lambda Expression indirectly references to that type.

Optional Argument type : It is not mandatory to provide datatype to the parameter, but if one does then parenthesis would be mandatory

Optional Parenthesis : if there is a single argument then putting parenthesis would be optional
Optional curly braces and return type : if there is a single statement in the expression body then there is no need to put curly braces and return statement(if have).

 

 

Before Lambda Expression:

create a function:

void cube(int x) {
System.out.println("cube :"+ x*x*x);

}

create an object to call that function:

Test obj = new Test();

Invoke it

obj.cube(3);

 

After Lambda Expression:

Import Function (A predefined functional interface)

import java.util.function.Function;

Create a Lambda expression:

Function<Integer,Integer> cube = x -> x*x*x;

call its apply abstract method

System.out.println("This is the cube of "+ x + ":"+ cube.apply(x));

]]>
https://programmerbay.com/lambda-expression-in-java-8/feed/ 0
Difference between Cohesion and Coupling https://programmerbay.com/difference-between-cohesion-and-coupling/ https://programmerbay.com/difference-between-cohesion-and-coupling/#respond Sun, 03 May 2020 09:58:19 +0000 https://programmerbay.com/?p=6243 Coupling and cohesion are methods to measure the relationship between and within modules.

cohesion vs coupling

A software system is divided into multiple modules, where each and every module are capable of performing a function independently. This technique is known as Modularization.

Further, Coupling and Cohesion indicate to which degree a module can carry out a task on its own and the strength of elements related to one other within that respective module.

Coupling measures interaction between modules whereas Cohesion focuses on interaction within a module.

Difference between Coupling and Cohesion in Tabular form

CouplingCohesion
It refers to relationship between two or more modulesIt refers to relationship between two or more elements within a module
It focuses on measuring a module's dependency with other modulesIt focuses on measuring a module's functional strength
It is ideal to have low coupled modules which states dependency between modulesIt is ideal to have a module with high cohesiveness which states implementation of a particular feature with low or no communication with other module
It is based on communication between two modules. Therefore, it is known as inter-module conceptIt is based on communication between two elements or fields within a single module. Therefore, it is known as intra-module concept
There are 6 types of coupling: Data Coupling,Stamp Coupling,Control Coupling,External Coupling,Common Coupling and Content CouplingThere are 8 types of cohesion: Functional Cohesion,Sequential Cohesion,Communicational Cohesion,Procedural Cohesion,Temporal Cohesion,Logical Cohesion and Coincidental Cohesion
It is not possible to achieve no coupling among all modulesIt is possible to achieve full cohesive modules

Coupling

The measure of how a module depends on other modules is known as coupling.

It can be viewed as highly coupled, loosely coupled and uncoupled. These are based on their degree of dependencies.

Uncoupled signifies no dependencies at all, all the modules or methods have nothing to do with other modules. No communication between this type of coupling takes place.

Highly coupled refers to the high dependency of the module with each other.

Loosely coupled represents less dependency which means that only essential piece of code would depend and communicate with each other. It means undesired data would not be passed to another section of code.

In programming, the ideal way of having a program to be loosely coupled is by using the concept of interfaces.

Coupling can be classified based on certain characteristics:

Coupling

Cohesion

It represents how a module’s attributes or fields are functionally related together. A module that is highly cohesive, has little or no interaction with other modules.

Therefore, it is better to have maximised cohesive modules where elements within a module interact properly to one another.

A module with high cohesion represents that it is strongly capable of performing a particular functionality or task, considering less or no communication with other modules.

Cohesion can be classified based on certain characteristics:

cohesion

A Good Relationship between Cohesion and Coupling

relation

A software with less coupled and high cohesive module design should always be preferred. A software design breaks down into multiple modules where each module solves a particular problem.

These modules are structured in a proper hierarchy. Each and every module must be implemented in a way that they are having less dependency with other modules and the elements within that module should be functionally related together.

]]>
https://programmerbay.com/difference-between-cohesion-and-coupling/feed/ 0
Best Sites that would help you to improve your coding skills https://programmerbay.com/best-sites-that-would-help-you-to-improve-your-coding-skills/ https://programmerbay.com/best-sites-that-would-help-you-to-improve-your-coding-skills/#respond Sun, 18 Aug 2019 08:43:04 +0000 https://www.programmerbay.com/?p=4725 Everyone wants to be known for their ridiculously best coding skills, right? And we are all aware of how difficult it is, as it requires a great effort whether it’s about formulating a logic to solve a problem or implementing it into code. So, to solve a problem one must have good logic building capability.

And to create logics much faster, you need practice and for that you need more problems. And there are many sites which offer you exactly this in form of study materials for brushing up your coding skills.

The resources that would help you to improve your coding skills and perform better in coding interviews can be seen as two groups.

First is the study material group. In this, you would interact with the sites where you can get material to study, basically for theoretical knowledge. These involve online courses. Some are free and some are paid. These sources are for learning the programming skills and getting aware of all the technologies that you like.

Some of these resources to study are –

1. EDX (free)

It is a platform founded by Harvard and MIT which offers a wide range of courses. You can find various free online courses on a decent range of topics published by Harvard and MIT. You can also attain a verified certificate from these universities but that is paid.

2. GeeksForGeeks (free)

This is a computer science portal where you find articles and study material on almost all the computer science topic. It provides free resources.

3. Udemy(paid – low price)

It is an online learning platform where you get tons of online courses, almost for all topics and technologies you can think of. Udemy offers reasonable price courses and certificates that you can use in your resumes to showcase.

4. Coursera (paid – fairly priced)

This is also one such online learning platform where you get online courses from various universities all around the world.

The second group is the practice resources. In this, you would get the resources where you need to practice the topics and skills that you have learned from the first category resources. For developing skills that are required to get jobs, you need to practice the questions of interview level, participate in contests and practice questions to increase your logics.

So of the resources to practice are:

1. Hacker Rank

It is an online coding challenge platform where you can participate in various challenges and also you may find a lot of questions on various topics to practice. It focuses on developing coding skills through competitive programming. You can practice question-related to most of the popular programming languages.

2. Hacker Earth

It is also a coding challenge platform where you can practice and participate in various challenges to develop your coding skills. On Hacker Earth many companies post there challenges and contests. If you are able to crack these problems then you may get rewarded with various prizes and job offers, also.

3. Codechef

It is a nonprofit initiative from Ditecti which is a product based company. It is an online platform for competitive programming. You can develop your coding and problem solving skills through participating in contests held on codechef.

4. Codeforces

This is also a competitive programming platform which is best for short time challenges. You can develop skills for coding interviews through participating in short challenges.

]]>
https://programmerbay.com/best-sites-that-would-help-you-to-improve-your-coding-skills/feed/ 0