Tuesday, September 26, 2017

What is the difference between Singleton Class and Static Class? Which one to use and when?

Almost both singleton class and static class serve the same purpose which creates confusion among developers and architects about which one to use. When to use singleton class and when to use static class. In this article I have tried to differentiate between the two. Following is the list of differences between a singleton class and a static class:

1. Singleton classes are more inclined to the object-oriented concepts as compared to the static classes. With Singleton classes, you can use inheritance and polymorphism to extend a base class, implement an interface and capable of providing different implementations. While a static class cannot inherit their instance members. So, Singleton classes are more flexible than static classes.

2. Singleton classes can be passed as an object to other methods while a static class allows only static methods and you cannot pass static class as parameter.

3. If your requirement is to maintain the state, then singleton class is the better choice than static class, because maintaining the state with static classes is very cumbersome and leads to subtle bugs.

4. Singleton classes can be lazy loaded if it’s a heavy object, but static class doesn't have such advantages and always eagerly loaded. Static class is generally initialized when it is first loaded and it will lead to potential class loader issues.

5. Static classes are hard to mock and consequently hard to test than singletons, which are easy to mock and thus easy to test. It’s easier to write unit tests for singleton than static classes, because you can pass mock object whenever singleton is expected, e.g. into constructor or as method arguments.

6. Singleton classes provide more flexibility. Consider the possibility that your application has a global shared object and tomorrow you decide that you must make more than one instance of the class. If you use a singleton class then all you should do is make the constructor public. This is not so simple with static classes.

7. Many Dependency Injection framework manages singleton quite well e.g. Spring, which makes using them very easy.

8. Singleton objects are stored in Heap, but static objects are stored in Stack.

9. Static class provides better performance than singleton class, because static methods are bonded on compile time.

10. Singleton classes maintain single object across the application life cycle, so the scope is at application level. The static does not have any object pointer, so the scope is at App Domain level. Moreover, both should be implemented to be thread-safe.

Thursday, September 14, 2017

Security and Privacy issues with IoT (Internet of Things) - Top barriers to IoT success

IoT is one of the biggest breakthroughs in the history of the tech industry. It will soon be an inherent part of every aspect of our lives. Security and Privacy are the most significant challenge for the IoT. Security and Privacy issues are acting as top barriers to IoT success. So, addressing underlying security and privacy concerns is very crucial. 

As more and mored devices are being added to the IoT everyday, privacy and security concerns are becoming vital. 

Security issue with IoT devices

Security is one of the main concerns of the IoT ("Internet of Things"). With billions of devices connected to the internet, it is needless to say that to protect your connected devices from malware penetrations is a real challenge. Security risks of IoT devices cannot be ignored whether it is from hackers or corporations. Increasing the number of connected devices increases the opportunity to exploit security vulnerabilities.

When IoT devices are connected to the cloud or data centers via internet, they get under the risk of being accessible to the outside world. Poorly designed devices can easily expose user data to theft. 

There are many reasons behind the state of insecurity in IoT. 

Companies do not update their devices enough or at all. This means that an IoT device which was safe when you first bought it can become unsafe as hackers discover new vulnerabilities.

The fundamental security weakness of the Internet of Things is that it increases the number of devices on the internet. Earlier, most of us had to only worry about protecting our computers, then, we had to worry about protecting our smartphones as well, and now after IoT, we have to worry about protecting our car, our home appliances, our wearables, and many other IoT devices.

Because there are so many devices that can be hacked, that means that hackers can accomplish more. You may have heard about how hackers could potentially remotely control cars and remotely accelerate or decelerate the car. But hackers could use even seemingly unimportant devices like baby monitors or your thermostat to uncover private information or just ruin your day. The point is that we have to think about what a hacker could do with a device if he can break through its security. 

In this way, our normal day to day life and health can become the target of IoT hack attacks. Urban infrastructure can also become a target for hackers.

Privacy issue with IoT devices

Corporations which create and distribute interconnected devices could also use these devices to obtain personal data, particularly dangerous when used for money transfers. Manufacturers can steal the information about your habits and misuse it. 

For example, consider how some companies are distributing Fitbits to their employees so that they can track their health and thus get lower health insurance premiums. Even if we ignore the worrying idea of workers’ health being monitored by corporations around the clock, there is the question of what corporations can do with the data they have gathered. Companies can attempt to send or even sell gathered data to other companies, which raises issues regarding our individual privacy rights.

Vision features and voice recognition are now being integrated into smart TVs. These features can listen continuously to conversations or look for activity and transmit data selectively to cloud services for processing. These cloud services may sometimes even include third parties. The collection of all this information faces a number of regulatory and legal challenges.

The collection of private information exposes legal and regulatory challenges facing data protection and privacy law. There are a wide range of regulatory and legal questions surrounding the IoT, which need thoughtful consideration. Legal issues with IoT devices include crossborder data flow, conflict between law enforcement surveillance and civil rights, data retention and destruction policies, and legal liability for unintended uses, security breaches or privacy lapses. 

In short, Security and Privacy issues are the biggest issues which consumers, businesses and governments need to consider before using IoT connected devices.

Tuesday, September 12, 2017

Real World Examples of IoT (Internet of Things) - How will IoT change our lives?

IoT (Internet of Things) is going to change our lives to a large extent. In the coming years, we will realize the real potential of IoT. Below are some real world examples of IoT.

Lets consider IoT enabled Alarm Clock or say Smart Alarm.

Imagine you wake up at 7am every day to go to work. Your alarm clock does the job of waking you just fine. That is, until something goes wrong. Your train is cancelled and you have to drive to work instead. The only problem is that it takes longer to drive, and you would have needed to get up at 6.45am to avoid being late. Oh, and it’s pouring with rain, so you’ll need to drive slower than usual. 

A connected or IoT-enabled alarm clock would reset itself based on all these factors, to ensure you got to work on time. It could recognize that your usual train is cancelled, calculate the driving distance and travel time for your alternative route to work, check the weather and factor in slower travelling speed because of heavy rain, and calculate when it needs to wake you up so you’re not late. 

If it’s super-smart, if might even sync with your IoT-enabled coffee maker, to ensure your morning caffeine’s ready to go when you get up.

Now consider IoT enabled car or say connected cars.

Having been woken by your smart alarm, you’re now driving to work. On comes the engine light. You’d rather not head straight to the garage, but what if it’s something urgent? In a connected car, the sensor that triggered the check engine light would communicate with others in the car. A component called the diagnostic bus collects data from these sensors and passes it to a gateway in the car, which sends the most relevant information to the manufacturer’s platform. The manufacturer can use data from the car to offer you an appointment to get the part fixed, send you directions to the nearest dealer, and make sure the correct replacement part is ordered so it’s ready for you when you show up.

You are on your way to a meeting; your car could have access to your calendar and already know the best route to take. If the traffic is heavy your car might send a text to the other party notifying them that you will be late. 

Now consider IoT enabled homes or say smart homes.

Take an instance where you need to monitor your home or child when you are away. A simple solution would be to fix an IP camera and monitor its feed using a web or mobile application. You can even hire a babysitter. The former option can give you the complete monitoring data, while the latter cannot. If you fix sensors or devices, which can be reached from anywhere, you have the flexibility to monitor as well as control those devices to the best of their ability; this can make your home or baby 99.99% secure. 

Your home security system, which already enables you to remotely control your locks and thermostats, can cool down your home and open your windows, based on your preferences.

British Gas's Hive Active Heating enables consumers to control their home heating from their smartphone, laptop or tablet. It even has the ability to turn off when no one is home by detecting whether your smartphone is in the house or not.

IoT can help in reducing accidents and save valuable human life.

Let’s look at one example. In 2007, a bridge collapsed in Minnesota, killing many people, because of steel plates that were inadequate to handle the bridge’s load. 

When we rebuild bridges, we can use smart cement: cement equipped with sensors to monitor stresses, cracks, and war-pages. This is cement that alerts us to fix problems before they cause a catastrophe. And these technologies aren’t limited to the bridge’s structure.

If there’s ice on the bridge, the same sensors in the concrete will detect it and communicate the information via the wireless internet to your car. Once your car knows there’s a hazard ahead, it will instruct the driver to slow down, and if the driver doesn’t, then the car will slow down for him.

And thus bridges become smart bridges, and cars smart cars. And soon, we have smart cities, and….

Airplane manufacturers are building air-frames with networked sensors that send continuous data on product wear and tear to their computers, allowing for proactive maintenance and reducing unplanned downtime. 

Now consider some more examples of Real World IoT:

Some insurance companies, for example, are offering to install location sensors in customers’ cars. That allows these companies to base the price of policies on how a car is driven as well as where it travels. Pricing can be customized to the actual risks of operating a vehicle rather than based on proxies such as a driver’s age, gender, or place of residence.

Sensors in even the domestic animals. In the world of IoT, even the domestic animals will be connected and monitored with the help of embedded sensors. This allows farmers to monitor their animal's health and track their movements, ensuring a healthier, more plentiful supply of milk and meat for people to consume. 

Some more...

What if your office equipment knew when it was running low on supplies and automatically re-ordered more? 

What if your refrigerators can warn you when you’re out of milk. 

What if smart dustbins can signal when they need to be emptied.

What if smart tea maker that knows just when you’re in need of a cup of tea.

Truly speaking, you can think of infinite examples of IoT in the real world. It cannot be summarized in an article. There is no limit. Just keep thinking...

Other articles on IoT:

Internet of Things (IoT) - Next Stage of Information Revolution

Internet of Things (IoT) - Next Stage of Information Revolution

The term "Internet of Things" was first coined by Kevin Ashton, cofounder and executive director of the Auto-ID Center at MIT in 1999.

The "Internet of Things (IoT)" is the next stage of the Information Revolution. 

What is IoT (Internet of Things)?

IoT refers to the connection of devices (other than computers, smartphones and tablets) to the Internet via embedded sensors. It allows devices to talk to us and talk to each other. So, IoT can also be defined as a network of internet-connected devices able to collect and exchange data using embedded sensors. 

A thing, in the "Internet of Things", can be a person with a heart monitor implant, a farm animal with a bio-chip transponder, an automobile that has built-in sensors to alert the driver when tire pressure is low or any other natural or man-made object (almost anything else you can think of) that can be assigned an IP address and provided with the ability to transfer data over a network with the help of embedded sensors. 

Earlier the data was created by people on the internet, but now the data will be created by the things (living or non-living) without any human intervention.

IoT Devices

Any stand-alone internet-connected device that can be monitored and/or controlled from anywhere. It should have embedded sensors and on/off switch. It should have the ability to represent itself digitally means it can be assigned an IP address and have the ability to collect and transfer data over a network without manual assistance or intervention. 

Due to the limited address space of IPv4 (which allows for 4.3 billion unique addresses), IoT devices will have to use the next generation of the Internet protocol (IPv6) to scale to the extremely large address space required.

Examples of IoT Devices: Smartwatch, TV,  Refrigerators, Washing Machines, Kitchen Appliances, Thermostats, Cars, Switches, Lights, Blood Pressure and Heart Rate Monitors, Smart grids, Virtual Power Plants, Intelligent Transportation and anything you can think of.

Basically, if your fridge or TV has an Internet connection, then it becomes an IoT device.

If your coffee maker connects to an app on your smartphone that allows you to begin brewing with a tap on your screen, that coffee maker becomes part of the Internet of Things.

As per IoT, Anything that can be connected, will be connected. Connect everything in this world. The Ultimate Goal of IOT is to Automate Human Life. In this way, IoT creates a relationship among people-people, people-things, and things-things.

Applications of IoT

Wearables (like Smartwatches to track health and exercise progress, sleep patterns, send text messages and calls).

Smart Home (hundreds of products in the market that users can control even with their voices).

Smart Cities (solves traffic congestion issues, smart parking, reduces noise, crime, and pollution).

Connected Cars (to assist drivers and reduce accidents).

Internet of Things Devices & Examples

Amazon Echo - Smart Home: The Amazon Echo works through its voice assistant, Alexa, which users can talk to in order to perform a variety of functions. Users can tell Alexa to play music, provide a weather report, get sports scores, order an Uber, and more.

Fitbit One - Wearables: The Fitbit One tracks your steps, floors climbed, calories burned, and sleep quality. The device also wirelessly syncs with computers and smartphones in order to transmit your fitness data in understandable charts to monitor your progress.

Barcelona - Smart Cities: The Spanish city is one of the foremost smart cities in the world after it implemented several IoT initiatives that have helped enhance smart parking and the environment.

AT&T - Connected Car: AT&T added 1.3 million cars to its network in the second quarter of 2016, bringing the total number of cars it connects to 9.5 million. Drivers don't have to subscribe or pay a monthly fee for data in order for AT&T to count them as subscribers.

Other articles on IoT:

Real World Examples of IoT (Internet of Things) - How will IoT change our lives?

Monday, March 14, 2016

Oracle Forms Debugging: Using the “DEBUG_MESSAGES=YES” runtime option - Handling "Please Acknowledge" message

Oracle Forms Debugging: Using the “DEBUG_MESSAGES=YES” runtime option - Handling "Please Acknowledge" message

“DEBUG_MESSAGES=YES” is a “quick and dirty” technique for pinpointing code problems. This causes a message to automatically display to let you know each trigger as it executes. Once you encounter the runtime error, you will know the last trigger that fired and should be able to trace through the code from that point. For anyone that was around in the SQL*Forms 3.0 days, this was the default behavior when running a form in debug mode.

To use this option from the Form Builder, check the “debug_messages” option on the runtime tab after choosing Tools -> preferences from the menu. From the command line, simply add the “debug_messages=yes” option. 

If you are using an icon in Windows to start your form, add the option to the shortcut command. It would look something like this for Windows platforms:

c:\orant\bin\ifrun60.exe module=myform userid=scott/tiger debug_messages=yes

On Unix:
f60runm module=myform userid=scott/tiger debug_messages=yes

The major disadvantage of using this technique is that you have to acknowledge every message as each trigger executes, which can be very annoying. You will keep getting "Please acknowledge message" prompt each time whenever a new trigger is encountered. Although it shows the triggers that fire, it does not show program units that execute, and there is no way to display the values of variables. It can also cause the same focus problems and program flow interruption that you see with the “MESSAGE” built-in. However, this method is useful if you have no idea which trigger is causing the problem; once you have narrowed down the scope, other troubleshooting techniques would be more appropriate.

Monday, February 29, 2016

Oracle Forms Exception Handling: NO_DATA_FOUND, TOO_MANY_ROWS and OTHERS

Oracle Forms Exception Handling: NO_DATA_FOUND, TOO_MANY_ROWS and OTHERS

EXCEPTION block in PLSQL Oracle Forms is used to track the exceptions. Following is the PLSQL code snippet which uses NO_DATA_FOUND, TOO_MANY_ROWS and OTHERS exceptions. If the SQL SELECT query does not return any data, NO_DATA_FOUND exception is fired. If the SQL SELECT query returns more than one row where it was expected to return only one row, TOO_MANY_ROWS exception can be used to track this kind of exception. If you are not sure what kind of exception can the code throw, use OTHERS exception.

DECLARE
  DEPARTMENT_NAME VARCHAR(60);
BEGIN
  SELECT DEPTNAME INTO DEPARTMENT_NAME FROM DEPT WHERE DEPTNO = 20;
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    MESSAGE('No data found');
  WHEN TOO_MANY_ROWS THEN
    MESSAGE('More than one row found');
  WHEN OTHERS THEN
    NULL; -- don't do anything and just return from the procedure
END;

Difference between WHEN-VALIDATE-ITEM and KEY-NEXT-ITEM triggers

Difference between WHEN-VALIDATE-ITEM and KEY-NEXT-ITEM triggers

WHEN-VALIDATE-ITEM and KEY-NEXT-ITEM triggers are very close to each other and create a lot of confusion. Following are three differences between them to clear the picture a little bit.

1. Whenever the user changes the value in the item and tries to move out of that item using ENTER or TAB or MOUSE, WHEN-VALIDATE-ITEM trigger is fired. But, in case of KEY-NEXT-ITEM trigger, if user moves out using MOUSE, it will not fire. So, the validation written on this trigger will not fire. Better use, WHEN-VALIDATE-ITEM trigger in this case as it also works with MOUSE.

2. KEY-NEXT-ITEM trigger fires before the WHEN-VALIDATE-ITEM trigger.

3. KEY-NEXT-ITEM trigger will fire every time you move to the next field from that field but WHEN-VALIDATE-ITEM will fire only when you have acutally made any changes to that item. If you have made no changes in the item, it will not fire when you move out this item.

Personally, I prefer to use WHEN-VALIDATE-ITEM trigger in many situations.