Monday, August 24, 2020

Python Tutorial

 Professional Program Online Tutorials(PPT)



Python 

Python:
             Python can be used to write simple programs, but it also possesses the full power required to create complex, large-scale enterprise solutions.

 the ways in which Python is used includes:

  • Desktop graphical application development, including games;
  • Mathematical and scientific analysis of data; and
  • Web and internet development.

                                Hello world using python

  print("hai")

  output

        hai

                               Adding two integers in python

a=10

b=20

c=a+b

print(c)

 

output

30

                           Adding two decimal numbers

a=10.10

b=20.2

c=a+b

print(c)

output

30.299999999999997

                               String variable print

 

a="sabari"

print(a)

 

output

sabari

 

 

                    Runtime input (String)

 

a=input()

print(a)

 

output

sabari

sabari

 

                        Runtime input(int)

 

a=int(input())

b=int(input())

c=a+b

print(c)

 

output

23

32

55

                          Runtime decimal numbers(float)

a=float(input())

b=float(input())

c=a+b

print(c)

output

20.1

20.2

40.3


 

                            Conditional Statements

If-else syntax

If(condition check):

    Statement;

else:

   statement;

 

example

a=int(input())

b=int(input())

if(a>b):

    print("a is big")

else:

    print("b is big")

 

output

23

21

a is big

 

if-else if

syntax

if(condition check):

   statement;

elif(condition check):

   statement;

else:

  statement;

 

example

 

a=int(input())

b=int(input())

c=int(input())

 

if(a>b and a>c):

    print("a is big")

elif(b>a and b>c):

    print("b is big")

else:

    print("c is big")

 

output

12

22

33

C is big

Nested if

Syntax

  If(condition check):

      If(condition check):

          Statement

    else:

          statement

  else:

       Statement

Example

a=10

if(a>5):

    if(a<20):

        print("a is between 5 to 20")

    else:

        print("a is above 20")

 

else:

    print("a is less then 5")

output

a is between 5 to 20

                                    LOOPINGS 

for loop

syntax

for variable in range(start,end):

     statement

ex

for i in range(1,10):

     print(i)

output

1

2

3

4

5

6

7

8

9

Example 2

for i in range(10):

     print(i)

output

0

1

2

3

4

5

6

7

8

9

 

Example 3

for i in range(2,20,2):

     print(i)

output

 2

4

6

8

10

12

14

16

18

 

While loop

Syntax

Initialize;

While(condition check):

  Statement

  Inc/dec

 

Example

 

i=0

while(i<5):

    print("hai")

    i=i+1

output

hai

hai

hai

hai

hai


break

 

i=0

while(i<5):

    print("hai")

 

    i=i+1

    if(i==3):

        break

output

hai

hai

hai


continue

 

i=0

while(i<5):

    i=i+1

  

    if(i==3):

        continue

 

    print(i)

   

 output

1

2

4

5

 

                        Strings

 

Example 1

a="sabari"

print(a)

a='sabari'

print(a)

 

output

sabari

sabari

Example 2(index print)

a="hello"

print(a[0])

output

h

Example 3(index particular)

a="hello"

print(a[1:3])

output

el

Example 4(index upto)

a="hello"

print(a[:3])

output

hel

example 5(index with reverse)

a="hello"

print(a[-1])

 

output

o

example 5(delete the string)

a="hello"

del a

                                String methods

1.index

a="hello this is python program"

b=a.index("this")

print(b)

output

6

2.upper

a="hello this is python program"

b=a.upper()

print(b)

output

HELLO THIS IS PYTHON PROGRAM

3.lower

a="HELLO"

b=a.upper()

print(b)

output

hello

4.isdigit()

a="hello"

print(a.isdigit())

output

False

 

5.isdecimal()

a="5"

print(a.isdecimal())

output

True

6. capitalize()

a="hello this is python"

print(a.capitalize())

output

Hello this is python

7.startswith()

a="hello this is python"

print(a.startswith('h'))

output

True

8.endswith()

a="hello this is python"

print(a.endswith('h'))

output

False

 

9.replace()

a="hello this is python"

a=a.replace("hello","welcome")

print(a)

output

welcome this is python

 

Functions example

 

Syntax

def  functionname():#delcare/define

    statement

functionname() #calling

example

#define

def sabari():

    print("hai")

 

#calling

sabari()

output
hai

Function with argument

#define

def sabari(fname):

    print(fname)

 

#calling

sabari("sabari")

output

sabari

 

Lambda expression

Synax

Lambda arguments:Expression


Example 

x=lambda a:a+10

print(x(5))

output

15

 

2 values

x=lambda a,b:a*b

print(x(5,5))

output

25

 

Arrays

 

cars=["bmw","ford","volvo"]

print(cars)

output

["bmw","ford","volvo"]

 

One by one print

cars=["bmw","ford","volvo"]

for i in cars:

    print(i)

output

bmw

ford

Volvo

 

Adding array

cars=["bmw","ford","volvo"]

cars.append("hello")

for i in cars:

    print(i)

output

bmw

ford

Volvo

hello

Remove(pop)

cars=["bmw","ford","volvo"]

cars.pop(1)

for i in cars:

    print(i)

output

bmw

volvo

remove keyword

cars=["bmw","ford","volvo"]

cars.remove("bmw")

for i in cars:

    print(i)

output

ford

Volvo

                                            Python collections

1.List

Ordered and changeable,duplicates

2.Tuple

Order and unchange able,duplicate

3.set

Un order and un index (no duplicates)

4.dictionary

Unordered,changeable and indexed(no duplicates)

 


1.List

Example

a=["apple","banana","cherry"]

print(a)

a[1]="orange"

print(a)

output

['apple', 'banana', 'cherry']

['apple', 'orange', 'cherry']

 

Example(list with index)

a=["apple","banana","cherry"]

print(a[1])

output

banana

 

Example (negative index)

a=["apple","banana","cherry"]

print(a[-1])

output

cherry

 

append

 

a=["apple","banana","cherry"]

a.append("orange")

print(a)

 

ouput

['apple', 'banana', 'cherry', 'orange']

 

Insert

a=["apple","banana","cherry"]

a.append("orange")

a.insert(1,"wel")

print(a)

 

ouput

['apple',’wel’, 'banana', 'cherry', 'orange']

 

Remove

a=["apple","banana","cherry"]

a.remove("apple")

print(a)

output

banana,cherry

 

pop

a=["apple","banana","cherry"]

a.pop()

print(a)

output

['apple', 'banana']

 

                                                       Tuples

Example

a=(101,'sabari',10)

print(a[0])

 

output

101

 

Example 2

a=(101,'sabari',10)

for i in a:

    print(i)

output

101

sabari

10

                                    Set

 

Example

 

days={"sabari","nathan","mca","sabari"}

print(days)

 

output

{'mca', 'sabari', 'nathan'}

 

Add

days={"sabari","nathan","mca","sabari"}

print(days)

days.add("monday")

print(days)

output

{'monday', 'sabari', 'nathan', 'mca'}

 

                                            Dictionary

example

emp={"Name":"sabari","Age":25}

print(emp)

output

{'Name': 'sabari', 'Age': 25}

 

Example

emp={"Name":"sabari","Age":25}

print(emp["Name"])

output

sabari

 

                                                             Class and objects

 

class A:

    x=5

 ob=A()

print(ob.x)

 output

                                           Constructor

class A:

  def __init__(self):

      print("hai")

  

ob=A()

 

output

hai

 

class and objects with functions

class A:

  def get(self,name):

      print("hai ",name)

  

ob=A()

ob.get("sabari")

output

sabari

 

modules

 

sd.py

def sabari():

    print("hai")

 

gg.py

 

import sd

 

sd.sabari()

 

output

hai

 

 

 




Wednesday, June 3, 2020

Jsp tutorial


JSP HELLO WORLD

Eclipse-->new -->Dynamic Web Project
---->webcontent--->jsp file

Program


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%

out.println("hai");



%>



</body>
</html>

Run Program

right click-->run as--->run server--->apache tomact 7.0




Addition of two numbers using jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%

int a,b,c;
a=10;
b=20;
c=a+b;
out.println("c is "+c);



%>



</body>
</html>


O/P

c is 30


Run time input

exam.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action="exam1.jsp" method="post">

Username <input type="text" name="n1"><br><br>
Password <input type="password" name="n2"><br><br>

<input type="submit">

</form>


</body>
</html>


exam1.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

String a=request.getParameter("n1");
String b=request.getParameter("n2");

out.println(a);
out.println("<br>");
out.println(b);


%>




</body>
</html>


if-else

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action="exam1.jsp" method="post">

a <input type="text" name="n1"><br><br>
b <input type="text" name="n2"><br><br>

<input type="submit">

</form>


</body>
</html>

exam1.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

int a,b;
a=Integer.parseInt(request.getParameter("n1"));
 b=Integer.parseInt(request.getParameter("n2"));
if(a>b)
{
out.println("a is big");
}

else
{
out.println("b is big");
}

%>




</body>
</html>

username and password checking

exam.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action="exam1.jsp" method="post">

username <input type="text" name="n1"><br><br>
password<input type="password" name="n2"><br><br>

<input type="submit">

</form>


</body>
</html>

exam1.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

String a,b;
a=request.getParameter("n1");
 b=request.getParameter("n2");
if(a.equals("admin") && b.equals("admin"))
{
out.println("correct password");
}

else
{
out.println("wrong password");
}

%>




</body>
</html>

Thursday, April 9, 2020

Java output questions set - 10


SET-10

1.class test
{
    public static void main(String args[])
   {
 int[] arr = {1,2,3,4};
 call_array(arr[0], arr);
 System.out.println(arr[0] + "," + arr[1]);     
    }
    static void call_array(int i, int arr[])
    {
 arr[i] = 6;
 i = 5;
   } 
}
(A) 1,2
(B) 5,2
(C) 1,6
(D) 5,6

2.public class test
{
 public static void main(String args[])
  {
  int x;
  x = -3 >> 1;
  x = x >>> 2;
  x = x << 1;
   System.out.println(x);
  }
}
(A) 7
(B) 23
(C) 5
(D) 2147483646

3.public class test {
    public static void main(String args[]) {
    String s1 = "abc";
    String s2 = "abc";
    if(s1 == s2)
        System.out.println(1);
    else
        System.out.println(2);
    if(s1.equals(s2))
        System.out.println(3);
    else
        System.out.println(4);
    }
}

(A) 1 2
(B) 1 3
(C) 1 4
(D) 2 4

4.public class test {
    public static void main(String args[]) {
    String s1 = "abc";
    String s2 = new String("abc");

    if(s1 == s2)
        System.out.println(1);
    else
        System.out.println(2);
    if(s1.equals(s2))
        System.out.println(3);
    else
        System.out.println(4);
    }
}
(A) 1 3
(B) 1 4
(C) 2 3
(D) 2 4

5.public class test
{
 public static void main(String args[])
  {
   int i = -1;
   i = i >> 1;
    System.out.println(i);
 }
}
(A) 255
(B) 128
(C) -1
(D) 1

6. Which of the following are legal array declarations
a.int i[5][];
b.int i[][];
c.int []i[];
d.int i[5][5];
e.int[][] a;
(A) a, d, e
(B) b, c, d
(C) b, c, e
(D) a, c, e

7. Which of the following are valid declarations for the main method
a.public static void main(String args[]);
b.public static void main(String []args);
c.final static public void main (String args[]);
d.public static int main(String args[]);
e.public static abstract void main(String args[]);
(A) a, b, c
(B) b, d, e
(C) a, d, c
(D) a, b, e

8.public class example {
  public static void main(String args[]) {
   int x = 0;
   if(x > 0) x = 1;
   switch(x) {
   case 1: System.out.println(1);
   case 0: System.out.println(0);
   case 2: System.out.println(2);
    break;
   case 3: System.out.println(3);
   default: System.out.println(4);
   break;
   }
  }
 }

A.0
B.1
C.2
D.3
E.4
(A) 1, 0, 2
(B) 3, 4
(C) 0, 2
(D) 1

9.String str;
int fname;
str = "Foolish boy.";
fname = str.indexOf("fool");
(A) 0
(B) 2
(C) -1
(D) 4

10.public class test {
 public static void main(String args[]) {
  byte x = 3;
   x = (byte)~x;
   System.out.println(x);
  }
 }
(A) 0
(B) 3
(C) -4
(D) none of these

Java output questions set - 9


SET-9

1)import java.util.*;
class demo1 {
 public static void main(String[] args)
 {
  Vector v = new Vector(20);
  System.out.println(v.capacity());
  System.out.println(v.size());
 }
}
A.20,0
B.22,2
C.20,1
D.20,2
2)
public class testmeth
{
static int i = 1;
public static void main(String args[])
{
System.out.println(i+” , “);
m(i);
System.out.println(i);
}
public void m(int i)
{
i += 2;
}
}

A.1 , 3
B.3 , 1
C.1 , 1
D.1 , 0

3)
Among these expressions, which is(are) of type String?

(A) “0”
(B) “ab” + “cd”
(C) ‘0’
(D) Both (A) and (B) above
(E) (A), (B) and (C) above.
4)
class eq
{
public static void main(String args[])
{
String s1 = “Hello”;
String s2 = new String(s1);
System.out.println(s1==s2);
}
}


(A) true
(B) false
(C) 0
(D) 1
5)
 Use the following declaration and initialization to evaluate the Java expressions

int a = 2, b = 3, c = 4, d = 5;
float k = 4.3f;

System.out.println( – -b * a + c *d – -);

(A) 21
(B) 24
(C) 28
(D) 26
(E) 22.
6)
class prob1{
int puzzel(int n){

int result;

if (n==1)
return 1;
result = puzzel(n-1) * n;
return result;
}
}

class prob2{

public static void main(String args[])

{

prob1 f = new prob1();

System.out.println(” puzzel of 6 is = ” + f.puzzel(6));

}
}
(A) 6
(B) 120
(C) 30
(D) 720
7)
In Java, a try block should immediately be followed by one or more ……………….. blocks.

(A) Throw
(B) Run
(C) Exit
(D) Catch
8)
public class Compute {

public static void main (string args [ ])
{
int result, x ;
x = 1 ;
result = 0;
while (x < = 10) {
if (x%2 == 0) result + = x ;
+ + x ;
}
System.out.println(result) ;
}
}

(A) 55
(B) 30
(C) 25
(D) 35
9)
Which of the following statements about Java Threads is correct?

(A) Java threads don’t allow parts of a program to be executed in parallel
(B) Java is a single-threaded language
(C) Java’s garbage collector runs as a high priority thread
(D) Ready, running and sleeping are three states that a thread can be in during its life cycle

10)
In a class definition, the special method provided to be called to create an instance of that class is known as a/an

(A) Interpreter
(B) Destructor
(C) Constructor
(D) Object 



Java Output questions set - 8


SET-8

1)public class Application {
    public static void main(String[] args) {
       
        String one = "Hello";
        String two = "Hello";
       
        if(one == two) {
            System.out.println("one == two");
        }
        else {
            System.out.println("one != two");
        }
    }
}

A.one == two
B.one != two
C.compile error
D.runtime error

2)Does the following code compile or not?

interface IFruit
{
    public String TYPE = "Apple";
}

class Fruit implements IFruit
{

}

public class Application {
    public static void main(String[] args) {
        System.out.println(Fruit.TYPE);
    }
}
A.yes
B.no
3)
public class HelloWorld{
    public static void main(String[] args) {
        System.out.println(Math.min(Double.MIN_VALUE, 0.0d));
    }
}
A.0.0
B.0.00001
C.Compile error
D.run error
4)
import java.util.*;
public class Test {
    public static void main(String[] args) throws Exception {
        char[] chars = new char[] {'\u0097'};
        String str = new String(chars);
        byte[] bytes = str.getBytes();
        System.out.println(Arrays.toString(bytes));
    }
}
A.-62, -105
B.0097
C.compile error
D.run error
5)
public class FizzBuzzTest{

    public static void main(String args[]){
   
        for(int i = 1; i <=10; i++) {
            if(i % (3*5) == 0) System.out.println("FizzBuzz");
            else if(i % 5 == 0) System.out.println("Buzz");
            else if(i % 3 == 0) System.out.println("Fizz");
            else System.out.println(i);
        }
    }

}

A.1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz
B.Fizz Buzz Fizz 7 8 Fizz Buzz
C.Fizz Buzz
D.1 2 3 4 5 6 7 8 9 10
6)TRUE OR FALSE

class BuggyBread {
   public static void main(String[] args)
   {
      String s2 = "I am unique!";
      String s5 = "I am unique!";
       
      System.out.println(s2 == s5);
   }
}

7)

class BuggyBread2 {

    private static int counter = 0;

    void BuggyBread2() {
        counter = 5;
    }

    BuggyBread2(int x){
        counter = x;
    }
   
    public static void main(String[] args) {
        BuggyBread2 bg = new BuggyBread2();
        System.out.println(counter);
    }
}
A.Compile error
B.Run error
C.5
D.null
8)
public class Test {
 public static void main(String[] args) {
  foo(null);
 }
 public static void foo(Object o) {
  System.out.println("Object impl");
 }
 public static void foo(String s) {
  System.out.println("String impl");
 }
}
A.String impl
B.Object imple
C.compile error
D.run error
9)
long longWithL = 1000*60*60*24*365L;
long longWithoutL = 1000*60*60*24*365;
System.out.println(longWithL);
System.out.println(longWithoutL);
A.31536000000,1471228928
B.12324,56677
C.3153609000,1471228928
D.1245577,324567
10)
public class Testing {
    public static void main(String[] args)
     {
         // the line below this gives an output
         // \u000d System.out.println("comment executed");
     }
}
A.comment executed
B.compile error
C.run error
D.none of the above

Python Technical Interview Questions

 1)first non repeating character Malayalam y programming p str = "MalayalaM" a = '\0' for c in str:     if str.index(c) ==...