Servlets - Factorial Calculation

FormFact.html

<!-- Servlet, form data and validation -->

 

<html>

<head>

         <title> Forms, servlet and factorial</title>

         <style>

                  h3{text-align:center}

         </style>

         <script type="text/javascript" language="javascript">

 

                  function fnvalidate()

                  {

                           // User Name Validation

                           var Num = document.FN.f1.value;

                           if (Num.toString().trim().length==0)

                           {

                                    alert( "Error...Enter number" );

                                    document.FN.f1.focus() ;

                                    return false;

                           }

                          

            if( isNaN(Num))

            {                  

                                    alert( "Invalid Number! Should have only digits." );

                                    document.FN.f1.focus() ;

                                    return false;

                           }

                            

                           return true;

                  }

         </script>                

</head>

<body>

         <br/><h3> Factorial Calculator </h3><br/><br/>

         <center>

         <form name="FN" method="get" action="http://localhost:8088/WT/FactCalc" onsubmit="return fnvalidate();">

        

                  <label> Enter Number : </label>

                  <input type="text" name="f1" />

                  <br/><br/>

                  <input type="submit" />

                  <input type="reset" />

                 

         </form>

</html>                         

 

 


 

FactCalc.java

 

import java.io.*; 

import javax.servlet.*; 

import javax.servlet.http.*;

 

public class FactCalc extends HttpServlet

{

         int N;

         public void init(ServletConfig sc)

         {

         }

        

         public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException

         {

                  res.setContentType("text/html");

                  PrintWriter pw = res.getWriter();

                                   

                  N = Integer.parseInt(req.getParameter("f1"));

                  int fact=1;

                  for(int i=1;i<=N;i++)

                           fact=fact*i;

                 

                  pw.println("<html><body><center>");

                  pw.println("<h3>");

                  pw.println("Factorial of "+N +" is "+fact);         

                  pw.println("</h3>");

                  pw.println("</center></body></html>");

                                   

                  pw.close();

         }

        

         public void destroy()

         {

         }

}


Thread Synchronization in C#

 Thread Synchronization in C#



using System;

using System.Collections;

using System.Numerics;

using System.Threading;

using System.Threading.Tasks;


namespace CSharp

{

    public class Q

    {

    Queue q = new Queue();


        public void put(int n)

        {

            lock (this)

            {

                while(q.Count==1)

                {

                    Monitor.Wait(this);

                }

                q.Enqueue(n);            

                Monitor.Pulse(this);

            }

        }


        public int get()

        {

            lock (this)

            {

                while (q.Count==0)

                {                

                    Monitor.Wait(this);

                }

                int n = (int)q.Dequeue();

                Monitor.Pulse(this);

                return n;

            }

        }

    }


    public class Consumer 

    {

        Q q;


        public Consumer(Q q)

        {

            this.q = q;

            new Thread(new ThreadStart(this.Consume)).Start();

        }



        public void Consume()

        {

            for (int i=1; i <= 5; i++)

            {

                int n = q.get();

                Console.WriteLine ("Consuming {0}", n);

                Thread.Sleep(200);

            }

        }

    }

    

    public class Producer 

    {

        Q q;


        public Producer(Q q)

        {

            this.q = q;

            new Thread(new ThreadStart(this.Produce)).Start();

        }



        public void Produce()

        {

            for (int i=1; i <= 5; i++)

            {

                q.put(i);

                Console.WriteLine ("Producing {0}", i);

                Thread.Sleep(200);

            }

        }

    }

    

    public class Program

    {

        public static void Main(string[] args)

        {

            Q q = new Q();

            

            new Producer(q);

            new Consumer(q); 

        }

    }

}


BEEME - DC Generator







Faraday's Law








DC Generator construction and working





BEEME FAQ

Basic Electrical, Electronics and Measurement Engineering 



BEEME 2 Protection devices

UNIT – 3
Utilization of Electrical Power

  
Need for earthing
Earthing is used to protect you from an electric shock. It does this by providing a path (a protective conductor) for a fault current to flow to earth. It also causes the protective device (either a circuit-breaker or fuse) to switch off the electric current to the circuit that has the fault.

What is circuit breaker?
Electrical circuit breaker is a switching device which can be operated automatically or manually for protecting and controlling electrical power systems.

Applications of Circuit breakers:
The circuit breaker is a switching device which also offers protection by tripping & cutting off the supply to load in case of fault. Primarily the circuit breakers are used for switching of different kinds of load in Industries, Buildings, Commercial Complexes, and Hotels, etc.



BEEME 2 Comparisons

UNIT – 3
Utilization of Electrical Power


Compare fuse and circuit breaker

Fuse
Circuit breaker
Detects and interrupts the fault current
Only interrupts the fault current. Detection is done by relay system
Automatic operation
Not automatic. Relay system is required to operate it
Breaking capacity is less
Has large breaking capacity
Arc interruption is simple
Arc interruption is complicated
Operating time is small. Operating speed is high
Operating time is large. Operating speed is comparatively less
Replacement / rewiring required after each operation
No replacement needed. Easy to reset
Simple design. Cheap
Complicated design. expensive





Comparing Horizontal and vertical axis wind turbines


Horizontal axis wind turbines
Vertical axis wind turbines
Axis of rotation
Axis of rotation is parallel to ground and wind steam
Axis of rotation is perpendicular to ground and wind stream
Mount point
Gearbox and generator are mounted above the ground with a tower to support them
Gearbox and generator are mounted at ground level. Hence does not require any support tower.
Output energy
Overall energy output is more
Overall energy output is less
Efficiency
Overall efficiency is more
Overall efficiency is less
Stress
Higher stress is put at the base of the blade by the wind
Higher stress is put at the center of the blade by the wind
Structural support
Requires more structural support
Requires less structural support 
Installation and maintenance
Installation and maintenance is hard
Installation and maintenance is easy
Yaw control
Yaw control is necessary to turn rotor so that the blades face the wind
Yaw control not needed  as rotor reacts to wind from any direction

BEEME 2 Batteries

UNIT – 3
Utilization of Electrical Power


General applications of Batteries

1.    Batteries are used in starting, lightning and ignition systems.
2.    They are used in back up power supply.
3.    Batteries are used in portable equipment like wrist watches, mobile phones, tablets, laptops.
4.    They are used in military and aerospace science.

Advantages of Ni-Cd battery
1.    Only battery that can be ultra-fast charged with little stress.
2.    It has long shelf life; can be stored in a discharged state.
3.    Simple storage and transportation.
4.    Available in wide range of sizes and performance options.

Disadvantages of Ni-Cd battery:
1.    Relatively low specific energy compared with newer systems.
2.    Cadmium is a toxic metal ,cannot be disposed of in landfills.
3.    It has high self-discharge.
4.    It has memory effect;needs full discharges.

Advantages of lead acid battery:
1.    It is less expensive.
2.    It is robust and tolerant to abuse.
3.    It can deliver very high currents.
4.    Wide range of sizes and capacities available.

Disadvantages of lead acid battery:
1.    It is very bulky and heavy.
2.    It has danger of over heating during charging.
3.    It is not suitable for fast charging.
4.    Must be stored in a charged state once the electrolyte has been introduced to avoid deterioration of the active chemicals.




Advantages of lithium battery
1.    It is Eco friendly
2.    It is less weight and compact.
3.    It needs low maintenance.
4.    It needs more charge cycles.

Disadvantages of lithium battery
1.    Requires protection circuit to maintain voltage and current within safe limits.
2.    It is expensive to manufacture-storage in a cool place at 40% charge reduces the aging effect.
3.    It is not fully mature -metals and chemicals are changing on a continuing basis.
4.    Shipment of larger quantities may be subject to regulatory control.


1.