PALINDROME CHECK IN JAVA FOR NUMBERS

package palindrome.in.java;
import java.util.Scanner;
public class PalinDromeInJava {
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int rem, temp, sum = 0;
temp = n;
while (n > 0) {
rem = n % 10;
n = n / 10;
sum = (sum * 10) + rem;
}
if (temp == sum) {
System.out.println(“palindrome”);
} else {
System.out.println(“non palindrome”);
}
}
}

                         OUTPUT

121
palindrome

/** but only for numbers this method is applicable
by digit addition and then tenth digit addition and so on it is done!
**/

What people mostly do to waste time!!!

Generally, people who are over conscious about time suffer most for lack of time. They count their life in term of hours, minutes but in doing that they forget to think that where their life is going are they actually doing something productive or they just  count time.

Some of the common characteristics of these are:

  • Regret: An inescapable disease, everyone has for some work but one has to move on. It is good to do regrets in life for which we could not do but it is worse to brood over the same issue thousands of time to destroy even what is left with us. Yes, one should live in present.
  • Useless talking- This includes talking with the friend, family members or anyone other on most irrelevant issues.I am not saying to stop jokes and fun from your life but if you get the chance then help your mind to enhance its domain of wisdom by talking over useful topics. Useless talk brings uselessness only.
  • Mood off: Yes this happens, so meet with a new entity,i.e. friends, psychiatrist, listen to songs or do sth to avoid that or take right decision by going to the depth of the problem.  
  • Procrastination: People procrastinate all the time about the world beyond their reality. Then hate facing reality and enjoy living in the daydream. Guys live in the present that is the only solution, broaden your thinking.  
  • Greediness for the shortcut to study: The more you search for shortcut the more you finds hurdles. It is rightly quoted that there is no shortcut to study. Who search for motivation to motivate himself to study and when he is addicted to this he finds world being difficult. 
  • Getting motivation is good but enough motivation will destroy you. The fact that what you are and where u should be is due to enough motivation. The ratio of Study & motivation should be 80:20. 

Some solution  which may  help you:

  • One minute principle: Think for one minute after u finished your work that how could you make that past work more productive. Remember, I am not saying to look -ve side of yours, that why u could not make work efficient rather have patience & use new ways out.
  • Little me and Big me: "Felling are temporary but the end results are permanent". Mind divert but you know better where to take yourself. Always focus on your goal.
  • Aggressive: Be aggressive while working and keep that aggressiveness synchronized within mind this is best to produce best out of you.
Thank you

ANY NUMBER :-no of digit,sum of digit,check for Armstrong number

 Armstrong :- a  number whose cubic sum of individual digit is equal to same number
package sum.of.digit;
import java.util.Scanner;
public class SumOfDigit {
void no_of_digit() {
Scanner sc = new Scanner(System.in);
System.out.println("enter number to know number of digit");
int no = sc.nextInt();
int nocount = 0;
while (no > 0) {
no = no / 10;
nocount++;
}
System.out.println("no of digit " + nocount);
}
/**documentation comment
*here nocount is initialized to count no of digit after each division by 10
* until number is greater than zero the while loop will continue
* at last when single digit left then further division will result decimal value(0.2 or 0.3) which is lees than zero so loop will fail
* and we will get the count of all digit till single digit left.
*/
void sum_of_digit() {
Scanner sc = new Scanner(System.in);
System.out.println("enter no to know sum of digit");
int no = sc.nextInt();
int sum = 0;
while (no > 0)
{
sum = sum + (no % 10);
no = no / 10;
}
System.out.println("the sum of digit is :" + sum);
}
/** documentation comment
* similarly here, we just add the remainder to sum box
*/
void armstrong_no_check() {
Scanner sc = new Scanner(System.in);
System.out.println("enter no to check for armstrong no");
int no = sc.nextInt();
int k = no;
int cubesum = 0;
int rem = 1;
while (no > 0)
{
rem = no % 10;
cubesum = cubesum + rem * rem * rem;
no = no / 10;
}
System.out.println("the cubesum of digit is :" + cubesum);
if (k == cubesum)
{
System.out.println("the entered number is an armstrong no");
}
else
{
System.out.println("the entered no is not an armstrong no");
}
}
/**documentation comment
* here instead of adding each digit to sum box, we add their cube of remainder to cubesum box
* finally we compare that with no
* caution we need to re-declear the no. at initial point because after while loop the number is no more the same no.
*/
public static void main(String[] args)
{
SumOfDigit ob = new SumOfDigit();
ob.no_of_digit();                                                //evaluating number of digit
ob.sum_of_digit();                                           //calculating sum of digit
ob.armstrong_no_check();                           //testing of armstrong no
}
}

                                    OUTPUT

enter number to know number of digit
153
no of digit 3
enter no to know sum of digit
153
the sum of digit is :9
enter no to check for armstrong no
153
the cubesum of digit is :153
the entered number is an armstrong no

JAVA CODES for prime no between 1 and given no

import java.util.Scanner;

public class Prime_No_Between_1_and_given_no {
public static void main(String[] args) {
int count;
Scanner sc = new Scanner(System.in);
System.out.println("enter the number");
int no = sc.nextInt();
System.out.println("The prime number between 2 and "+no+ " are");
for (int i = 2; i < no; i++) {
count = 0;
for (int j = 2; j < i; j++) {
if (i % j == 0) {
count++;
}
}
if (count == 0) {
System.out.println( i);
}
}
}
}

ERROR CHECKING BY PARITY BIT


import java.util.*;
public class Parity_bit {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the data bit");
String abc = sc.nextLine();
int len = abc.length();
int count1 = 0;
for (int i = 0; i < len; i++) {
if (abc.charAt(i) == '1') {
count1++;
}
}
System.out.println("No of 1 in string is " + count1);
if (count1 % 2 == 0) {
System.out.println("No of 1 is even ");
}
if (count1 % 2 != 0) {
System.out.println("No of 1 is odd ");
}
System.out.println("Enter the parity bit");
String new_bit = sc.nextLine();
String bitnew = abc + new_bit;
System.out.println("The binary data after parity bit addition is " + bitnew);
int rn = 0 + (int) (Math.random() * (len - 0) + 1);
System.out.println("random position is " + rn);
String rn_pos_chg = bitnew.substring(0, rn - 1) + "1" + bitnew.substring(rn);
System.out.println("The random bit is genrated data is:" + rn_pos_chg);
int count = 0;
for (int i = 0; i < len + 1; i++) {
if (rn_pos_chg.charAt(i) == '1') {
count++;
}
}
System.out.println("No of 1 in string is " + count);
if (count % 2 == 0) {
System.out.println("No if 1 is even thus it does not contain error");
}
if (count % 2 != 0) {
System.out.println("No if 1 is odd so it contain error");
}
}
}

RANDOM NO GENERATOR

import java.util.*;
public class RandomNoGenerator {
public static void main(String[] args) {
//way to generate any random no between 0 and 1
double no = Math.random();
System.out.println("random no in double format " + no);
// Way to generate any random no
Random no2 = new Random();
int n = no2.nextInt();
System.out.println("2nd random no is " + n);
//correct way to generate random no between two no here 5 and 10 are two no
int rn = 5 + (int) (Math.random() * (10 - 5) + 1);
System.out.println("random no between 5 and 10 is " + rn);
}
}

Program of object-call through Constructor

CLASS A


class A
{
int a=0; //initialise
A() //default constructor
{
a=10; //value of a in default constructor
}
A(int b) //parametrised constructor
{
a=50; //value of a in PARAMETRISED CONSTRUCTOR
}
void showA() //method call
{
System.out.println(a);
}
}

CLASS B

class B extends A //INHERITANCE OF CLASS A
{
int b=0;
B()
{
b=20; // VALUE OF B IN DEFAULT CONSTRUCTOR
}
B(int a)
{
super(a); // super keyword is used to called the value of super class i.e here class A
b=a;
}
void showB() //METHOD CALL
{
System.out.println(b);
}
}

CLASS Object_Call

class Mock_Test_For_Object_Call//mock test application
{
public static void main (String args[])//main class
{
B b = new B(); //object created as b
b.showA (); //method with default parameter via object of class b is called
b.showB (); // class B is called
}
}

CLASS  Parametrised_Call

class Mock_Test_For_Parametrised_Call
{
public static void main (String args[]) //main class here for A and B CLASS
{
B b = new B(30); //object b created with parameter 30
b.showA (); //method with PARAMETRISED CONSTRUCTOR IS EVOKED BY PASSING THE VALUE AS 30 OF CLASS A THOUGH OBJECT OF CLASS B
b.showB (); // method with PARAMETRISED CONSTRUCTOR IS EVOKED BY PASSING THE VALUE AS 30 OF CLASS B
}
}
/**
*@author Shashi Jaiswal
*@use of method overloading is done
*/






Program for understanding difference between Static & non - Static variable

class Test {
public void show_non_static() {
int a = 6;
System.out.println(" non static " + a);
}
public static void Static_eg(int n1, int n2) {
System.out.println("The first parameter value is " + n1);
System.out.println("The second parameter value is " + n2);
}
public static void main(String args[]) {
Test n = new Test(); //creating object n for calling non static variable a
n.show_non_static();
Static_eg(5, 6);//calling of static does not need object creation
// n.Static_eg(5, 6); //static variable may be accessed by non static method i.e obj creation
}
}


output

non static 6
The first parameter value is 5
The second parameter value is 6


program to show constructor calling in multi-constructor

public class Multiconstructor  //to execute more than one const on creation of single object
{
public Multiconstructor(int args) //constructor having same class name and a return type
{
System.out.println("Called integer parameter: " + args);
}
public Multiconstructor(String arg) {
System.out.println("Called string parameter: " + arg);
}
public static void main(String args[]) {
Scanner define = new Scanner(System.in);
System.out.println("string parameter");
String s1 = define.nextLine();
System.out.println("integer parameter");
int s2 = define.nextInt();
Multiconstructor m1 = new Multiconstructor(s1); // constuuctor calling
Multiconstructor m2 = new Multiconstructor(s2);
}
}

OUTPUT

string parameter
shashi
integer parameter
7277
Called string parameter: shashi
Called integer parameter: 7277

SOME FUNCTIONS OF C

SOME FUNCTIONS of C
                                               ARITHMETIC FUNCTION
abs:- return absolute value of integer
fabs:-find absolute value of int
fmod:- break down string into int & fractional part
hypot(p,b):- return hypoteneous of triangle
DATA CONVERSION
atof:-String to float
atoi:-string to integer
atol:-string to long
ecvt ; gcvt ; fcvt:-double to string
itoa:- int to string
ltoa:-long to string
strtod:-string to decimal
strtoul:-string to unsigned long integer
 CHARACTER TESTING
TESTING FOR
isupper:- for upeercase
islower:- for lowercase
isspace:-containing space
isxdig:- for hexadecimal
isdigit:- for digit
isalnum:-is alphanumeric
tolower:- for lowercase if upper than convto lowercase
toupper:- for upeercase if lower than convto uppercase
                                        STRING MANIPULATION
strcat:- concat/append two string
strchr(str,'ch'):- find first occurance of given character in string
strcmp:-compare two string
strcpy(char*destination,const char*source):-copy the character form sourceto destination
strnicmp ;strcmpi ;stricmp:- copy without regard to case
strlen:-return length of string
strlwr , strupr:- convert string to lower & upper respectively
strrev:- reverse the string
strset:- set all string to given char destination
strstr:- find first occurance of string in a given string
strstr:- find first occurance of char ion given string
                                     SEARCHING & SORTING FUNCTION
bsearch:- binary search
lfind:- linear search
qsort:- quick sort
                                            I/O FUNCTION
close:- close of file
open :- open of file
eof:- reach end of file
feof:-check if eof is reached or not
printf:- print o/p
fprintf:- write to file the formatted data
sprintf:- print o/p in character of array
getch():- return value of char
getche()- echo value of char on screen
fgetchar():- read char from keyboard
fget:- read char from file
fgetc :-read char from file
fputc:- write char to file
fputchar:- write char to screen

Method Overloading

package method_overloading;
public class Method_Overloading {
void A() {
System.out.println("PQR, a method with no parameter ");
}
void A(int a) {
System.out.println("XYZ, a method with parameter :" + a);
}
public static void main(String[] args) {
Method_Overloading ob = new Method_Overloading(); //in meth_ovld 2 or more mthod has same name in a class with different argument
ob.A();
ob.A(5);
}
}
OUTPUT
PQR, a method with no parameter
XYZ, a method with parameter :5









Abstract class with abstract method

package pkgabstract.pkgclass;
abstract class A           //abstract class defined
{
abstract void callme(); // abstract method defined
void callmealsoo()
{
System.out.println("In non-abstract method but the class is abstract ");
}
}
class B extends A
{
void callme()
{
System.out.println("Abstract method call in inherited class B ");
}
}
public class AbstractClass
{
public static void main(String[] args)
{
B b = new B();
b.callme(); // calling abstract method
b.callmealsoo(); //calling method of abstract class
}
}

                        OUTPUT

Abstract method call in inherited class B
In non-abstract method but the class is abstract

METHOD OVERRIDING

package method_overriding;
class A
{
int i, j,k=7;
A() // no need to make this constructor if we have globally defined i and j
{
i = 5;
j = 6;
}
void meth() //use of super keyword return program counter to here
{
System.out.println("The values i ,j and k are : " + i + " " + j+" "+k);
}
}
class B extends A //inheritance is neceszsary for overriding/calling the method by use of super keyword
{
void metd1()
{
super.meth(); //to refer to superclass here A i.e, method overridden
System.out.println("After method overroiding we are here "); //after returning from super class
}
}
public class Method_overriding
{
public static void main(String args[])
{
B b = new B();
b.metd1();
}
}

                   OUTPUT
The values i ,j and k are : 5 6 7
After method overroiding we are here
















THIS keyword for variable hiding and in method

package this_keyword;
public class This_Keyword {
int c = 100;
void A() {
int c = 50;
System.out.println("accessing global variable" + this.c);
System.out.println("accessing local variable " + c);
}
void B(int c) // paramerised constructor
{
c = 25;
System.out.println("accessing global variable" + this.c);
System.out.println("accessing local variable " + c);
}
public static void main(String[] args) {
This_Keyword ob = new This_Keyword();
ob.A();
System.out.println("FOR PARAMETRISED CONSTRUCTOR");
ob.B(15);
}
}

                            OUTPUT 
accessing global variable100
accessing local variable 50
FOR PARAMETRISED CONSTRUCTOR
accessing global variable100
accessing local variable 25
***********************************************************************
package this_keyword;
public class This_Keyword {
int c = 100;
void A() {
int c = 50;
System.out.println("accessing global variable at A " + this.c);
System.out.println("accessing local variable at A " + c);
}
void B(int c) // paramerised constructor
{
this.A();
c = 25;
System.out.println("accessing global variable at B " + this.c);
System.out.println("accessing local variable at B " + c);
}
public static void main(String[] args) {
This_Keyword ob = new This_Keyword();
ob.B(15);
}
}



OUTPUT

accessing global variable at A 100
accessing local variable at A 50
accessing global variable at B 100
accessing local variable at B 25











THIS keyword for variable hiding and in method

package this_keyword;
public class This_Keyword {
int c = 100;
void A() {
int c = 50;
System.out.println("accessing global variable" + this.c);
System.out.println("accessing local variable " + c);
}
void B(int c) // paramerised constructor
{
c = 25;
System.out.println("accessing global variable" + this.c);
System.out.println("accessing local variable " + c);
}
public static void main(String[] args) {
This_Keyword ob = new This_Keyword();
ob.A();
System.out.println("FOR PARAMETRISED CONSTRUCTOR");
ob.B(15);
}
}

                            OUTPUT 
accessing global variable100
accessing local variable 50
FOR PARAMETRISED CONSTRUCTOR
accessing global variable100
accessing local variable 25
***********************************************************************
package this_keyword;
public class This_Keyword {
int c = 100;
void A() {
int c = 50;
System.out.println("accessing global variable at A " + this.c);
System.out.println("accessing local variable at A " + c);
}
void B(int c) // paramerised constructor
{
this.A();
c = 25;
System.out.println("accessing global variable at B " + this.c);
System.out.println("accessing local variable at B " + c);
}
public static void main(String[] args) {
This_Keyword ob = new This_Keyword();
ob.B(15);
}
}



OUTPUT

accessing global variable at A 100
accessing local variable at A 50
accessing global variable at B 100
accessing local variable at B 25











Swicth case with char and number

package char_switch_case;
import java.util.Scanner;
public class Char_Switch_Case {
private void number_case() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter number");
int num = sc.nextInt();
switch (num) {
case 1:
System.out.println("Number 1 is called ");
break;
case 2:
System.out.println("Number 2 is called ");
break;
default:
System.out.println("small example only for num 1 and 2");
}
}
private void char_case() {
Scanner sc1 = new Scanner(System.in);
System.out.println("Enter the character ");
String input_string = sc1.nextLine();
char input_char = input_string.charAt(0);
switch (input_char) {
case 'A':
System.out.println("Char a is called ");
break;
case 'B':
System.out.println("Char b is called ");
break;
default:
System.out.println("small example only for char a and b");
}
}
public static void main(String[] args) {
Char_Switch_Case ob = new Char_Switch_Case();
ob.number_case();
ob.char_case();
System.out.println("finally i am here after switch case");
}
}

                            OUTPUT
Enter number
1
Number 1 is called
Enter the character
A
Char a is called
finally i am here after switch case

Interface

package interface_class;
interface A {
void work1_Administration();
}
interface AB extends A {
void work2_Examination();
void work3_Class_Performance();
}
class secretary implements AB {
@Override                                                              //here we r overriding that method
public void work1_Administration() {
System.out.println(" Here work of administration is done & we have done that");
}
@Override
public void work2_Examination() {
System.out.println("Here work of Examination is done & we have done that");
}
@Override
public void work3_Class_Performance() {
System.out.println("Here class performance is analysed is done & we have done that");
}
}
public class Interface_class {
public static void main(String[] args) {
secretary ob = new secretary();
System.out.println("Give details of administration work");
ob.work1_Administration();
System.out.println("Give details of Examination work");
ob.work2_Examination();
System.out.println("Give details of class performance of all students");
ob.work3_Class_Performance();
}
}

               OUTPUT

Give details of administration work
Here work of administration is done & we have done that
Give details of Examination work
Here work of Examination is done & we have done that
Give details of class performance of all students
Here class performance is analysed is done & we have done that

                         EXPLANATION

In an interface, we use interface class, where methods are defined we can also make one or more interface classes to define method separately but that must be inherited by extend keyword.
After defining, we make a class (not the main class)
which need to inherit interface class by use of implement keyword where methods are doing their required work (here all methods need to be declared )
Now we make the main class (under whole project main class) and by making an object of the class(where methods doing work) we call all methods . This is an interface.

an example of goto function in can example of goto function in c

#include<conio.h>
#include<stdio.h>
int main( )
{
int x;
printf("enter x");
scanf("%d",&x);
if(x>5)
goto sj;
else
{printf("x is less or equal to than 5 so you r in a non goto location \n");
goto eof;
}
sj:
printf(" x>5 so you are in goto directed statement\n");
eof:
getch();
}

               OUTPUT

enter x
5
x is less or equal to than 5 so you r in a non goto location

program to call value by method through constructor

package account_balamce;
public class Balance {
int bal; //bal and name initialised
String name;
Balance(int b, String n) //creating constructor for calling the paameter in two step 1st here and then adding 5 and sending to method showBalance
{
bal = b + 5;
name = n;
}
void showBalance()
{
System.out.println("NAME OF ACCOUNT HOLDER IS: " + name);
System.out.println("THE BALANCE OF ACCOUNT HOLDER IS : " + bal);
}
}

MAIN CLASS

package account_balamce;
public class Account_Balamce {
public static void main(String args[]) {
System.out.print("Details are: ");
Balance b = new Balance(50, "RAHUL KUMAR");
b.showBalance(); // if u do not want to use constructor add parameter here and it will be
}
}

Difference between dynamic programming and divide and search

divide and search
divide problem into subpart and then solve subpart
e.g : quick sort , merge sort.
used in complex problem-solving
Dynamic programming
after dividing the problem into subpart greedy choose the sub part to solve to get optimized result
e.g : longest common subproblem, knapsack problem, matrix multiplication.
used in Optimisation of solution

Difference between call by value and call by reference

package multiconstructor;
import java.util.Scanner;
public class Multiconstructor {
public Multiconstructor(int args1, int args2)   //constructor having same class name and a return type
{
System.out.println("Sum of two no by call by reference " + (args1 + args2));
}
void call_by_value(int a, int b) {
int c = a + b;
System.out.println("Sum of two no by call by value " + c);
}
public static void main(String args[]) {
Scanner define = new Scanner(System.in);
System.out.println("integer parameter");
int s1 = define.nextInt();
int s2 = define.nextInt();
Multiconstructor m1 = new Multiconstructor(s1, s2);             // constuuctor calling so call by    reference
m1.call_by_value(s1, s2); // method calling so call by value
}
}


OUTPUT 
3
4
Sum of two no by call by reference 7
Sum of two no by call by value 7

BINARY SEARCH TREE

  • similar to a binary tree , it may be empty
  • every node (or element) has distinct key value
  • its left sub tree key value is less than root key value  and right sub tree key value is more than root key value
  • nodes are searched according to key value
  • during search key value is compared with root node if greater then searched along right sub tree, if key  value is less it is searched along  left sub tree, if key =zero then searching node is absent in tree.
  • The resulting left sub tree and right subtree is also a Binary search tree
  • Its time complexity is O(n)
  • during searching it follows recursive algorithm

PRIME NO BETWEEN ANY TWO GIVEN NUMBER

package prime.no.btwn.any.two.no;
import java.util.Scanner;
public class PrimeNoBtwnAnyTwoNo {
void prime_no_cll()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter 1st no");
int n1 = sc.nextInt();
System.out.println("Enter 2nd no");
int n2 = sc.nextInt();
int rem = 0;
if(n1>n2)                                         //swapping of digit in cace of descending order user input
{
int valuestorebox=0;
valuestorebox=n2;
n2=n1;
n1=valuestorebox;
System.out.println(" now n1 is : "+ n1 +"\n n2 is : "+ n2+" \nand temp value store box is : "+ valuestorebox);
}
for (int i = n1; i <= n2; i++)
{
int count = 0;
for (int j = 2; j < i; j++)
{
rem = (i % j);
if (rem == 0)
count = 1;
}
if (count == 0)
System.out.println("nmbr is prime" + i);
if (count == 1)
System.out.println("nmbr. is non-prime" + i);
}
}
public static void main(String[] args)
{
PrimeNoBtwnAnyTwoNo ob = new PrimeNoBtwnAnyTwoNo();
ob.prime_no_cll();
}
}
/** documentation comment
* 1st : check that you have to run loop from n1 to n2
* for prime number loop should run one less than the i
* caution : counter to be declare after for loop because we have to reset it every time
* if user enter larger number before for that apply if condition to swap the digit before only
*/

                 OUTPUT

Enter 1st no
2
Enter 2nd no
11
nmbr is prime2
nmbr is prime3
nmbr. is non-prime4
nmbr is prime5
nmbr. is non-prime6
nmbr is prime7
nmbr. is non-prime8
nmbr. is non-prime9
nmbr. is non-prime10
nmbr is prime11

PERFECT NUMBER

PERFECT NUMBER:-no which is sum of its proper divisor(proper divisor:- no which completely divide with no remainder)

package perfect_number;

import java.util.Scanner;
public class Perfect_number
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int number = sc.nextInt();
int sum = 0;
for (int i = 1; i < (number - 1); i++)
{
int divisorcheck = number % i;
if (divisorcheck == 0)
sum = sum + i;
}
if (sum == number)
System.out.println("perfect number : " + number);
else
System.out.println("non-perfect " + number);
}
}
/**documentation comment
* just make a loop before that input number and check for number divisibility by modulus operation with all succeeding number
* if modulus satisfies then sum all those satisfying no and compare with the given entered number
*/

                          OUTPUT

Enter the number
6
perfect number : 6

REGULAR EXPRESSION

  • an infinite set of the finite sequence defined over a language
  • analysis of the behaviour of string defined over the language
  • set of language accepted by  finite automata
  • it is a pattern which repeated itself over a definite sequence

PROPERTIES

  1. UNION :: L1UL2 is a regular language if L1 and L2 are regular
  2. CONCATENATION :: L1.L2 is a regular language if L1 and L2 are regular
  3. CLOSURE:: L* is a regular language.

AUTOMATA

  • A mathematical model of discrete sets of inputs and outputs
  • used for making machine .e.g:tuning machine, software, and hardware ,compiler design ...
TYPES(expressed in)
  • DFA/NFA( regular language)
  • LINEAR BOUND (context sensitive language)
  • TUNING MACHINE (recursive enumeric language)
  • PUSHDOWN AUTOMATA (context-free language)

ARDEN'S THEOREM

theorem to find R.E of any language
  • Let Pand Q be two R.E and P does not contain any null string
  • then R= Q+RP  has a unique solution that is :R=QP*

DFA/NFA

DFA (Deterministic Finite Automata)
  • every state must have a unique output for a specific input
  • must have  one initial and at least one final state
  •  transition function Q X ∑ →Q
NFA (Non-deterministic Finite Automata)
  • a state may not require a unique output for a specific input
  • its subsets  are in a power set
  • transition function Q X (∑ U {∈})→2Q
Both of these machines has 5 tuples
q0 : initial state
Q: finite set of state
F: final state
𝛿: transition function
∑: set of alphabets

PUMPING LEMMA


a  theorem to check whether a language is regular/ non-regular
##   let L be a regular language then there exist a constant n (length of string) which depend on L . such that for every string w in L , and |W|>=n
  • then we can break W into there substrings as W=XYZ such that
  • Y>=1
  • |XY|<=n
  • for all i>=0, XYiZ is also in L
## we require a necessary condition for a string to follow to be the regular language . This result is pumping lemma.

Floyd_Triangle


import java.util.Scanner;
lic class Floyd_Triangle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter no of row ");
int n = sc.nextInt();
System.out.println("The floyd triangle is :");
int a = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(a++);
}
System.out.println("");
}
}
}
/** DOCUMENTATION COMMENT
*Floyd triangle
* right angle triangle which is filled consecutive natural number starting with 1
* here we enter row no
* and the series is generated accordingly
* e.g  1
*         2 3
*         4 5 6
* and so on ...
*/

                                       OUTPUT

Enter no of row
4
The floyd triangle is :
1
23
456
78910

Difference between TCP/IP and OSI layer

TCP/IP layer

TCP (Transmission Control Protocol) is used for data delivery of packet.
IP(Internet Protocol) is used for logical addressing.
# consist of 4 layers
  • APPLICATION
  • TRANSPORT
  • INTERNET
  • NETWORK
# act as communication gateway between host and webserver

OSI layer

OSI(Open Standard Interface)
#consist of 7 layers
  • APPLICATION
  • PRESENTATION
  • SESSION
  • TRANSPORT
  • NETWORK
  • DATA LINK
  • PHYSICAL
#During transmission (at sender side) each layer add its header and at receiver side headers are removed respectively.
# also act as communication gateway between host and webserver

ERROR CORRECTION AND DETECTION in computer networks

  • PARITY CHECK:For even parity:if an even number of 1 is present then it is ok else add 1  to make an even number of 1 in the transmitting message.At the receiver side, an even number of 1 is checked if true then ok else error in the message is reflected.                     
  • CYCLIC REDUNDANCY CHECK: u will be given a generator function and a binary message . Count digit of generator function(let us say, n), add n-1 zero to the message and divide it.Add the remainder  to the binary message .This is your transmitted message .At the receiver side, it is transmitted message is divide with generator function and if remainder == zero then no error else error in  the message.
  • INTERNET CHECKSUM METHOD: Add numbers, convert to the binary, make a group of 4 and do module 2 operation . convert this remainder value to decimal and add it original decimal value. This is your transmitted message .At the receiver side , again do the same technique and at last take the 1's complement of the remainder.If it is all zero then no error else error in transmitting the message.

Showing Element of Matrix

import java.util.Scanner;
public class ShowingElementOfMatrix
{
void through_user_input()   //method one 
{
Scanner sc = new Scanner(System.in);
int a[][] = new int[2][2];
System.out.println("Enter the elements of matrix");
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
int n = sc.nextInt();
System.out.println("Element of Matrix at[" + i + "][" + j + "] is " + n);
}
}
}
void predefined_element()   //method second
{
int a[][] = {{2, 4}, {5, 6}};
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
System.out.println("Element of Matrix at[" + i + "][" + j + "] is " + a[i][j]);
}
}
}

void transpose_of_predefined_matrix()                    //method third
{
int a[][] = {{2, 4}, {5, 6}};
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
System.out.println("Element of Matrix at[" + i + "][" + j + "] is " + a[j][i]);
}}
}



public static void main(String[] args)
{
ShowingElementOfMatrix ob = new ShowingElementOfMatrix();
ob.through_user_input();
System.out.println("The value at predefined matrix are");
ob.predefined_element();
System.out.println("Transpose of predefined matrix is");
ob.transpose_of_predefined_matrix();
}
}

                                     OUTPUT

Enter the elements of matrix
2
Element of Matrix at[0][0] is 2
4
Element of Matrix at[0][1] is 4
5
Element of Matrix at[1][0] is 5
6
Element of Matrix at[1][1] is 6
The value at predefined matrix are
Element of Matrix at[0][0] is 2
Element of Matrix at[0][1] is 4
Element of Matrix at[1][0] is 5
Element of Matrix at[1][1] is 6

Transpose of predefined matrix is
Element of Matrix at[0][0] is 2
Element of Matrix at[0][1] is 5
Element of Matrix at[1][0] is 4
Element of Matrix at[1][1] is 6

How to install mongodb in windows

               STEPS

  1. install software from the official site
  2. in C drive ⇒programs files⇒mongoDB⇒server⇒3.2⇒bin⇒ (right place,lets say)
  3. at the right place, shift+right click⇒open command window here⇒mongod
  4. again go to' c drive' and make a new folder name it as 'data' :inside data ,make a new folder name it as 'db'
  5. now goto 'right place' and open command prompt⇒type mongo⇒it will show connecting to test:  ⇒type 'db' it will show 'test'
  6. set path of mongod   [  goto my computer⇒properties⇒advance system setting ⇒ environment variable⇒   system variable⇒path⇒edit that goto its end (without deleting earlier content) put a semicolon and paste the address of 'right place' {you would  click three times ok before complete exit} ]
  7. an important one:: now open command prompt different from the right place that is now through control panal ⇒type mongod⇒display message connection to port 27017.
  8. Download mongo chef
  9. open command prompts from control panal ⇒mongod
  10. inside mongo chef click connect⇒ enter name of connection ⇒connect.
  11. click on intel sell and write your query..
thank you

ARRAY DECLARATION IN PHP

<?php
$mongodb = array ('operations' => array('create','delete','drop') );
foreach($mongodb as $element => $inner_array )
{
echo '<br>'.$element.'<br>';
foreach($inner_array as $item)
{
echo '<br>'.$item.'<br>';
}
}
/** documentation commentS
array declaration in PHP is very simple
first, define a string after that declare an array  and keeps elements in that
now add inner array by using => sign
similarly, declare an inner array
for displaying them use for each function with two parameters
1st parameter string name
and 2nd as array name and then echo elements
inside array .
*/
?>

Php program to redirect any page

<?php ob_start();
?>
<h1>My Page</h1>
A page to show redirection to url.
<?php
$redirect_page = 'https://www.google.co.in/?gfe_rd=cr&ei=ScUQWPyYNIOHoAPMkaiYBA';
$redirect =true;
if($redirect == true)
{
header ('Location: '.$redirect_page );
}
ob_end_clean();
?>
/** php program for redirecting page to server
** use redirect keyword
** and if and else condition
** if true then redirect
**/

AUTOMATA:- CONTEXT FREE GRAMMER

CFG (Context Free Grammer)
It has 4 parameters
#Starting Symbols : Denotes first symbol of Grammer
#Set of Terminals : Represented by small letters they are alphabets or we can say end point of grammar
#Set of non-Terminals :Represented by capital letters they give rise to production.
#Production rules:  Rules which govern the Grammer.
There is two type of parsing done in this
*Left-most parsing: where evaluation of string starts from left side
*Right-most parsing: where evaluation of string starts from right side
$ if an equal string is obtained by any of the parsings(right/left) then that string is called ambiguous.
& to remove the ambiguity we do the following :
1. Removing useless symbols: any non-terminal which does not accompany terminal should be removed.
2. Removing unit Production: if non-terminal follow transition rule then middle should be removed.
3. Epsilon Transition: epsilon symbol should be replaced with the corresponding terminal symbol.
CNF(Chomsky Normal Form)
It has two rules
# A non-terminal can give rise to only one terminal.
# A non-terminal can give rise to two non-Terminals.

PHP :- Random number Generation

<?php
$rand = rand();
$max = getrandmax();
echo $rand.'/'.$max ;// to get random number with index
echo '<br>';
echo $rand ; // get random number
$rand1= rand(1,6);//to get random number between specified range
echo '<br>' ;
echo $rand1;
// code for form to respond
if (isset ($_POST['roll the dice'] ) ) //call name of input and display result
{
echo "you rolled a dice " .$rand;
}
?>
<form action ="Random number.php" method ="POST">
<input type = "submit" name =" roll the dice" value ="Roll dice">
</form>

PHP -Time and Date Function

<?php
$time = time();//display only seconds
$actual_time = date('h:i:s', $time ); //display time
echo 'the current time is '. $actual_time;
$actual_time = date('D M Y', $time );//displaying date
echo '<br>the current date is '. $actual_time;
?>

Some networking terms

DHCP (Dynamic host configuration protocol): It allocates IP address over the internet.
ICMP(Internet Control Messaging Protocol):  used by the router to send error message over the internet.
RIP (Routing Internet protocol): give routing count for traversal over nodes.
OSPF(Open Shortest Path First ) : Routing protocol to route data to shortest network first
DMA (Direct Memory Access): user to access information without the involvement of CPU e.g Graphics card .
IPV6 (Internet Protocol version 6) : 128-bit address;8-octet ; advanced version of IPV$4 to address more IP over the internet.
DVMRP(Distance Vector Multicast Routing Protocol) :  share information between routers to facilitate transportation of IP multicast packet among the network.
PIM (Protocol Independent Multicast ) : Provide one-to-one and many - to - many data distribution over the internet/LAN/WAN.
ATM(Asynchronous Transfer Mode): high-speed switching technology.
VLSM(Variable Length Subnet Masking) : getting a specific range of IP address, the length of the subnet is variable.



ARTIFICIAL INTELLIGENCE-Searches

                     UNINFORMED SEARCH


BREADTH FIRST SEARCH
#Search start from root: then   it search for all nodes at just immediate below node.And in similar fashion it goes till end node
#USE BACKTRACKING
#useful in finding shortest node between two node.
#queue implementation :FIFO(First In First Out)S
DEPTH FIRST SEARCH
#It uses some greeedy alogrithm in selecting next level node and after selecting the node it search till depth of the node. Again if it could not find the node it start from the next node and search till end of that node untill it finds the result.
#It is optimal when goal is known.
#Stack implementation :LIFO(Last In First Out)

                           INFORMED SEARCH

BEST FIT SEARCH
#Search by 1st selecting most promosing node and find solution as far as possible.
BRANCH AND BOUND SEARCH
#give feasible solution , it break the solution space and then bound them by using either Breadth first or Depth first search.

AUTOMATA

 PDA

#representation of non-regular language.
#extra data structure stack is added to keep the list of the top-most alphabet.Symbols are kept in LIFO(Last In First Out) manner.
#It can remember infinite amount of informattion.
#has triplet structure(states, alphabets, stack-symbol)

Context-free languages are closed under

*union
*concatenation
*closure & +closure
*homomorphism
*Reversal

Closure properties of Regular Language

# Union
# Intersection
# Concatenation
# Complement
# Difference
# Closure
# Reversal
# Homomorphism
# Inverse Homomorphism

Creating file using File handling Technique

import java.io.FileOutputStream;
public class FileHandling {
public static void main(String[] args) {
try {
FileOutputStream f= new FileOutputStream("Data.txt");
String i = "File written by using File Output Stream Class";
byte b []=i.getBytes();
f.write(b);
f.close();
} catch (Exception e) {
System.out.println("exception");
}
}
}
/**This is a program for creating any type of file using file handling technique.
*
* we make an object of file handling stream class where we specify which type of file we wish to create and
* we create that using their .extention name suffixed with the filename.
* here data.txt so a text file will be created.You may add extension of your wish.
* Don't forget to import FileOutputStream.
*/

Project Scheduling


Common terminology :

Early start- Early time in which an activity can start.
 Late start- Latest time by which an activity can start.
Early Finish- Earliest time in which an activity can finish.
Late finish- Latest time by which an activity can finish.
Optimistic Time: earliest time in which an activity can finish if no hurdles or complications arises.
Pessismistic TimeMaximum duration in which an activity can finish if any complications arises.
Most likely Time : Mid duration taken between Optimistic time and Pessismistic time.
Expected Complition Time: (optimistic time + (4*most likely time) + pessismistic time)/ 6
EOT(Early Occurance Time): Time in which event has been completed earliest.
Its computation procedure is refered to as FORWARD PASS.
LOT (Late Occurance Time) :Latest allowabletime in which an event can occur.
Computed by BACKWARD PASS: by moving in backward direction from end node.

PERT-(Project Evaluation and Review Technique)
# can determine slack
# time based analysis 
# can manage uncertain activites
#probalistic 
#focus on event
# suitable for research and development programs


CPM - (Critical path method)
# can't determine slack 
#cost based analasis
# can manage well defined activity
#deterministic
# focus on activity
# suitable for project like civil engineering project , ship project ...

# critical path is the longest path along with feasible time and the node appearing in the critical path are called critical node.

Typecasting in pointer

#include<conio.h>
#include<stdio.h>
main()
{
int a=1025;
int *p =&a;
printf("Addres of a = %d, and value of a =%d \n",p , *p );
printf("Addres of a+1 = %d, and value at a+1 =%d\n",(p+1) , *(p+1) );
char *p0; //char pointer initialiseed
p0=(char*)p; // char pointer typecasted to int
printf("the casted char pointer address =%d, and value = %d\n",p0,*p0 );
/** Generic pointer**/
void *p1; //generic pointer initialised
p1=p; //storing address of a
printf(" Address of a (with use of void pointer) = %d",p1 );
}

                      OUTPUT

Addres of a = 2686736, and value of a =1025
Addres of a+1 = 2686740, and value at a+1 =73
the casted char pointer address =2686736, and value = 1
Address of a (with use of void pointer) = 2686736

PATTERN IN C

#include<stdio.h>
#include<conio.h>
main()
{
int c=1;
for(int i= 1; i<=5; i++ )
{
for(int j =1; j<i; j++ )
{
printf("#");
}
for(int k=5;k>=c;k-- )
{
printf("*");
}c++;
printf("\n");
}
}

OUTPUT


*****
#****
##***
###**
####*

PATTERN IN C

#include<stdio.h>
#include<conio.h>
main()
{
int c=1;
for(int i= 1; i<=5; i++ )
{
for(int j =1; j<i; j++ )
{
printf("#");
}
for(int k=5;k>=c;k-- )
{
printf("*");
}c++;
printf("\n");
}
}

OUTPUT


*****
#****
##***
###**
####*

PATTERN IN C


#include<conio.h>
#include<stdio.h>
main()
{
int count =0;
for(int i=5; i>=1; i-- )
{
for(int j=(i-1); j>=1; j-- )
{
printf("#");
}
for(int k=0; k<=count; k++ )
{
printf("*");
}count=count+2;
printf("\n");
}
}

OUTPUT


####*
###***
##*****
#*******
*********

Difference between compiler and interpreter

Compiler
  • convert source (high level )language to Target language at a time
  • shows error after complete compilation
  • less time consuming if codes are smaller
  • space complexity is high
  • less efficient for a small program
  • execute conditional code statement and logical statement faster
  • generate intermediate object code for which it require more memory allocation
  • e.g C, C++, etc.


Interpreter
  • convert source (high level )language to Target language line by line
  • shows error during run time of each line and when error found it stop debugging
  • takes less time to analyze source code but overall processing is slow
  • memory efficient as it takes less memory
  • eg : python, ruby

Compiler Design

Cousins of compiler
  1. Preprocessor
  2. Assembler
  3. Linker/Loader
PHASES OF COMPILER DESIGN
  • LEXICAL PHASE 
  • SYNTAX PHASE 
  • SEMANTIC PHASE
  • INTERMEDIATE CODE GENERATOR
  • OPTIMISED CODE GENERATOR
  • TARGET CODE GENERATOR
RED COLOUR - FRONT END PHASE
BLUE COLOR - BACK END PHASE

LEXICAL ANALYSIS: valid tokens separation(lexeme) made(by removing white spaces from source program)
SYNTAX ANALYSIS: generating parse tree, symbol tree(parameter: position, type, constant/variable)
INTERMEDIATE CODE GENERATOR: creating temporary variable
OPTIMISED CODE GENERATOR: optimizing intermediate code
TARGET CODE GENERATOR: converting to assembly code

POINTER TO POINTER

#include<conio.h>
#include<stdio.h>
main()
{
int a=5;
int *p= &a;
printf("Simple pointer address = %d, and value =%d \n", p,*p );
int **q= &p;
printf("Pointer to Pointer address =%d, and value = %d \n",*q,*(*q) );
int ***r= &q;
printf("triple pointer address = %d, and value = %d" ,**r,*(*(*r)) );
}

OUTPUT



Simple pointer address = 2686744, and value =5
Pointer to Pointer address =2686744, and value = 5
triple pointer address = 2686744, and value = 5

Differernce beteween Top-Down Parser and Bottom-up Parser

Top Down Parser
  • expansion of parse tree
  • backtracking
  • use recursive descent parsing
  • follow LL parser
  • use leftmost derivation (token consumed from left to right)




Bottom-up Parser
  • reduction of a parse tree
  • no backtracking
  • use shift-reduce parsing
  • follow LR parser
  • use rightmost derivation(token consumed from right to left)

Lead and last in compiler design

lead

  • 1st element in RHS of production and the accompanying non-terminal(where non-terminal  end in terminal that symbol)
  • X-a
  • X-sH
  • H-e
  • here lead of X: a,s,e.
  • we only write terminal in lead of grammer.
  • here H was non terminal so its end terminal was taken


last


  • last element in RHS of production and the following non-terminal(where it end in terminal that symbol)
  • X-.....a
  • X-......sH
  • H-.....e
  • here last of X: a,s,e.
  • we only write terminal in last of  grammar.

left factoring in Compiler design

It is factoring out prefixes which are commom in two productions .
It is simillar to left recursion but here a factor of string is considered rather than single term.
S-iES/iESpq/a
E-b
After left factoring
S-iES'/a
S'-pq/episilion
E-b

Creating file using File handling Technique

import java.io.FileOutputStream;
public class FileHandling {
public static void main(String[] args) {
try {
FileOutputStream f= new FileOutputStream("Data.txt");
String i = "File written by using File Output Stream Class";
byte b []=i.getBytes();
f.write(b);
f.close();
} catch (Exception e) {
System.out.println("exception");
}
}
}
/**This is a program for creating any type of file using file handling technique.
*
* we make an object of file handling stream class where we specify which type of file we wish to create and
* we create that using their .extention name suffixed with the filename.
* here data.txt so a text file will be created.You may add extension of your wish.
* Don't forget to import FileOutputStream.
*/

Regular Expression Check (aa)*+(aaa)*

Regular Expression Check (aa)*+(aaa)*

package regularexpression.check;
import java.util.Scanner;
public class RegularExpressionCheck {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(“The R.E is (aa)*+(aaa)*”);
System.out.println(“Enter the string”);
String str = sc.nextLine();
System.out.println(“The condition for R.E is to have a in multiple of 2 or 3 or no a and no other symbol “);
int length = str.length();
int flag=0;
System.out.println(“length =” + length);
for (int i = 0; i < length; i++) {
if(str.charAt(i)!=’a’)
{
flag=1;
}
else
{ if(length%2==0||length%3==0||str.isEmpty())
{
flag=2;
}
else
{
flag=1;
}
}
}
if(flag==2||str.contains(“e”)|| str.isEmpty())
{
System.out.println(“RE ACCEPTED”);
}
else
{
System.out.println(“RE REJECTED”);
}

                                                        OUTPUT

The R.E is (aa)*+(aaa)*
Enter the string
The condition for R.E is to have a in multiple of 2 or 3 or no a and no other symbol
length =0
RE ACCEPTED             //since no char inserted


The R.E is (aa)*+(aaa)*
Enter the string
e
The condition for R.E is to have a in multiple of 2 or 3 or no a and no other symbol
length =1
RE ACCEPTED      //e represents epsilline


The R.E is (aa)*+(aaa)*
Enter the string
aaaaa
The condition for R.E is to have a in multiple of 2 or 3 or no a and no other symbol
length =5
RE REJECTED

Fibbonacci_No_Generation

package fibbonacci_no_generation;
import java.util.Scanner;
public class Fibbonacci_No_Generation {
public static void main(String[] args) {
int n1=0,n2=1,n3;
Scanner sc=new Scanner(System.in);
System.out.println("enter number of terms to get fibonacci series");
int count=sc.nextInt();
System.out.print("The numbers are "+n1 +","+n2);
for (int i = 2; i <count; i++) {
n3=n1+n2;
System.out.print(","+n3);
n1=n2;
n2=n3;
}
}
}

                                                        OUTPUT


enter number of terms to get fibonacci series
5
The numbers are 0,1,1,2,3

Regular expression check: a+b(a+b)*

package re_check_3;
import java.util.Scanner;
lic class Re_Check_3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("The R.E is a+b(a+b)*");
System.out.println("Enter the string");
String str = sc.nextLine();
System.out.println("The condition for R.E is to have either a or start with b ");
int length = str.length();
if (length == 1) {
if (str.charAt(0) == 'a' || str.charAt(0) == 'b') {
System.out.println("RE ACCEPTED");
} else {
System.out.println("RE REJECTED");
}
} else {
for (int i = 1; i < length; i++) {
if ((str.charAt(0) == 'b') && (str.charAt(i) == 'a' || str.charAt(i) == 'b')) {
System.out.println("RE ACCEPTED");
break;
} else {
System.out.println("RE REJECTED");
break;
}
}
}
}
}

                    OUTPUT

The R.E is a+b(a+b)*
Enter the string
baab
The condition for R.E is to have either a or start with b
RE ACCEPTED

RE CHECK :(1+01+001)*(e+0+00):of atmost two zeros

import java.util.Scanner;
public class E000 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter the string Satisfying RE:(1+01+001)*(e+0+00)");
String str=sc.nextLine();
int length=str.length();
int count=0,flag=0;
for (int i = 0; i < length; i++)
{
if(str.equals("e"))
{
System.out.println("empty string accepted");
return;
}
else if(str.charAt(i)!='0'&&str.charAt(i)!='1')
{
System.out.println("String does not contain binary digits");
return;
}
}
for (int j = 0; j < length; j++)
{
if (str.charAt(j)=='1')
{
flag=0;
}
else if(str.charAt(j)=='0')
{
flag++;
}
}
if(flag<3||str.contentEquals("e")||str.equals("0")||str.equals("00")||str.equals("1")||str.equals("01"))
{
System.out.println("String Accepted");
}
else
{
System.out.println("String Rejected");
}
}
}


                      OUTPUTS

Enter the string Satisfying RE:(1+01+001)*(e+0+00)
e
empty string accepted

Enter the string Satisfying RE:(1+01+001)*(e+0+00)
5
String does not contain binary digits

Enter the string Satisfying RE:(1+01+001)*(e+0+00)
100100
String Accepted

Enter the string Satisfying RE:(1+01+001)*(e+0+00)
100000
String Rejected

File Handling (creating file and reading it simultaneously)

package file_handling;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
class FileWrite{
public static void write()throws Exception{
FileWriter writer =new FileWriter("shahi.txt");
BufferedWriter bw=new BufferedWriter(writer);
try {
bw.write(" shashi is really a good boy");
bw.newLine();
bw.write("shashi will always be a good boy");
bw.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
class FileRead{
public static void read()throws Exception{
FileReader reader =new FileReader("shahi.txt");
BufferedReader br=new BufferedReader(reader);
String sj;
try {
while((sj=br.readLine())!=null)
{
System.out.println(sj);
}
} catch (Exception e) {
}
}
}
public class File_Handling {
public static void main(String[] args)throws Exception{
FileWrite.write();
FileRead.read();
}
}

                      OUTPUT

shashi is really a good boy
shashi will always be a good boy

CHECKING LEFT RECURSION IN JAVA

package leftrecursion;
import java.util.Scanner;
public class LeftRecursion {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.println("Enter number of production");
int prod=sc.nextInt();
String leftprod[]=new String[prod];
String rightprod[]= new String[prod];
int flag=0;
System.out.println("Enter Non-Teminals of left production");
for (int i = 0; i < prod; i++) {
leftprod[i]=sc.next();
}
System.out.println("Enter Non-Teminals/terminals of right production");
for (int i = 0; i < prod; i++) {
rightprod[i]=sc.next();
}
System.out.println("The productions are:");
for (int i = 0; i < prod; i++) {
System.out.println(""+leftprod[i]+"-->"+rightprod[i]);
}
for (int i = 0; i < leftprod.length; i++) {
for (int j = 0; j < rightprod.length; j++) {
if(leftprod[i].charAt(0)==rightprod[j].charAt(0))
{
flag=1;
}
}
}
if(flag==1)
{
System.out.println("left recursive");
}
else
System.out.println("non left recursive");

}
}


                            OUTPUT

Enter number of production
2
Enter Non-Teminals of left production
A
A
Enter Non-Teminals/terminals of right production
Ad
g
The productions are:
A-->Ad
A-->g
grammer left recursive

Pattern_Wise_Reverse_Of_String_In_Cmd

public class Pattern_Wise_Reverse_Of_String_In_Cmd
{
public static void main(String args[])
{
if(args.length==1)
{
String s=args[0];
for(int i=0;i<s.length();i++)
{
s =s.substring(1)+s.charAt(0);
System.out.println(s);
}
}
else
{
System.out.println("wrong no of input");
}
}
}
RIGHT NOW A STUDENT..

Pattern

class Pattern
{
public static void main(String args[])
{int n=5,z=1;
for(int i=1;i<=n;i++)
{
for(int j=(n-1);j>=i;j--)
{
System.out.print(" ");
}
for(int k=1;k<=z; k++)
{
System.out.print("*");
}
z++;
System.out.print("\n");
}
}
}
/* output
*
**
***
****
*****
*/

Matrix_Multiplication_Two_Dimentional

class Matrix_Multiplication_Two_Dimentional
{
public static void main (String args[])
{
int a [][]= {{1,2},{1,1}};
int b [][]= {{2,3},{3,3}};
int c [][]= new int[4][4];
int sum;
for(int i=0; i<a.length; i++)
{
for (int j =0; j<b.length; j++)
{
sum=0;
for (int k=0;k<2;k++)
{
sum+= (a[i][k]*b[k][j]); //initially i.k=0 i.e, at 1 and it is multiplied to k,i=0 i.e, 9 so 1*9=9 amd so ..
}
c[i][j]=sum;
System.out.println(" "+c[i][j]);
}
}
}
}
/* an overview
[1,2] * [2,3] =[8,9]
[1,1] * [3,3] =[5,6]
A B C
*/

Pattern1-5-1

class Pattern1-5-1
{
public static void main(String args[])
{
for (int i = 5; i>=1;i--)
{
for(int j = 1; j<=i;j++)
{
System.out.print(j);
}
System.out.print("\n");
}
}
}

Simple_interest_in_cmd_line_argument

class Simple_interest_in_cmd_line_argument
{
public static void main(String args[])
{
{
if (args.length==3)
{
int p =Integer.parseInt(args[0]);
int r =Integer.parseInt(args[1]);
int t =Integer.parseInt(args[2]);
float i = (p*r*t)/100;
System.out.println(i);
}
else{
System.out.println("wrong input");
}
}
}
}

Stringhandling in java

class Stringhandling {
public static void main(String args[])
{
String s ="I LOVE LOVE";
System.out.println(s);//DISPLY THE STRING
System.out.println(s.length());// DISPLAY NO. OF CHAR
System.out.println(s.toUpperCase());//CONVERSION TO CAPITAL LETTERS
System.out.println(s.toLowerCase());//CONVERSION TO SMALLER LETTERS
System.out.println(s.startsWith("i"));//CHECKING STRING WHERTHER IT START WITH I OR NOT(CASE SENSITIVE)
System.out.println(s.endsWith("I"));//CHECK STRING END WITH I OR NT CASE-SENSITIVE
System.out.println(s.replace('O','h'));//REPLACE 'O' TO 'h' (CASE -SENSITIVE)
System.out.println(s.trim());//REMOVE UNUSED SPACES FROM CORNER
System.out.println(s.indexOf('O'));//DISPLAY POSITION OF CHARACTER FROM BEGINNING
System.out.println(s.lastIndexOf('O'));//DISPLAY POSITION OF CHARACTER FROM BEGINNING & IF CHAR NOT PRESENT THEN ANS= -1.
System.out.println(s.charAt(7));//DISPLAY CHAR WHICH IS AT 7th POSITION FROM BEGINNING
System.out.println(s.substring(2));// DISPLAY CHARACTER FROM 2nd POSITION TO LAST
System.out.println(s.substring(2,7));//DISPLAY CHARACTER FROM 2nd position to 7th where counting start from zero position(ANS LOVE)
String s2 ="I LOVE love";
System.out.println(s.startsWith(s2));// CHECK FROM BEGINNING TO END THE MATCH OF EACH WORD (here ans false 'coz case does not match)
System.out.println(s.equals(s2));//COMPARE ALL CHARACTER (CASE SENSITIVE)
System.out.println(s.equalsIgnoreCase(s2));// COMPARE BUT NOT CASE-SENSITIVE
}
}

While_Use_for_generating_Table_Of_2

class While_Use_Table_Of_2
{
public static void main(String args[])
{
int i=0;
while(i<20)
{
i=i+2;
System.out.println(i);
}
}
}
/**@first initialisation
**@use of while condition
**@ need curly braces
**@ w small letter
*/

Program to find factorial of any no

import java.util.Scanner;
public class factorial_of_any_no
{
public static void main(String args[])
{
int fa=1;
Scanner sc =new Scanner(System.in);
System.out.println("enter the no");
int n=sc.nextInt();
if(n<0)
System.out.println("not defined");
else
{
for(int i=1;i<=n;i++)
{
fa=fa*i;
}
System.out.println(fa);
}
}
}

Another method

import java.util.Scanner;
class Factorial_In_Dec_Way
{
public static void main (String args[])
{
Scanner define =new Scanner(System.in);
System.out.println("enter the no for factorial");
int f = define.nextInt();
if(f<0)
{
System.out.println("not defined");
}
else
{
for (int i=(f-1); i>=1; i--)                        //recuursion with function call
{
f=f*i;
}
System.out.println(f);
}
}
}

Array_wise_display_of_alphabates

class Array_wise_display_of_alphabates
{
public static void main(String args[])
{
try
{
String s= args[0];
for(int i=0;i<s.length();i++)
{
System.out.println(s.charAt(i));
}
}
catch(Exception e)
{
System.out.println("catch little little ");
}
}
}

Circle_Menu_driven_function

import java.util.Scanner;
public class Circle_Menu_driven_function
{
public static void main(String args[])
{
Scanner scanner = new Scanner(System.in);
double sum,d;
double div,pd;
System.out.println("enter radius");
int a =scanner.nextInt();
System.out.println("what you want to calculate \n1 diameter \n2 area \n3 circumference \n4 exit ");
int abs=scanner.nextInt();
if(abs==1)
{sum =(2*a);
System.out.println(+sum);
}
else if(abs==2)
{d=(3.14*a*a);
System.out.println(+d);
}
else if(abs==3)
{
pd=(3.14*a*2);
System.out.println(+pd);
}
else if(abs==4)
System.out.close();
else
System.out.println("choose right option");
}
}

Command line Check_Of_Two_Entered_String

class Cmd_Check_Of_Two_Entered_String
{
public static void main(String args[])
{
if(args.length==2)
{
String s1=args[0];
String s2=args[1];
if(s1.equals(s2))
{
System.out.println("both string are equal");
}
else
{
System.out.println("both string unequal");
}
}
else
{
System.out.println("wrong no of input");
}
}
}

Matrix_Substration_Two_Dimensions

class Matrix_Substration_Two_Dimensions
{
public static void main (String args[])
{
int a [][]= {{1,2},{4,4}};
int b [][]= {{9,2},{5,6}};
int c [][]= new int[4][4];
for(int i=0; i<2; i++)
{
for (int j =0; j<2; j++)
{
c[i][j]= (a[i][j]-b[i][j]);
System.out.println(c[i][j]);
}
}
}
}

Method_Call_Example_Min_Of_Two_No

class Method_Call_Example_Min_Of_Two_No
{
public static int Min(int a , int b)
{
int Min;
if (a>b)
Min=b;
else
Min=a;
return Min;
}
public static void main (String args[])
{
int a = 5;
int b =6;
int c= Min(a,b);
System.out.println(c);
}
}
/**
**@ int - is used because it return a value i.e Min (a no )
**@ void - is used when it does not return any value but only statement
*/

How to set path of java compiler in C drive of computer!




Steps to set path of JDK  are

1. open bin folder under javaJDKk folder
2 click on address bar to copy the path
3 Right,click on my computer :  open  "properties" go to  "advance system setting" then to "advance" menu then "Environment variables".
4 There u will find "User variable for (your computer name)" and below three buttons new,edit&delete.
5 click new

Variable name : path
variable value : the path  of the bin location which you copied

*three times you have to press ok to exit.

Aggressiveness in life

Aggressiveness is best for you if u could handle it properly.
The idea I want to share is if you r aggressive and you could not control your temper and could not realize where u r taking your mind too then it can be very destructive for u.
U will suffer a lot as you will be losing both the time and work effort. But on their hand, if u  are aggressive and you know how to keep yourself in a balanced way so then its result  can be much fruitful for u that u can ever imagine

With time u may slow down but again after some time, you could start with more zeal than before in your work.
That's the concept behind aggressiveness i.e., combining the perseverance in it.
And remember it had no limit today with which enthusiasm u are working tomorrow u can work with more better than that. Just have had patience and put more enthusiasm in your life. That's the most amazing way of living life.
thank you.