Skip to main content

JAVA Programming



JAVA

Introduction:
                         Java is a pure object oriented programming language. Java is developed by James Gosling(Computer Scientist) in 1991. Latest version of Java program files is JDK 10.0.1. 


JDK:- It is Java Development Kit. It can be downloaded free from internet.


JVM:- Its JAVA VIRTUAL MACHINE. It is use for run the program of java. The JVM use byte code file for running the program.

BYTE CODE:- This file contains the byte code information. The byte code file is created after compilation of java source code.

Setting Global path of java:-

use environmental variable 

1. Right click on my computer
2. Click on Advanced System Setting 
3. Click on Environmental Variable.
4. Select path from the list. and click on edit button.
5. Select java Path From C:\ Drive LIke : C:\program Files\Java\jdk_\bin.
6. Type ; from end and paste the path. and ok.
 --------------------------------------------------------------------

Variable:-
--------

datatype variable_name=value;

int a=45;
float x=4.6f;
double xy=4.777777777;
String name="AMIT";
String ab="a"; a is define as string type
char ch='a'; a is define as character type
boolean z=true/false;  1/0
-------------------------------------------------------------------
System.out.println("msg"+variable);
                          here + is use for concatenate the msg and value.
like:-

   int a=34;
System.out.println("a="+a); output:- a=34
System.out.println(a); output :- 34
------------------------------------------------------------------

COMMENTS:-
single line:-   //
multiline:  /* ........ */

-------------------------------------------------------------------------
Input from the keyboard by using scanner class:-
-------------------------------------------------

1. use header file:- import java.util.*;

2. object of scanner class

Scanner sc=new Scanner(System.in);
     class_name         constructor
here sc is an object.

3. input of value
 integer value:-
sc.nextInt();
int a=sc.nextInt();

 float value
float b=sc.nextFloat();

Double value
double c=sc.nextDouble();

Long value
long d=sc.nextLong();

String value
String s1=sc.nextLine();

Character value
char ch=sc.next().charAt(0);
------------------------------------------------------
Condition:-
1.if

2.if..else

3.ledder

4.Nested

5.Ternary operation


   False<-------If cndition------->True
     |                           
     |                             
     |
     |
    Else
------------------------------------------------
Operaters:-       (x=3,  y=2|a=2 ,  b=3)
  > Greater                      a>b=false 
  < Less                           a<b=true   
 >= Greater or equel       x>=y=true
 <= Less or equel            x<=y=true
  = Equel                         a==b=true
 != Not equel                  a!=b=true

 1.    if
         
               if(Condition)
                {
                  .......
                  ....... true
                  .......
                 }
             
When Condition is false then if provide No result
             
            if(Condition)---->True
                               |
                               |
                               |
                            Execute
                                         
2.If..else

            If(Condition)
             {
              ........
              ........ True
              ........
             }
             else
             {
              ........
     False    ........
              ........
              }     

            False-------(Condition)--------True
              |                              |
              |                              |
              |                              |
          Exe False                       Exe True 
----------------------------------------------------------------------lader if:-
-----------
it is use for check multiple condition in steps.
it is use in range program.
syn:-
if(condition)
{
-----
-----
}
   else if(condition)
{
----
----
}
   else if(condition)
{
-----
-----
}
.
.
.
else
{
-----
-----
}
---------------------------------------------------------------------
type casting of data:-
---------------------
it means to change the data in to another type.
variable=(datatype)value;
always typecasting is perform when the data is converted into small to large datatype.
like int to long
like float to double
like int to float
 like :-
  int x=4;
  int y=x/3;  hear y contain a float value then it give an error so use type casting for converting the decimal (float) value in to integer.
      example:-
int y=(int)x/3;
then and is converted into integer value
-----------------------------------------------------------------------
working with multiple condition:-
-----------------------------------
logical operator:-
---------------
   it is use for check the range of program value.
there are three types of logical operator.
1. AND && use when check all condition is true
2. OR   || use when atleast one condition is true.
3. NOT  !  when condition is true then result is false.
---------------------------------------------------------------------
nested if:-
-----------
if within if
if first condition is true then check second condition
syn:-
----
if(condition)
{
if()
{
----
----
}
else
{
----
----
}
}
else
{
if()
{
}
else
{
}
}
-----------------------------------------------------------------
choice based programming:-
-------------------------
menu driven programming

print menu 1
print menu 2
print menu 3
.
.
.
.
input choice
switch(choice)
{
case 1:
------------
-----------
-----------
break;
case 2:
------------
-----------
-----------
break;

case 3:
------------
-----------
-----------
break;

case 4:
------------
-----------
-----------
break;

.
.
.
default:
when case are not in the list then default is executed.
break;
}
break:- this keyword is use for exit from the case statement.
if break is not use in case then all case are executed till break
<------------------------------------------------------------------------<------------------------------------------------------------------------<----------------------------------------------------------------------->
looping Statement:-
--------------------
looping is use for execute the repeated type of statement .
component of loop:-
------------------
1. initialization start
2. condition stop
3. increment/decrement. step
++ --
type of loop:-
------------------
1. FOR
2. WHILE
3. Do-WHILE
3. NESTED
-------------------------------------------------------------------
1. FOR Loop:-
---------------
syn:-
(1) (2)       (4)
for(initialization;condition;increment/decrement)
{
--------------------
    (3) --------------------
--------------------
}
-----------------
example:-
print your name upto 10 times.

for(i=1;i<=10;i++)
{
S.o.pln("ROBIN");
}
initialization:-i=1 or i=10
condition:- i<=10 or i>=1
increment:- i++ or i--
i=i+1 or i=i-1
i+=1 or i-=1
--------------------------------------------------
while loop:-
----------
initalization;
while(condition)
{
-------------
-------------
-------------
increment/decrement;
}

wap to print 10 times hello;

int i=1;
while(i<=10)
{
print("hello");
i++;
        }
----------------------------------
Input using InputStreamReader class
--------------------------------------
1. import java.io.*;  -> io is input and output
2. create an object

InputStreamReader isr=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(isr);
 remember :- Object of buffer reader is used for taking the input from the user.
3. input:-
variable=TypeCast(br.readLine());
 typecast is use to convert the string value in to integer,float and double.
but for string value then no need to use typecasting.
readLine()-> it is a method to use for taking the input from the user.
------------
For integer value:-
int variable=Integer.parseInt(br.readLine());
For float value:-
float variable=Float.parseFloat(br.readLine());
For double value:-
double variable=Double.parseDouble(br.readLine());
for string value:-
String variable=br.readLine();
for character value:-
char variable=br.read();
always use Exception Handling in java program when use INPUTSTREMREADER class.
throws IOException
------------------
it is use with main() method line.
ex:-
public static void main(String as[])throws IOException

It is use because java is pure secure language and it catch all the input output error. like mouse and keyboard error.
-------------------------------------------------------
example of InputStreamReader class for taking the input and print them
-------------------------------------------------------------------
import java.io.*;
class TestISR
 {
    public static void main(String as[])throws IOException
 {
InputStreamReader isr=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(isr);

    int a;
System.out.println("enter two number ");
        a=Integer.parseInt(br.readLine());
    int b=Integer.parseInt(br.readLine());
    int c=a+b;
System.out.println("sum= " +c);

  }
}
-------------------------------------------------------------------
function:-
--------------
Function is the collection of statement .
function is divide in to two type:-
1. Predefine Function
2. user define function:-
------------------------------------
Predefine Function is also known as library function. It is already define in java.
There are different types of predefine function, LIke:-
1. Math function
2. String Function
------------------------------------------------------
Math Function:--
---------------
Math function returns double value.
Math Function is used with Math keyword as prefix.
There are different types of Math Function:-
-------------------------------------------
double variable=Math.function(value);

Like:-
----
1. pow()   :- finds power of base value
2. sqrt()  : - find square root of value
3. max()   :- find maximum between two value
4. min()   :- find minimum between two value
5. rint()  :-  find roundoff value
6. ceil()  :- find next integer value
7. floor() :- find previous integer value
9. abs()   :- find absolute value
9. random() :- find randome value
10. log()  :- find logrithm value
11. exp()  :- find exponential value
12. sin()  :- find sin value
13. cos()  :- find cos value
14. tan()  :- find tan value
15. asin() :- find inverse sin value
16. acos() :- find inverse cos value
17. atan() :- find inverse tan value
----------------------------------------------------------------
String function:-
----------------
String function works with string value.
it is use for handling the string value operation
String function is start with string value and seperate with dot operator.
ex:-
  String str="hello";
variable=String_value.function(value);
---------------------------------------------------
1. lenght() :- find the length of sting
2. charAt() :- find charater at particular index
3. substring() :- extract the string within string
4. toUpperCase() :- convert string in upper case
5. toLowerCase() :- convert string in lower case
6. equals():- check equality of string in upper or lower case
7. equalsIgnoreCase() :- check equality of sting by ignore case
8. startsWith() :- check string start with particular word or not.
9. endsWith() :- check string ends with particular word or not.
10. indexOf():- find the index of charater in string
11. lastIndexOf() :- find the last index ofcharacter in string
13. replace() :- replace the character with another character.
14. concat() :- combine two or more string
15. valueOf() :- convert integer/float/double value in to string value.
----------------------------------------------------------------------
user define Function:-
------------------

user define function is define by the user.

Decleration Of user define Function-
-----------------------------------
syntax:-
------
[access Specifire][modifier][return type]function_name(parameter,...)
{
   -----------------
   -----------------
   -----------------
   body of function
   -----------------
   -----------------
   return(value/variable); -> used when function define as return type
}
----------------------------------------------------------------------
access specifier:- public/private/protected
modifier:- static/final
return type :- void/int/float/char/double
       void return type is used when function is define as no return type
function_name :- add()
parameter :- its a value that pass when function is called
---------------------------------------------------------------------
Function is called by the help of object:-
-----------------------------------------
like:-
object_name.function_name();
ex:-
 object create:-
 -------------
class_name object_name=new class_name();
 like:-
if class name is Test then
Test ob1=new Test();
ob1.function_name();
like:-
ob1.display();
---------------------------------------------------------------------
like:-
----
define a function display();

  public void display()
  {
System.out.println("This is a display function");
  }
----------------------------------------------------------------

Comments

Popular posts from this blog

O Level Practical Queestion Paper (MS-OFFICE, MSDOS, MS-EXCEL, ICT Resources)

MSDOS 1. Write command to display all files having extension ‘jpg’. 2. Write command to display all files of all types starting with letter ‘m’. 3. Write command to display all files having names up to ten characters with second last letter as ‘n’, e.g. intelligent. 4. Write a command to copy the file mars of type exe from the directory ‘space’ of drive U to another directory “universe” in drive S. 5. Write a command to delete the directory as well as the files of the directory ‘world’ on drive E. 6. Write command to display all file names on the disk in drive A and having an extension of no more than two characters.   7. Write command to copy all the files beginning with ‘m’ and whose file names has a ‘txt’ extension from drive A to the ‘\document’ directory on drive C. 8. Write set of commands to create a subdirectory of the root directory called ‘exercise’, and then move into it 9. Perform the following tasks using DOS commands in the DOS sh...

Learn Programming in UNIX

Q: - Write a program to input two numbers and add them?             gedit add.sh             clear             echo “enter two numbers:”             read a             read b             sum=`expr$a+$b`             echo $sum Syntax for if-else:- (1)          if test condition             then                 ---------                 --...

IICS College 15th August Celebration Day

IICS COLLEGE  15th August Celebration Day