Showing posts with label Shanoor Afreen. Show all posts
Showing posts with label Shanoor Afreen. Show all posts

Friday, 24 November 2017

Execute PHP Code From EditPlus




EditPlus is the best editor for writing any program.Mostly we use it for Java programs.In my previous post, I have shown How to Execute Java from EditPlus.

Today I will explain PHP execution from EditPlus:

Goto Command Prompt and move to www folder of WAMP server

Once enter key is pressed EditPlus will popup with a dialog box asking for confirmation.Click Yes
.Go to Tools Menu in Edit Plus and Click Configure User Tools.The following screen is displayed.



To Add a Tool click Add Tool ->Program-->Give a proper name under Menu text.Then Browse for PHP interpreter.

 Select FilePath for Argument and FileDir for Initial Directory and In Actions: opt for Capture output.
\

Click OK.Now Type small PHP script.



Go To Tools and Click on New Shortcut created with the menu text:




After Running the PHP script we can view the output in the output window.

Friday, 29 September 2017

inter thread communication to resolve producer-consumer problem



Producer-Consumer Problem:
This problem arises if there is no communication between producer and consumer thread.
1.producer will produce the item which leads to buffer overflow.
2.consumer will try to consume the item until buffer underflow arises.
To avoid these issues and utilize cpu time efficiently we are going to use wait(),notify(),notifyAll():

  • final void wait( ) throws InterruptedException
  • wait( ) tells the calling thread to give up the monitor and go to sleep until some other thread enters the same monitor and calls notify( ) or notifyAll( ).
  • final void notify( )
  • notify( ) wakes up a thread that called wait( ) on the same object.
  • final void notify All( ) 
  • notifyAll( ) wakes up all the threads that called wait( ) on the same object. One of the threads will be granted access.
       Following program illustrates the same scenario

Main class which creates object for other classes

Consumer thread

                 producer thread
Queue /Buffer class with get() and put()


The output of program when its executed is as follows:


The following program keeps on producing the output unless we press ctrl-c.As we dont have any restriction on buffer.

   


       

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)


Monday, 14 August 2017

Netbeans installation

NetBeans IDE is the official IDE for Java 8. With its editors, code analyzers, and converters, you can quickly and smoothly upgrade your applications to use new Java 8 language constructs, such as lambdas, functional operations, and method references.
Batch analyzers and converters are provided to search through multiple applications at the same time, matching patterns for conversion to new Java 8 language constructs.
With its constantly improving Java Editor, many rich features and an extensive range of tools, templates and samples, NetBeans IDE sets the standard for developing with cutting edge technologies out of the box.

Download Netbeans IDE 8.2




Once the exe file gets downloaded double click on it to proceed with installation

Accept the license agreement and then click next


Specify the location of jdk and the drive where you want to install netbeans.By default it takes C drive as location

Specify the location to install Glassfish server

Oracle GlassFish Server

Oracle GlassFish Server is the world's first implementation of the Java Platform, Enterprise Edition (Java EE) 6 specification.  Built using the GlassFish Server Open Source Edition, Oracle GlassFish Server delivers a flexible, lightweight, and production-ready Java EE 6 application server.
















To run the program right click on java application project and click run.You can see the output in Output screen