Thursday, February 4, 2016

Knowing the Structure of Android App in terms of Software Engineering

Most of us want to know what is the best way of creating high quality apps in android or any other platform. But we tend to forget the basics of how to start creating apps that can become popular.


There are some things that you need to remember in order to create some good quality apps.

1) Analysis: Determine what information you have regarding the app idea that you wish to create. Try to enhance it by regularly collecting the info about your idea. This is where you would be thinking "Why to waste such time in collecting the info? It can be done while creating the app." Yes, it can be done, but at the time of developing the app, you won't be able to create the app in less time. Instead it will increase your developing time. Which is where you will sit ideally and think about collecting the info. So its better to try collecting Information ASAP.

2) Design: After that you have collected almost every bit of info about the idea that you want to create, try to design that idea into some animated graphics and awesome good looking images. Surely it will be good to look at. But remember that designing is next important part in developing any app. You need to start from logo and end up on to the last image or animation that will create some good motions in your app.

3) Developing: This is the third most important part of any app and this is where you want to showcase your coding skills. So start with all round performance by creating some good quality code and make sure that people who see your code also understand it better than you. There is a saying from Martin Fowler "Any fool can write code that a computer can understand. Good programmers write code that humans can understand." Try picking up some coding language and learn the basics of it. Remember it and then implement it in your app.

4) Testing: This is the last stage in creating any app, but not that this cycle has stopped after this. You have a lot to do after this step, if you've reached this far. Testing is not to be done here but, testing is the step which is accomplished throughout your apps creation. Testing is applied in all the above mentioned stages. In this stage(After Development Stage) you have to test your app in every aspect that comes to your mind. Test your app in almost every possible way, whether its cross platform or not, any devices like your own mobile or tablet or if it's a web app than test it in every different web browser. This is where your app is finalized to be distributed in the market and it will lend you some profit.

Well, this is it for this post where i have put some theory talk that may help you to understand the structure of any software that you want to build. After all, an android app is a software for mobiles.

Monday, September 14, 2015

Java program print prime numbers


This java program prints prime numbers, number of prime numbers required is asked from the user. Remember that smallest prime number is 2.

Java programming code


import java.util.*;
 
class PrimeNumbers
{
 public static void main(String args[])
 {
 int n, status = 1, num = 3;
 
 Scanner in = new Scanner(System.in);
 System.out.println("Enter the number of prime numbers you want");
 n = in.nextInt();
 
 if (n >= 1)
 {
 System.out.println("First "+n+" prime numbers are :-");
 System.out.println(2);
 }
 
 for ( int count = 2 ; count <=n ; )
 {
 for ( int j = 2 ; j <= Math.sqrt(num) ; j++ )
 {
 if ( num%j == 0 )
 {
 status = 0;
 break;
 }
 }
 if ( status != 0 )
 {
 System.out.println(num);
 count++;
 }
 status = 1;
 num++;
 } 
 }
}

Output of program:


We have used sqrt method of Math package which find square root of a number. To check if an integer(say n) is prime you can check if it is divisible by any integer from 2 to (n-1) or check from 2 to sqrt(n), first one is less efficient and will take more time.

Thursday, September 10, 2015

Java program to find factorial

This java program finds factorial of a number. Entered number is checked first if its negative then an error message is printed.

Java programming code

import java.util.Scanner;
class Factorial { 
public static void main(String args[]) { 
int n, c, fact = 1;   
System.out.println("Enter an integer to calculate it's factorial"); 
Scanner in = new Scanner(System.in);   
n = in.nextInt();   
if ( n < 0 ) 
System.out.println("Number should be non-negative."); 
else { for ( c = 1 ; c <= n ; c++ ) 
fact = fact*c;   
System.out.println("Factorial of "+n+" is = "+fact); 
} 
} 
}
Output of program:


You can also find factorial using recursion, in the code fact is an integer variable so only factorial of small numbers will be correctly displayed or which fits in 4 bytes. For large numbers you can use long data type.

Java program for calculating factorial of large numbers


Above program does not give correct result for calculating factorial of say 20. Because 20! is a large number and cant be stored in integer data type which is of 4 bytes. To calculate factorial of say hundred we use BigInteger class of java.math package.

import java.util.Scanner; 
import java.math.BigInteger; 
class BigFactorial { 
public static void main(String args[]) { 
int n, c; 
BigInteger inc = new BigInteger("1"); 
BigInteger fact = new BigInteger("1"); 
Scanner input = new Scanner(System.in); 
System.out.println("Input an integer"); 
n = input.nextInt(); 
for (c = 1; c <= n; c++) { 
fact = fact.multiply(inc); 
inc = inc.add(BigInteger.ONE); 
} 
System.out.println(n + "! = " + fact); 
} 
}
We run the above java program to calculate 100 factorial and following output is obtained.
Input an integer
100
100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

Enhanced for loop java

Enhanced for loop java: Enhanced for loop is useful when scanning the array instead of using for loop. Syntax of enhanced for loop is:

for (data_type variable: array_name)

Here array_name is the name of array.

Java enhanced for loop integer array

class EnhancedForLoop { 
public static void main(String[] args) { 
int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29}; 
for (int t: primes) { 
System.out.println(t); 
} 
} 
}
Output of program:

Java enhanced for loop strings

class EnhancedForLoop { 
public static void main(String[] args) { 
String languages[] = { "C", "C++", "Java", "Python", "Ruby"}; 
for (String sample: languages) { 
System.out.println(sample); 
} 
} 
}

Wednesday, September 9, 2015

Java program to find largest of three numbers

This java program finds largest of three numbers and then prints it. If the entered numbers are unequal then "numbers are not distinct" is printed.

Java programming source code

import java.util.Scanner;
class LargestOfThreeNumbers { 
public static void main(String args[]) { 
int x, y, z; 
System.out.println("Enter three integers "); 
Scanner in = new Scanner(System.in);   
x = in.nextInt(); 
y = in.nextInt(); 
z = in.nextInt();   
if ( x > y && x > z ) 
System.out.println("First number is largest."); 
else if ( y > x && y > z ) 
System.out.println("Second number is largest."); 
else if ( z > x && z > y ) 
System.out.println("Third number is largest."); 
else System.out.println("Entered numbers are not distinct."); 
} 
}

Output of program:


If you want to find out largest of a list of numbers say 10 integers then using above approach is not easy, instead you can use array data structure.