Showing posts with label Pranathi. Show all posts
Showing posts with label Pranathi. Show all posts

Sunday, 24 September 2017

Multi-threaded application oops lab program number four

Hi all.Today we are going to create a multithreaded application which will perform the following tasks:
1.First Thread generates random integer every 1 second--(value may be even or odd)

2.Second thread computes the square  of the number and prints--(value of first thread is even)

3.Third thread will print the value of cube of number--(value of first thread is odd)

In order to create this application, we require Netbeans IDE.

Follow below steps to create it.

1.Open NetbeansIDE
2.Go to File menu --->NewProject
3.Select Java Application 
4.Give it appropriate name according to your requirement
5.Click Next and your new project gets created with the main class whose name is same as your project
6.If you are not in need of the same name for your class refactor it and give the different name for your java class. 


In main class, you have to create Object for class A and start its thread.In class A we have thread name, Random class variable, and two thread class variables.
The java.util.Random class instance is used to generate a stream of pseudorandom numbers
Random(): This creates a new random number generator.
The nextInt(int n) method is used to get a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.


Based on the generated random number, and using the following condition we can find whether it is odd or even and perform action accordingly:

if (num % 2 == 0) {
t1 = new Thread(new even(num));
t1.start();
} else {
t2 = new Thread(new odd(num));
t2.start();
}

In even class, we are going to compute the square of the number and in the odd class cube of the number.


The output in Netbeans console is as follows:

Main Thread and Generated Number is 47
Thread Name: ODD Thread and 47 is odd number and Cube of 47 is: 103823
--------------------------------------
Main Thread and Generated Number is 81
Thread Name: ODD Thread and 81 is odd number and Cube of 81 is: 531441
--------------------------------------
Main Thread and Generated Number is 41
Thread Name: ODD Thread and 41 is odd number and Cube of 41 is: 68921
--------------------------------------
Main Thread and Generated Number is 14
Thread Name: Even Thread and 14is even Number and Square of 14 is: 196
--------------------------------------
Main Thread and Generated Number is 35
Thread Name: ODD Thread and 35 is odd number and Cube of 35 is: 42875
--------------------------------------
Main Thread and Generated Number is 12
Thread Name: Even Thread and 12is even Number and Square of 12 is: 144
--------------------------------------
Main Thread and Generated Number is 31
Thread Name: ODD Thread and 31 is odd number and Cube of 31 is: 29791
--------------------------------------
Main Thread and Generated Number is 0
Thread Name: Even Thread and 0is even Number and Square of 0 is: 0
--------------------------------------
Main Thread and Generated Number is 25
Thread Name: ODD Thread and 25 is odd number and Cube of 25 is: 15625
--------------------------------------
Main Thread and Generated Number is 72
Thread Name: Even Thread and 72is even Number and Square of 72 is: 5184
--------------------------------------
Main Thread and Generated Number is 28
Thread Name: Even Thread and 28is even Number and Square of 28 is: 784
--------------------------------------
Main Thread and Generated Number is 50
Thread Name: Even Thread and 50is even Number and Square of 50 is: 2500
--------------------------------------
Main Thread and Generated Number is 55
Thread Name: ODD Thread and 55 is odd number and Cube of 55 is: 166375
--------------------------------------
Main Thread and Generated Number is 9
Thread Name: ODD Thread and 9 is odd number and Cube of 9 is: 729
--------------------------------------
Main Thread and Generated Number is 49
Thread Name: ODD Thread and 49 is odd number and Cube of 49 is: 117649
--------------------------------------
Main Thread and Generated Number is 33
Thread Name: ODD Thread and 33 is odd number and Cube of 33 is: 35937
--------------------------------------
Main Thread and Generated Number is 22
Thread Name: Even Thread and 22is even Number and Square of 22 is: 484
--------------------------------------
Main Thread and Generated Number is 37
Thread Name: ODD Thread and 37 is odd number and Cube of 37 is: 50653
--------------------------------------
Main Thread and Generated Number is 10
Thread Name: Even Thread and 10is even Number and Square of 10 is: 100
--------------------------------------
Main Thread and Generated Number is 85
Thread Name: ODD Thread and 85 is odd number and Cube of 85 is: 614125
--------------------------------------
Main Thread and Generated Number is 99
Thread Name: ODD Thread and 99 is odd number and Cube of 99 is: 970299
--------------------------------------
Main Thread and Generated Number is 58
Thread Name: Even Thread and 58is even Number and Square of 58 is: 3364
--------------------------------------
Main Thread and Generated Number is 78
Thread Name: Even Thread and 78is even Number and Square of 78 is: 6084
--------------------------------------
Main Thread and Generated Number is 1
Thread Name: ODD Thread and 1 is odd number and Cube of 1 is: 1
--------------------------------------
Main Thread and Generated Number is 39
Thread Name: ODD Thread and 39 is odd number and Cube of 39 is: 59319
--------------------------------------
Main Thread and Generated Number is 66
Thread Name: Even Thread and 66is even Number and Square of 66 is: 4356
--------------------------------------
Main Thread and Generated Number is 22
Thread Name: Even Thread and 22is even Number and Square of 22 is: 484
--------------------------------------
Main Thread and Generated Number is 93
Thread Name: ODD Thread and 93 is odd number and Cube of 93 is: 804357
--------------------------------------
Main Thread and Generated Number is 4
Thread Name: Even Thread and 4is even Number and Square of 4 is: 16
--------------------------------------
Main Thread and Generated Number is 41
Thread Name: ODD Thread and 41 is odd number and Cube of 41 is: 68921
--------------------------------------
Main Thread and Generated Number is 58
Thread Name: Even Thread and 58is even Number and Square of 58 is: 3364
--------------------------------------
Main Thread and Generated Number is 77
Thread Name: ODD Thread and 77 is odd number and Cube of 77 is: 456533
--------------------------------------
Main Thread and Generated Number is 60
Thread Name: Even Thread and 60is even Number and Square of 60 is: 3600
--------------------------------------
Main Thread and Generated Number is 4
Thread Name: Even Thread and 4is even Number and Square of 4 is: 16
--------------------------------------
Main Thread and Generated Number is 8
Thread Name: Even Thread and 8is even Number and Square of 8 is: 64
--------------------------------------
Main Thread and Generated Number is 25
Thread Name: ODD Thread and 25 is odd number and Cube of 25 is: 15625
--------------------------------------
Main Thread and Generated Number is 47
Thread Name: ODD Thread and 47 is odd number and Cube of 47 is: 103823
--------------------------------------
Main Thread and Generated Number is 53
Thread Name: ODD Thread and 53 is odd number and Cube of 53 is: 148877
--------------------------------------
Main Thread and Generated Number is 25
Thread Name: ODD Thread and 25 is odd number and Cube of 25 is: 15625
--------------------------------------
Main Thread and Generated Number is 58
Thread Name: Even Thread and 58is even Number and Square of 58 is: 3364
--------------------------------------
Main Thread and Generated Number is 75
Thread Name: ODD Thread and 75 is odd number and Cube of 75 is: 421875
--------------------------------------
Main Thread and Generated Number is 36
Thread Name: Even Thread and 36is even Number and Square of 36 is: 1296
--------------------------------------
Main Thread and Generated Number is 20
Thread Name:Even Thread and 20is even Number and Square of 20 is: 400
--------------------------------------
Main Thread and Generated Number is 27
Thread Name:ODD Thread and 27 is odd number and Cube of 27 is: 19683
--------------------------------------
Main Thread and Generated Number is 16
Thread Name:Even Thread and 16is even Number and Square of 16 is: 256
--------------------------------------
Main Thread and Generated Number is 57
Thread Name:ODD Thread and 57 is odd number and Cube of 57 is: 185193
--------------------------------------
Main Thread and Generated Number is 35
Thread Name:ODD Thread and 35 is odd number and Cube of 35 is: 42875
--------------------------------------
Main Thread and Generated Number is 80
Thread Name:Even Thread and 80is even Number and Square of 80 is: 6400
--------------------------------------
Main Thread and Generated Number is 54
Thread Name:Even Thread and 54is even Number and Square of 54 is: 2916
--------------------------------------
Main Thread and Generated Number is 63
Thread Name:ODD Thread and 63 is odd number and Cube of 63 is: 250047
--------------------------------------
BUILD SUCCESSFUL (total time: 50 seconds)


Sunday, 3 September 2017

How to compile and run from EditPlus



EditPlus is a Windows text editor with built-in FTP (also FTPS) and sftp capabilities. While it can serve as a good Notepad replacement, it also offers many powerful features for Web page authors and programmers.

Syntax highlighting for HTMLPHPJavaC/C++CSSASPPerlJavaScriptVBScriptPython and Ruby on Rails. Also, it can be extended for other programming languages based on custom syntax files.
Seamless Web browser for previewing HTML pages, and FTP (also sftp and FTPS) feature for uploading local files to FTP server.

After installation

1.Go to Tools Configure Tools 

2.Then Click on Add Tool then click on Program 

 3) Write the menu text-->compiler, commands-->path to your bin.exe, arguments--> filename for compilation and initial directory.

4.Add one more tool to run your java programs with the following arguments shown in picture below.





5.Inorder to test the tools create a new java file as shown below

6. go to tools to see the newly added user defined tools with their shortcuts


7. To compile your code press ctrl+1 and to run press ctrl+2



Once you run the code output is automatically shown on command prompt.


Monday, 10 April 2017

calculator database using php

Hi all this post explains implementation of calculator database in php
you are required to write the following set of instructions here.


<TITLE>PHP Calculator v1</TITLE>
<form name="calc" action="?page=calc" method="POST"> <!--implementing pagination with the page name appended to url -->
Number 1: <input type=text name=value1><br>
Number 2: <input type=text name=value2><br>
Operation: <input type="submit" name=oper value="add"/> <input type="submit" name=oper value="subtract"/>
<input type="submit" name=oper value="divide"/> <input type="submit" name=oper value="multiply"/><br>
</form>

<?php
if($_SERVER['REQUEST_METHOD'] === 'POST')//checking if the form method is post
{
$page = $_GET['page'];  
// Defining the "calc" class
class calc {
var $number1;  //variable declaration
var $number2;  
function add($number1,$number2)  {
$con=db();       //creating connection variable            
$result =$number1 + $number2;
echo("The sum of $number1 and $number2 is $result<br><br>");
echo("$number1 + $number2 = $result");
mysqli_query($con,"insert into plus values('$number1 + $number2',$result)");
exit;            
}  
function subtract($number1,$number2)  {
$con=db();                  
$result =$number1 - $number2;
echo("The difference of $number1 and $number2 is $result<br><br>");
echo("$number1 &#045 $number2 = $result");
mysqli_query($con,"insert into plus values('$number1 - $number2',$result)");
exit;          
 }  
function divide($number1,$number2)  {
$con=db();                  
$result =$number1 / $number2;
echo("$number1 divided by $number2 is $result<br><br>");
echo("$number1 &divide $number2 = $result");
mysqli_query($con,"insert into plus values('$number1 / $number2',$result)");
exit;          
 }  
function multiply($number1,$number2)  {
$con=db();                  
$result =$number1 * $number2;
echo("The product of $number1 and $number2 is $result<br><br>");
echo("$number1 x $number2 = $result");
mysqli_query($con,"insert into plus values('$number1 * $number2',$result)");
exit;            
}
}
$calc = new calc();
 ?>

<?php
if($page == "calc"){
$n1 = $_POST['value1'];
$n2 = $_POST['value2'];
$number1=abs(ltrim($n1,''));
$number2=abs(ltrim($n2,''));
$oper = $_POST['oper'];
function db () {
static $con;
if ($con===NULL){        
$con = mysqli_connect ("localhost", "root", "", "plus");
     }
return $con;
 }
if(!$number1){
echo("You must enter number 1!");
exit;    
 }
if(!$number2){
echo("You must enter number 2!");
exit;      
}
if(!$oper){
echo("You must select an operation to do with the numbers!");
exit;      
}
if(!preg_match("/[0-9]/", $number1)){
echo("Number 1 MUST be numbers!");
exit;      
}
if(!preg_match("/[0-9]/", $number2)){
echo("Number 2 MUST be numbers!");
exit;      
}
if($oper == "add"){          
$con=db();
$query = mysqli_query($con,"SELECT * FROM plus WHERE exp='$number1 + $number2'");
if (!$query) {
        echo 'MySQL Error: ' . mysqli_error();
        exit;
    }
$numrows = mysqli_num_rows($query);
if ($numrows == 0) {
$calc->add($number1,$number2);
      }

}
if($oper == "subtract"){
$con=db();
$query = mysqli_query($con,"SELECT * FROM plus WHERE exp='$number1 - $number2'");
$numrows = mysqli_num_rows($query);
if ($numrows == 0) {        
$calc->subtract($number1,$number2);
      } }
if($oper == "divide"){
$con=db();
$query = mysqli_query($con,"SELECT * FROM plus WHERE exp='$number1 / $number2'");
$numrows = mysqli_num_rows($query);
if ($numrows == 0) {  
          $calc->divide($number1,$number2);    
 }
}
 if($oper == "multiply"){
$con=db();
$query = mysqli_query($con,"SELECT * FROM plus WHERE exp='$number1 * $number2'");
$numrows = mysqli_num_rows($query);
if ($numrows == 0) {  
          $calc->multiply($number1,$number2);       } }
while ($row = mysqli_fetch_assoc($query)) {
print("Accessed from database.......<br>");
print($row['exp'] . " = " . $row['res']);
 }    
}
}
?>











Tuesday, 4 April 2017

Authenticating User Details from xml file using Java Server Pages

Our main aim is to authenticate user details from xml file.Now this xml file can be normal one or u can take web.xml for implementation also.

I will explain u both the ways one after the other

1.Normal XML file using Document Builder

The folder structure for this jsp program is as follows:

This is the xml file which we have to use:



Below you can find the index.html file which accepts username and password:


This is the jsp file xret.jsp where the actual logic is specified:



These are the output screens cross check with xml file:










2)Using InitParam in web.xml





The output for this is as follows:








Sunday, 26 March 2017

Java Script programs on displaying country's capital

Write an HTML page that contains a selection box with a list of 5 countries. When the user selects a country, its capital should be printed next to the list. Add CSS to customize the properties of the font of the capital (color, bold and font size).  


As we all know Javascript can change HTML content.One of javascript HTML method is getElementById()
This example uses the method to "find" an HTML element (with id="txtSelectedCapital") and changes the element content (innerHTML) to "selectedValue":




dropDown.options[dropDown.selectedIndex].value;
This line allows us to select the drop down list value based on the index and store it in some variable for displaying in the browser.

Thursday, 2 March 2017

jsp programs of wtlab

Following should be the directory structure that is always followed for implementing jsp applications.

In Tomcat web-apps folder you have to create your own respective folder for jsp implementation.

Sessions implementation using jsp:It requires following three files:
                                                             1.login.jsp
                                                              2.home.jsp
                                                              3.logout.jsp




The output of above program is






 Age validation implementation using jsp:



The output of above program is


Calculator implementation in jsp


The above programs output is as follows: