Saturday, 13 September 2014

Swapping two numbers

java source code

import java.util.*;
class swap
{
  public static void main(String[] args)
   {
     Scanner scr=new Scanner(System.in);
     System.out.print("Enter first number:");
     int n1=scr.nextInt();
     System.out.print("Enter second number:");
     int n2=scr.nextInt();
System.out.println("The first number is "+n1+" and the second number is "+n2);
       /*logic for swapping,
       1>assign number1 to a temporary variable
       2>assign number2 to number1
       3>assign temporary variable to number1*/
     int temp=n1;
     n1=n2;
     n2=temp;
System.out.print("After swapping, the first number is "+n1+" and the second number is "+n2);
  }
}

Unit conversion in java(km->m)

java source code

import java.util.*;
class UnitConverg
{
   public static void main(String args[])
   {
     Scanner scr=new Scanner(System.in);
     System.out.print("Enter units in Km to be converted ");
       int Km=scr.nextInt();
     int m=Km*1000;
     System.out.print("Unites in m is "+m);
   }
}

Calculation of Simple Interest

java source code

import java.util.*;
public class SimpleInterest
{
public static void calculate(int principal, int time, int rate)
{
     double interest = principal * time * rate / 100;
     double amount = principal + interest;
     System.out.println("Interest is " + interest);
     System.out.println("Amount is " + amount);
}
   public static void main(String args[])
{
     Scanner scr=new Scanner(System.in);
     System.out.print("Enter Principal Amount:");
     int principal=scr.nextInt();
     System.out.print("Enter time:");
     int time=scr.nextInt();
     System.out.print("Enter rate of interest:");
     int roi=scr.nextInt();
     calculate(p,t,r);
   }
}

Program in java

Addition of two numbers

java source code

import java.util.*;
class Addition
{
  public static void main(String args[])
  {
     Scanner scr=new Scanner(System.in);
     System.out.print("Enter 1st number:");
     int n1=scr.nextInt();
     System.out.print("Enter 2nd number:");
     int n2=scr.nextInt();
     int sum=n1+n2;
     System.out.println("Addition of "+n1+" and "+n2+" is "+sum);
   }
}

Friday, 12 September 2014

Program in java




Basic Programs Conditional Programs
Sum of Two numbers Larger between two vaiables
Calculate Simple Interest Largest using ternary Operator
unit conversion Km-->meters Larger among three vaiables
Swap two variables Larger among three vaiables using nested if else

BLOG IN CONTRUCTION......

LARAVEL ...installation

l.jpg








LARAVEL






Installation (windows)    


Step 1

  • Install composer from link on laravel official website
           Laravel utilizes composer to manage its dependencies. First download a copy of the compose.phar once you have PHAR archive, you can either keep it in your local project directory or move to user/local/bin to use it globally on your system. On Windows, you can use the composer windows installer

Step 2

  • Through command prompt
                   -via Laravel Installer
                            First, download the Laravel installer using Composer.
                          Command: “composer global require "laravel/installer=~1.1"
Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable is found when you run the laravel command in your terminal.
Once installed, the simple laravel new command will create a fresh Laravel installation in the directory you specify. For instance, laravel new blog would create a directory named blog containing a fresh Laravel installation with all dependencies installed. This method of installation is much faster than installing via Composer.
Step 3

  • Via Composer Create-Project
            You may also install Laravel by issuing the Composer create-project command in your terminal:
Command=”composer create-project laravel/laravel --prefer-dist


               





Friday, 23 May 2014

downloading and installing JDK

Installing JDK

please watch video below.................

 
Running a java program ....

Thursday, 17 April 2014

First java program

A First Simple Program

/*This is first simple Java program 
Call this file Example,java*/

class Example 
{
 public static void main(String args[])
 {
   System.out.println("This is a Simple java program");
 }
}
---------------------------------------------
Entering the program
--------------------------------------------------------
Compiling the  program

To compile the Example program, execute the compiler, javac , specifying source file on the command line as shown here

c:\>javac Example.java

The javac compiler creates a file called Example.class that contains bytecode version program. As discussed earlier, the Java Bytecode is the intermedia representation representation of your program that contains instructions that Java Virtual machine will execute
Thus output of javac is not code that can be directly executed.

To actually run the program, you must use the application launcher called java. To do so, pass the class name Example as a Command -line argument, as shown here.
 
c:\>java Example

Output:This is a Simple java program
---------------------------------------------------------
A closer look
--------------------------------------------------------

Monday, 7 April 2014

Java Primitive Data Types - Default Values

TARGET LANGUAGE:JAVA

THEORY:(DATA TYPE:Default Values)

  • Java primitive data types are initialized to some default values when they are declared as class members.
  • While programming in Java you declare and use variables at two places.
  • First, inside a function those are local to that function.
  • And second, as a class member. When a variable is declared local to a function it must be initialized or assigned before its first use otherwise compiler reports an error "variable <variable name> might not have been initialized". But when a variable is declared as a class member or field, it is not always essential to assign a value to the member.
  • In that case class members are initialized to some default values by the compiler. However, leaving class members uninitialized is not considered a good practice.
  • The following table lists the default values for the data types shown in Table 1.
  •  

Sunday, 6 April 2014

Character data type...

 TARGET LANGUAGE:JAVA

THEORY:(DATA TYPE:Character and Boolean)

Character

  • Data type used to store characters is char.
  • Java uses UNICODE to represent characters
  • Java char is 16 bit type
  • The range of char is 0 to 65,536
  • There are no negative char.
UNICODE-
Unicode provides a unique number for every character,
no matter what the platform, no matter what the program,
no matter what the language.
Unicode Table


EXAMPLE:
//Demonstrates char Data types
 
class charDemo1
{
  public static void main(String args[])
  {
    char ch1,ch2;
    ch1=88;
    ch2='Y';
    System.out.print("ch1 and ch2");
    System.out.println(ch1+" "+ch2);
  }
}

//ch1 and ch2:X Y

-Notice that ch1 is assigned 88,which is ASCII(and UNICODE) value of the corresponding letter X
 
class charDemo2
{
  public static void main(String args[])
  {
    char ch1,ch2;
    ch1='X';
    System.out.println("ch1:"+ch1);  
    ch1++;
   
    System.out.println("ch1:"+ch1);
  }
}

//ch1:X
//ch1:Y

-As ch1 is increamented the ASCII value is increamented.Thus second time in the output we get Y. 

BOOLEAN

Java has a primitive type,called Boolean for logical values.
It can have only one of the two values true,false.

EXAMPLE

class Booltest
{
  public static void main(String args[])
  {
   boolean b;
   b=false;
   System.out.println("b:"+b);

   b=true;
   System.out.println("b:"+b);
  
   if(b)//a Boolean value can control if statement
   {
     System.out.print("This is executed");
   }
b=false;

   if(b)//This is not executed
   {
     System.out.print("This is not executed");
   }

  }
}

Output of relational operator in if statement is Boolean value
eg 10>9


---------------------------------------------
In the next publication  we shall deal with literals
---------------------------------------------


Friday, 4 April 2014

Floating-Point types

TARGET LANGUAGE:JAVA
THEORY:(DATA TYPE:Float)

Floating Point Type

Floating point numbers also known as real numbers are used when evaluating expressions that require fractional precision.

Example:

  1. Calculations such as  square root..
Program:

public class CalculateSquareRootWithMathSqrt
 {
 public static void main(String[] args) 
        {       
                float a=30;
                 
  // square root of 16 which equals with 4
  System.out.println(Math.sqrt(16));
   
  // square root of 44 which is 6.6332495807108
  System.out.println(Math.sqrt(44));
  
  // sin of 30 is -0.9880316240928618
  System.out.print(Math.sin(a));
  
  //cos of 30 is 0.15425144988758405
  System.out.print(Math.cos(a));
        }

}

There are two kinds of floating point types Float and double.
Their ranges are specified in the table below.

Primitive  data Types

FLOAT

  • The type specifies a single precision value that uses 32 bit of storage.
  • Variables of float are useful when you need a fractional component but don't require large degree of precision. 
DOUBLE

  • The type specifies double  precision values that uses 64 bit of storage
  • Variables of float are useful when you need a fractional component but  require large degree of precision. 
Program: Area of circle

class Area
{
 public static void main(String args[])
 {
   double pi,r,a;
   r=10.7;//radius of circle
   pi=3.14;//pi,approximately
   a=pi*r*r;//compute area
   System.out.print("Area of circle"+a);
 }
}
---------------------------------------------
In the next publication,we shall see character type and then literals.
---------------------------------------------
After which we shall take a closer look at the simple program...in the next Publication 
--------------------------------------------


Monday, 31 March 2014

Integers Data types Simplified.....

TARGET LANGUAGE:JAVA
THEORY:(DATA TYPE:INT)


  • Data type is one of java's most fundamental  three elements(data types, variables, arrays).
  • As like all programming languages java supports several types of data.
JAVA is a SRONGLY TYPED LANGUAGE
  • First, every variable has a type, every expression has a type, every type is strictly defined.
  • Second, all assignments whether explicit or via parameter passing in method calls, are checked for type compatibility.
  • Any type mismatch or error must be corrected before compilation.   
Primitive Types

 Data types are primarily used in computer programming, in which variables are created to store data. Each variable is assigned a data type that determines what type of data the variable may contain. Java defines eight types of data: byte, short, int, long, char, float, double, and Boolean.
We are going to see only integer data type.
    • Integer-
      • It includes byte, short, int, and long, which are whole valued signed numbers.
      • All of them are signed(positive and negative values).
      • Java does not support unsigned integers
The width and ranges if these integer types vary widely, as shown in the table.
      
     
    
NameSizeRange
byte8 bit-27 to 2 7-1
short16 bit-215 to 215-1
int32 bit-231 to 231-1
long64 bit-2 63 to 2 63-1
      
    table ref:http://www.jchq.net/certkey/0406certkey.html
-----------------------------------------------------------      
A simple byte program
  1. /*
  2.   Java Byte Example,Byte is a wrapper class provided to wrap byte primitive value. It has a single field of type byte.
  3. */
  4. public class ByteExample {
  5.   public static void main(String[] args) {
  6.     //create a Byte object using one of the below given constructors
  7.     //1. Create a Byte object from byte
  8.     byte b = 10;
  9.     Byte bObj1 = new Byte(b);
  10.    
  11.     /*
  12.     2. Create Byte object from String. Please note that this method can
  13.     throw NumberFormatException if string doesnt contain parsable number.
  14.     */
  15.     Byte bObj2 = new Byte("4");
  16.    
  17.     //print value of Byte objects
  18.     System.out.println(bObj1);
  19.     System.out.println(bObj2);
  20.   }
  21. }
  22. /*
  23. Output of the program would be
  24. 10
  25. 4
  26. */
------------------------------------------------------------
Byte

  • It is the smallest integer type.
  • It is a signed 8 bit type that has a range from -128 to 127
  • It is useful when you are working with a stream of data from network or file.

Short

  • It is a signed 16 bit type.
  • It has a range from -32,768 to 32,768
  • It is probably the least used Java type.
Declaration:

short s;
short t;

int 

  • It is commonly used integer type.
  • It is a signed 32 bit that has a range of -2,147,483,647 to 2,147,483,647.

long

  • It is a signed 64 bit type for those occasions when int is not large enough to hold the desired value 
  • For example below is a program which calculates the number of miles light will travel in specific number of days.

class Light
{
  public static void main(String args[])
  {
   int lightspeed;
  double days;
  double seconds;
  double distance;
   
   lightspeed=186000;//approximate speed of light
   days=1000;//specify the number of days here
   seconds=days*24*60*60;//convert to seconds
   distance=lightspeed*seconds;
   System.out.println("In "+days);
   System.out.println(" days light will travel about ");
   System.out.println(distance+" miles.");
  }
}
---------------------------------------------------------
The program will generate the following o/p

In 1000 days light will travel about 1607040000000 miles

Clearly,the result could not be held in an int variable
--------------------------------------------------------------
next publication will consist of floating point types ---------------------------------------------------------------- 

Friday, 28 March 2014

My first Blog....

TARGET LANGUAGE:JAVA


PROGRAMME NO 1
 
----------------------------------------------------------------

public class hello
 {
        public static void main(String args[])
      {
          System.out.print("Hello world");
      }
}

//Output:-Hello world
--------------------------------------------------------------------------------------------------------------------
From the above program we can conclude the following features of JAVA

1. java is simple

2. java is secure i.e.
  • It cannot harm other systems
3. It encourages error free programming i.e. it is ROBUST.
-------------------------------------------------------------------------------------------------------------------