Sunday, December 30, 2018

Control Statement in PHP with Example

PHP Control Statement

What is Control Statement in PHP?

A block of code which decide the execution way of programme according to the value of the given condition.
PHP Control Statement with Example

There are some control statements that PHP supports.

1. PHP if Statement

If a given condition is true, only then if statement will execute.
if(condition) {
block1 of code;

if Statement Example: 
if ($15 > $10)
echo “15 is greater than 10”;

15 is greater than 10

2. PHP if…else Statement

In PHP, if a statement is executed only when a specified condition is true. It evaluated to its Boolean values. If the condition is FALSE, it’ll ignore it.
if(condition) {
block1 of code
}else {
block2 of code

if - else Statement Example: Find a largest number between two numbers using if else statement;
$first_value = 5;
$second_value = 10;
if($first_value > $second_value) {
echo “$first_value is greater than $second_value”;
} else {
echo  “$second_value is greater than $first_value”;
10 is greater than 5

3. PHP if….elseif….else Statement 

With this statement, you can select one of several blocks of code to be executed.
if (condition)
first blockto be executed if condition is true;
elseif (condition)
Second block to be executed if condition is true;
final block to be executed if condition is false;
if -else if else statement Example:
$d = date("D");
if($d == "Thu"){
echo "Have a nice weekend!";
} elseif($d == "Sun"){
echo "Have a nice Sunday!";
} else{
echo "Have a nice day!";

Have a nice day!

4. PHP Switch Statement

It is like IF statements. If you want to select one of several blocks of code to be executed, use the Switch statement.
switch ( )
default code

PHP Switch case Statement Example:
         $d = date("D");

         switch ($d){
            case "Mon":
               echo "Today is Monday";

            case "Tue":
               echo "Today is Tuesday";

            case "Wed":
               echo "Today is Wednesday";

            case "Thu":
               echo "Today is Thursday";

            case "Fri":
               echo "Today is Friday";

            case "Sat":
               echo "Today is Saturday";

            case "Sun":
               echo "Today is Sunday";

               echo “which day is this ?";

Today is Wednesday

Friday, December 21, 2018

Introduction to Control System Design and its Classification

What is Control System?

A control system is a group of mechanical or electronic devices that regulate alternative devices or systems using control loops. Typically, control systems are computerized.
Control systems are a central a part of the business and automation. The kinds of control loops that regulate these processes represent industrial management systems (ICS) like superior management and knowledge acquisition (SCADA) and distributed management systems (DCS).

Introduction to Control System Tutorial

Uses of Control systems are won’t enhance production, potency, and safety in several areas, including:

  • Agriculture
  • Chemical plants
  • Pulp and paper mills
  • Quality management
  • Boiler controls and powerhouse
  • Nuclear power plants
  • Environmental management
  • Water treatment plants
Control System Tutorial

There are two types of control system:

1. Open loop control system:  Its operation is incredibly easy, once a signal directs the control component to response, an output is going to be made. Samples of the open loop control systems include laundry machines, light-weight switches, gas ovens, etc.

Open Loop Control System | Thetechunknown
A washing machine is an example of an open loop system. The input and output of an open loop system area unit unrelated. An example is that the operation of a washing machine doesn't rely on the cleanness of the garments, however instead on this time. Each the structure and therefore the control method of an open loop system area unit are natural. However, the results of the output depend on whether the signal is suitable or not.

2. Closed loop control system: Sometimes, we tend to could use the output of the system to regulate the input. This can be referred to as feedback. Feedback could be a unique feature of a closed-loop system. A closed-loop system compares the output with the expected result or commands standing; then it takes appropriate management actions to regulate the input. Therefore, a closed-loop system is usually equipped with a sensing element, that is used to observe the output and compared it with the expected output.

Close loop Control System

One advantage of using the closed-loop system is that it will modify its output mechanically by feeding the signal back to the input. Once the load changes, the error signals generated by the system can adjust the output. However, closed-loop system management systems square measure typically a lot of complicated and so dearer to form.

Classification of Control System: 

Some popular Classifications of Control System are as Follow:
1. The equation of research and style, as Linear & Non-linear system.
2. the sort of the signal, as Time variable, Time-variant, Continuous information, distinct information systems, etc.
3. the kind of system parts, as Electro-Mechanical, Hydraulic, etc.,
4. the most purpose, as a Position management system.

Linear and Non-Linear systems:  A control system is linear if the principle of superposition applies to it. In actual track most of the systems area unit non-linear as a result of the saturation, friction, dead zone, etc. Most of the physical systems area unit non-linear to a certain extent.
Time varied & Time-Invariant System: whereas operative an effect system. If the parameters area unit unaffected by the time, then the system is named Time variant system. Most physical systems have parameters dynamic with time. 

Discrete information systems: If the signal isn't unendingly varied with time however it's within the type of pulses. Then the system is named distinct information system.

Continuous information systems: If the obtained at a varied a part of the systems area unit varied unendingly with time, then the system is named continuous information management systems. 

Adaptive management System:  In some control system, specific parameters area unit either not constant or vary in an unknown manner. If the parameters variations are more significant or rapid, it may be desirable to design for the capability of continuously measuring them & changing the compensation, so that the system performance criteria can always be satisfied. This is called Adaptive control system.

Optimal  Control system: optimum management system is obtained by minimizing and increasing the performance index. This index depends upon the physical network.
Single variable system: In the straightforward order there'll be one input & one output such system is named Single variable management system.
Multi-Variable system: In multivariable management system there'll be over one input & correspondingly additional output.

Monday, December 17, 2018

An Ultimate Guides to Garbage Collection in Java

What is Garbage Collection in Java?

Java garbage collection is the method by that Java programs accomplishes automatic memory management. Java programs compile to bytecode which will be run on a Java Virtual Machine. Once Java programs run on the JVM, objects are created on the heap, which is a share of memory dedicated to the program. Ultimately, some objects cannot be required. The garbage collector finds these unused objects and deletes them to liberate memory.

Java garbage collection

When there are not any references to an object, it is assumed to be now not required, Also, the memory, obtained by the purpose can be rescued. There is no specific necessity to destroy an object as Java handles the de-allocation by itself.
The technique that accomplishes this is often called Garbage Collection. Programs that don’t de-allocate memory will eventually crash once there’s no memory left within the system to assign. These programs are said to have memory escapes.

Why we perform Garbage Collection in Java?

The purpose of garbage collection is to spot and discard objects that are not any longer required by a program, so their resources are saved and reused. A Java object is a focus to garbage collection once it becomes inaccessible to the program within which it’s used.

How Java Garbage Collection Works?

Many people assume garbage collection collects and discards dead objects. But, in Java garbage collection is doing the differing! Live objects are followed and everything else chosen garbage. As you will see, this basic misunderstanding will result in several performance issues.

Let's begin with the heap that is that the space of memory used for dynamic allocation. In most configurations, the package allocates the heap in before to be managed by the JVM whereas the program is running. 

This includes several important complications:
Object creation is quicker as a result of world synchronization with the package isn’t required for every single object. An allocation claims some area of a memory array and transfers the offset pointer forward. The next assignment starts at this offset and requests the next portion of the array.
When an object is not any longer used, the garbage collector retrieves the underlying memory and recycles it for future object allocation. This implies there is no specific deletion and no memory is given back to the operating system.

All objects are allotted on the heap area managed by the JVM. Every item that the uses by the developer is treated in this manner, organized with class objects, variables, and even the code itself. If an object is being documented, the JVM considers it active. Once an object is no longer documented and therefore is not approachable by the application code, the garbage collector removes it and retrieves the unused memory.

Garbage Collection Example in Java:

public class Example1{   
   public static void main(String args[]){  
        /* Here we are purposely assigning a nullvalue to a reference*/
Example1 obj=new Example1();  
        /* Here we are purposely assigning reference a to another reference b*/
Example1a = new Example1();
Example1b = new Example1();
b = a;
System.gc();  /* representing garbage collection by calling this*/
   protected void finalize() throws Throwable
        System.out.println("Garbage collection is performed by JVM");
Garbage collection is performed by JVM
Garbage collection is performed by JVM

In this example, we are representing the garbage collection by calling System.gc(). During this example, we have overridden a finalize() method. This method is invoked directly before an object is destroyed by java garbage collection method. This is often the motive you would see within the output that this technique has been invoked double.