Thursday, 23 August 2018

USER INPUT IN JAVA

USER INPUT IN JAVA

Hello Friends,
                         Today I am going to tell you two ways to take input from user in java.
As we know that java is an object oriented language so any work is based on classes and objects.
First Way :

                 In this method we use two java classes named as : 

               InputStreamReader  and BufferedReader 

There are 2 type of streams : Input Stream and Output Stream 
Input Stream are those stream which receive or read data coming from some other place. and Output Stream are those stream which send and write data 

All the streams are represented by the classes in java.io package, so we need to import this package in our program.
import java.io.*;
 To take input from the keyboard we use System.in 
System.in: it represent InputStream object, which by default represent standard input device i.e. Keyboard

Now first step to create object of InputStreamReader class and connect keyboard to it

1)  InputStreamReader obj = new InputStreamReader(System.in);

Second we have to create the object of BufferedReader class and connect the previous object to that

2)  BufferedReader  br = new  BufferedReader(obj);

Now to read data we have 2 methods of BufferedReader Class 

    read()     and readLine();

read() :    this method is used to read a single character from the keyboard, but it returns the ASCII value of that character. So to print the character on screen we have to convert integer (ASCII value) to char data type 

char ch = (char) br.read();

readLine():  this method read a string from keyboard such as :

String s = br.readLine();

 If we want to take integer we have to convert it 

int n = Integer.parseInt(br.readLine());

 In the same way we can convert string in any of primitive data type.

Example :


import java.io.*;
class First
{
       public static void main(String args[]) throws IOException
        { 
             //above two lines in article can be combimed and written as :
              BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
              System.out.print("enter your name, gender and age");
              String name = br.readLine();
                char gender = (char)br.read();
              int age = Integer.parseInt(br.readLine());

             // display details 
             System.out.println("name = " + name);
             System.out.println("gender = " + gender);
             System.out.println("age = " + age);
}

The only thing which is not discussed till now is Throws IOException  i have written right after main method. it is because :
read() method of BufferedReader class throw an runtime exception named IOException and our program stuck bcaz of the exception . there are 3 ways to handle exception 
1) put the code generating exception in try block and define a catch block below
2) throw the exception using throw keyword
3) throws keyword is used at the method definition, which is generating Exception
so we are using 3rd way in this program ..

I hope it will be helpful for those who is studying java first time ...... 
If you have any question, u can ask in comment ..

Thank You ...






Friday, 20 July 2018

Introduction to android

ANDROID BASICS  


All you need to know before starting android programming ...

ANDROID is an open source  operating system that is based on a modified version of linux.

About its architecture 

1) LINUX KERNEL  -- It contains device driver for display, camera, memory .....

2)  LIBRARIES  -- developed in C/C++

some of them are --

SURFACE MANAGER - for display management

SQLITE   -- for database support

SSL --or security

WEBKIT  -- for web browsing

OpenGL/ES -- graphic library

FREETYPE -- it is used as font render in android

SGL -- scalable graphic library

LIBC -- standard C library

SSL -- secure socket layer

3) ANDROID RUNTIME 

Core libraries    &   DALVIK VIRTUAL MACHINE (DVM)

*   Program for android are written in java and compiled to byte code for JVM, which is then translated to Dalvik bytecode and  stored in .dex (dalvik executable) and .odex (optimized dalvik executable)

Succesor of Dalvik is ART Android Runtime which uses the same byte code and  .dex file but not .odex.

* Each app is a different user for  android OS.
* Each app is assigned a unique linux user ID which is used by the system & unknown to the app.
* It is possible to arrange for  2 apps to share the same linux user ID, in which they aare able to access each others files
* App with same user ID can also arrange to run in same linux process & share the same VM.


To be continued .....



Thursday, 19 July 2018

Matrix & ITS Types

MATRIX :

"Matrix is nothing but the rectangular representation of data in the form of rows and columns inside square brackets "


  • A row matrix is a matrix that has only one row.
  • A column matrix is a matrix that has only one column.
Example :

Image result for matrix examples in maths
To convert linear equations into matrix :

Each equation in the system becomes a row. Each variable in the system becomes a column. The variables are dropped and the coefficients are placed into a matrix. If the right hand side is included, it's called an augmented matrix. If the right hand side isn't included, it's called a coefficient matrix.

The system of linear equations ...

 x +  y -  z = 1
3x - 2y +  z = 3
4x +  y - 2z = 9

becomes the augmented matrix ...


x
y
z
rhs


1
1
    -1 
        1


3
-2
1
3


4
1
-2
9


Type of Matrix :

1. ZERO/NULL Matrix :

Image result for zero matrix examples in maths

2. UPPER  & LOWER TRIANGULAR MATRIX :

Image result for upper triangular matrix examples in maths


3. Diagonal Matrix  :

Image result for diagonal matrix example
4. IDENTITY MATRIX:

Image result for diagonal matrix example
5. SYMMETRIC MATRIX : 


Image result for diagonal matrix example

* If a matrix is equal to its transpose matrix then it is called symmetric matrix.

                                                                  A = AT

6. SKEW SYMMETRIC 

* If a matrix is equal to the negative of its transpose then it is called SKEW SYMMETRIC 


 A = -AT


Example of skew symmetric :

Image result for skew symmetric  matrix example


7. Idempotent Matrix :

Image result for idempotent matrix example

* A square matrix A is called idempotent matrix if   

A2 = A

8. Involutory Matrix 
 A2 = I






Search This Blog

Total Pageviews