25 September, 2014

Learning Scala- Hello World!

If you are using Ubuntu, Install Scala by running the following command on terminal:

sudo apt-get install scala

This would install Scala on your machine.

install Scala

Create a project directory lets say : MyProject and go to it

mkdir MyProject
cd MyProject/

Using terminal run the following lines of code

mkdir -p src/main/scala
This would make a project directory structure for Scala project that we are going to create

echo 'object Hi { def main(args: Array[String]) = println("Hi!") }' > src/main/scala/hw.scala

Here we are creating a file named hw.scala, inside src/main/scala direcctory which we created in previous step. and wrote the line
object Hi { def main(args: Array[String]) = println("Hi!") }
in it. Let's format it and understand
object Hi {
def main(args: Array[String]) = println("Hi!")
Here, we are defining an object Hi, with a main function inside.
This function simply prints a Hi! on the screen.

Lets compile our code now:
scalac src/main/scala/hw.scala
This would compile our scala code to byte code.
Test the code by running it
scala Hi

scala Hello World Test
It should print "Hi!" on console.

You just created a basic program in Scala.

18 September, 2014

Calculating Largest known Russian Prime number

Prime Number is a number which is not perfectly divisible by more than 2 numbers. (And those two numbers which would divide a prime number are 1 and the number itself.)

A Russian Doll is a set of wooden dolls of decreasing size placed one inside the other.

A Russian Doll Prime Number is a prime number whose right digit can be repeatedly removed, and it still is prime.

Why are interfaces used?

1) In programming languages, Interfaces are like a contract which states what methods would be available by Implementing Classes. This is really helpful, when we are concerned about specific functionality only.

2) Child classes implementing an interface follow IS-A relationship with that interface.

17 September, 2014

Security and Hacking

Security today is an unsaid requirement (which is assumed implemented) by customers, but if neglected can cause huge losses including monitory and reputation. Most of the applications deal with at least one of the following
  • Financial Information
  • Credit Cards
  • Account Numbers
  • Customer's Personal Information
  • Name
  • Contact information
  • Special information

Security Principles

Security in software industry is an unsaid requirement these days. Clients are looking for a software which works fine, but is secure enough to prevent data breach. 
In this blog we will discuss some of the security principles that should be adapted while developing software that would minimize probability of our applications being hacked
  1. Defence in depth
  2. Positive security Model
  3. Fail Securely
  4. Principle of Least Privilege
  5. Avoid security by obscurity

Traversing multi dimensional array in Java

An array in Java is a type of container which contains a specified number of indexed elements, which can be thought of a single line segment. e.g. an array of int would be represented as
int[] integerArray;
 A multidimensional array is one, in which we can traverse through them to more than one way. for instance we can think of a 2-D array like a graph plot (x and y axis) similarly, a 3-D array would be like a 3-D Graph (x-y-z axis)

A 2-D array could be represented in Java as
int[][] twoDArray

In Java a 2-D array is an array of arrays. Because of this implementation, the performance of a program would vary, depending upon the way we are traversing through the array.

How to create an Immutable Class in Java?

Immutable means: something which cannot be modified once created. In Java, an immutable class is one, whose objects retain their initial state through out their life-cycle. Objects whose properties/ values cannot be changed after they have been created are immutable objects e.g. java.lang.String

To achieve a design of such a class we need to understand what are the ways in which an object can be modified.

  1. All state variables must be private and final
  2. Remove setters.
  3. Prevent leaking of reference variables by using clone.
  4. Make the class final