Introduction Data Structures and Algorithm

Tags

, , , ,

discrete-mathematical-algorithm-data-structures

discrete-mathematical-algorithm-data-structures

https://leanpub.com/discretemathematicalalgorithmanddatastructures

We have already been introduced to data structures before. Of course, we have learned a few operations using Array in various languages, so we can say that the concept of data structures is not completely alien to us.
We need a good way to store, organize and use our data. As times passes by, the nature of data is becoming not only more and more complex, but also it’s getting bigger in quantity. More and more people are getting hooked to the Internet, exchanging huge amount of data every day, in various forms; scientific data are getting larger, we need weather data to be processed to get more accurate weather prediction, medical data are becoming humongous; this list is endless.
Therefore, we need more efficient way to sort, organize, and use that data.
Data Structures are all about this. It has a very close relation with Algorithm, because managing such huge amount of data is less tedious if we have more efficient Algorithm, ready at our hand.While managing such huge humongous data, by sorting, organizing, or using them, one is not only prone to error, but also fail to satisfy one of the most important requirements – time and space. Yes, time complexity really matters, so the space.

Continue reading

Twisted Prime in Java

Tags

, , ,

JAVA CODING BOOTCAMP: LEARN LANGUAGE BASICS AND ALGORITHM

JAVA CODING BOOTCAMP: LEARN LANGUAGE BASICS AND ALGORITHM

Java Coding Bootcamp for Beginners

 

It is one of the most common problem we face in any IT job interview related to software industry or any programming language. Can you write a program that will determine whether a number is twisted prime or not? Let us try it in Java. You can apply the same algorithm in other language like C, C++, PHP, C#, Python or Dart. First of all let us know what is twisted prime number. It is a prime number whose reverse is also a prime number, such as, 11, 71, 13, etc. Therefore, when the reversed prime number is also prime, we call it twisted prime. Example is 97. The reverse of 97 is 79, which is also prime.

Continue reading

PHP 7: How API, Connector, driver and extension work together

Tags

, , , , , , , , , ,

https://leanpub.com/u/sanjibsinha

An Application Programming Interface or API, classifies the classes, methods, functions and variables that one application will need to call in order to tasks. APIs can be procedural or object oriented. The procedural API helps you to call functions to carry out tasks. And the object-oriented API creates class instantiation and then calls methods on resulting objects. The object-oriented API is much preferable as they lead to better organized code.
The connector is a piece of software that allows your applications to connect to the MySQL database server. MySQL provides connectors for variety of languages including PHP. In a dynamic database driven web applications, you need to write php code to perform a few tasks including connecting to the database server, querying the database and other database related functions. The Connector is a kind of software that allows your application to connect to a database server.
Continue reading

Java: Why we need Interface in Java

Tags

, , ,

https://leanpub.com/u/sanjibsinha

A class can be extended and at the same time, it may implement multiple interfaces. The next problem is a showcase for the same example.

package fun.sanjibsinha;
/*
class cannot extend multiple classes
so we cannot write like this: public class CatyClass extends MobileClass, MobileFeatures
 */
public class CatyClass extends MobileClass implements MobileUpgradable {

    private double batteryStrength = 0.0;
    private int pixel = 10;
    private double mins = 60.0;
    private int days = 0;
    public double version = 1.0;

    public double getVersion() {
        return version;
    }

    public void setVersion(double version) {
        this.version = version;
    }

    public double getBatteryStrength() {
        return batteryStrength;
    }
    public void setBatteryStrength(double batteryStrength) {
        this.batteryStrength = batteryStrength;
    }

    public double getMins() {
        return mins;
    }
    public void setMins(double mins) {
        this.mins = mins;
    }

    public double takeCharge(double mins){
        this.mins = mins;
        return mins;
    }
    public double batteryCanLast(int days){
        this.days = days;
        return days;
    }

    public CatyClass(){}
    public CatyClass(String name, String color, double price, double mins){
        super(name, color, price);
        this.mins = mins;
    }

}

After the class declaration, we need an interface.

Continue reading

Data Structures in Java

Tags

, ,

https://leanpub.com/u/sanjibsinha

 

How we could manage a collection of data in Java? There are many options, different type of data structures.

You have already seen array. However, array has many limitations, such as it holds fixed number of values of a single type. You cannot change it.
To overcome such limitations, Java introduces core collection interfaces. They encapsulate different type of collections. You have learned the role of an interface, it is actually a contract. So it allows collections to be manipulated independently. The foundation of Java Collections Framework consists of such Core Collection Interfaces.
They are ‘Set’, ‘List’, ‘Queue’, ‘Deque’, and ‘Map’.
In the last problem, we have seen an example of ‘LinkedList’ class, which is a collection based on a Linked List. As the name suggests, it is a collection of container that holds data and each container has a link identifier that links it either to the next one or the previous one. The last link identifier is always ‘null’, because it points to nothing.

Continue reading

While or Do-While? It depends on your problem

Tags

, , , ,

https://leanpub.com/u/sanjibsinha

In some cases like the previous examples, the ‘while’ loop is indispensable. The user input validation is also done by using ‘while’ loop. We can do it by applying the ‘if-else’ logic. But, that should not be as robust as the code below:

package fun.sanjibsinha.understandingloops;
/**
* how to force the user to give valid input
*/

import java.util.Scanner;

public class WhileThree {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
System.out.println("Enter your age : between 0 and 150 ");
int age = sc.nextInt();
while (age < 0 || age > 150){
System.out.println("That is impossible; try again! ");
age = sc.nextInt();
}
System.out.println("Your are " + age + " years old.");
}
}

 

Continue reading

Introduction to MySQL and RDBMS

Tags

, , ,

https://leanpub.com/u/sanjibsinha

PHP 7 : Intensive Coding Bootcamp For One Month to Create a PHP Framework

PHP 7 : Intensive Coding Bootcamp For One Month to Create a PHP Framework

https://leanpub.com/php7intensivecodingbootcampforintermediatelearnerstocreateaphpframework Edgar F Codd had invented it. Later it became exceptionally popular. The relational database management system (RDBMS) is a database management system based on the relational model. Today most databases use it. MySQL is one of them. Along with PHP, we need to know about MySQL for one reason. MySQL is a central component of the LAMP open-source web application software stack. LAMP is an acronym for “Linux, Apache, MySQL and Perl/PHP/Python”. How important MySQL is? Well, it really needs no introduction. Many popular applications, such as WordPress, Drupal or Joomla use it. Many high scale websites including Google, Facebook, Twitter, Flickr and YouTube draw on it. Since 1980s it has been a common practice for storage of information in databases. Databases are used for different types of applications; from financial records to personal data – it’s much easier to implement and administer. RDBMS like MySQL maintains a clearer division between the database model and the application.

Continue reading

JAVA CODING BOOTCAMP: LEARN LANGUAGE BASICS AND ALGORITHM

https://leanpub.com/u/sanjibsinha

JAVA CODING BOOTCAMP: LEARN LANGUAGE BASICS AND ALGORITHM

JAVA CODING BOOTCAMP: LEARN LANGUAGE BASICS AND ALGORITHM

https://leanpub.com/u/sanjibsinha   This book will empower computer science and programming students to learn the language basics of Java; so that, they could build applications in Java. It is for the first time that a book with a “problems-solutions-explanations” approach using “Direct Method”; it is like an intensive coding bootcamp where participants will take active part to develop their logical and analytical thinking so that they could solve interactive problems. For that reason, we will get our head around the basics of Data Structures and Algorithm also. We are learning the language basics of Java together to solve many types of problems first. It will help us to build applications that are discussed in the next Java bootcamp series, where we will develop applications.

Continue reading

Java: Different usages of While loop that you must know

Tags

, , , ,

https://leanpub.com/u/sanjibsinha

There are different usages of While loop in Java. In some cases, we could calculate the average of definite number of integers. Suppose we enter five integers and get their average.

package fun.sanjibsinha.understandingloops;

import java.util.Scanner;

public class WhileOne {

public static void main(String[] args) {

final int listSize = 5;
double valueOfSum = 0;
int valueProcessed = 0;

System.out.println("Please enter " + listSize + " numbers.");
Scanner sc = new Scanner(System.in);
while (valueProcessed < listSize){
double yourNumber;
yourNumber = sc.nextDouble();
valueOfSum += yourNumber;
valueProcessed++;
}
double averageOfYourNumbers = valueOfSum / valueProcessed;
System.out.println("The average of given numbers " + averageOfYourNumbers);


}
}

Let us enter five numbers and check the average.

Continue reading

Story of Socrates: How objects contain other objects and communicate with each other in Java

Tags

, , , , ,

https://leanpub.com/u/sanjibsinha

 

In my previous post, I wrote about how objects contain other objects. Well, I also said that every programming language has its own way to do that. I gave you an example in PHP 7. This time, I am going to give you an example in Java.

I hope you have probably heard the story of Socrates, one of the greatest philosopher who was sentenced to death by the wise men of Athens. Socrates died drinking the poison Hemlock. The reason was quite amazing. Socrates questioned their wisdom and said famously while dying, “an unexamined life is not worth living”.

Socrates’ friend and student Plato, another great philosopher, wrote about his friends, in fact, in Plato’s many writings, Socrates appeared as one of the central character.

Here, we are going to develop a small console based application that tells us the life story Socrates.

There are four objects, Socrates, Plato, Wise men of Athens and the Hemlock.

Let us first define the Socrates class.

package fun.sanjibsinha.object;

class Socrates {
public String name = "Socrates";
WiseMen wise;
Hemlock hemlock;

public void questionWiseMen(WiseMen wise){
this.wise = wise;
System.out.println(this.name + " questioned the wisdom of " + wise.name);
}

public void sayToWiseMen(WiseMen wise){
this.wise = wise;
System.out.println(this.name + " said to the " + wise.name + " hearing" +
" his death sentence, 'an unexamined life is not worth living'.");
}

public void dieByDrinking(Hemlock hemlock){
this.hemlock = hemlock;
System.out.println(this.name + " died drinking " + hemlock.nature);
}
}

After that we need a Plato class, similarly, with some states and methods.

package fun.sanjibsinha.object;

class Plato {
public String name = "Plato";
Socrates socrates;

public void hasARelationWith(Socrates socrates){
this.socrates = socrates;
System.out.println(this.name + " had a friendship with " + socrates.name);
}
public void writesAbout(Socrates socrates){
this.socrates = socrates;
System.out.println(this.name + " had written about his friend and teacher "
+ socrates.name);
}
}

Next, we want the wise men of Athens, who decided Socrates’ fate, and gave him death sentence.

package fun.sanjibsinha.object;

class WiseMen {
public String name = "Wise men of Athens";
Socrates socrates;

public void giveDeathSentenceTo(Socrates socrates){
this.socrates = socrates;
System.out.println(this.name + " had given death sentence to "
+ socrates.name);
}
}

The Hemlock object is defined in a small class, where its state has been declared as poison.

package fun.sanjibsinha.object;

class Hemlock {
public String nature = "Poison";
}

Finally, we want to run the application by creating the objects, and based on the relationship they have, we build our algorithm.

package fun.sanjibsinha.object;

public class PhilosopherDemo {

public static void main(String[] args) {
Socrates socrates = new Socrates();
WiseMen wiseMenOfAthens = new WiseMen();
Plato plato = new Plato();
Hemlock hemlock = new Hemlock();
socrates.questionWiseMen(wiseMenOfAthens);
wiseMenOfAthens.giveDeathSentenceTo(socrates);
socrates.sayToWiseMen(wiseMenOfAthens);
socrates.dieByDrinking(hemlock);
plato.hasARelationWith(socrates);
plato.writesAbout(socrates);
}
}

While we run our application, here goes the output:

Socrates questioned the wisdom of Wise men of Athens
Wise men of Athens had given death sentence to Socrates
Socrates said to the Wise men of Athens hearing his death sentence, 'an unexamined life is not worth living'.
Socrates died drinking Poison
Plato had a friendship with Socrates
Plato had written about his friend and teacher Socrates

I hope, this example will help you to understand how objects contain other objects, and communicate with each other.