Posts

The switch-case fall through

So, I am a Software Engineer at a reputed firm and still fell for the trap of fall-through feature of the switch-case statement.

Rule of thumb: Starting from the matched case, all statements are executed, unless a break statement is reached. After the break statement, the control is transferred to the statement next to the switch-case block. 

Here are some examples to test your understanding of switch-case:

The output of the example is AB. This is because there is no break statement and so all the statements are executed after the first match of case 0.

The output of the example is BCD. This is because there is no break statement and so all the statements are executed after the first match of case 1.
The output of the example is AB. This is because there is a break statement at the end of case 1 so, after the first match at case 0, all the statements are executed till the break statement.

The output of the example is AB. This is because there is a break statement at the end of case 2…

Constructor of a Fragment in Android

Recently, I came to a very strange issue in Android development and I wish to share a very important lesson. As an Android developer, you might be knowing that most of the crashes are related to lifecycle events of Activities and Fragments. Moreover, most phone manufacturers patch the original Android system to come up with their own versions. Such versions might have a hostile kernel which may kill Activities more frequently to claim more free space and faster performance for foreground apps. This makes Android development difficult as you have to check for each of the edge cases that may occur.

One of the best ways to debug such crashes is to use the "Don't Keep Activities" feature of the development mode. This kills the Activities and the fragments as soon as the app goes to the background. Enable this mode and start your app and navigate through all your Activities and Fragments. If you get no faulty behaviour, then your app is of quality-at-par.
Let's take a cl…

Rendering Performance Evaluation - Android SDK vs React Native

Image
UI rendering speed has always been a key for evaluating a new technology. The lesser is the rendering time, the more preferable is the technology. In the recent times, React native has become very popular for developing native apps. Such apps are truly native and way different from similar other technologies like Xamarin and Cordava. I got some time to evaluate how React Native compares to Android SDK.

TLDR: As you might expect, Android SDK outperforms React Native by a huge margin. But React native technology is slowly catching up (most of the credits goes to the amazing diff rendering technology which forms the core of React). React native is efficient enough for apps with small number of UI components which could be rendered within reasonable time.
Performance comparisonEmulator used for evaluation

Model - Google Pixel 2
API Level - 24
Resolution - 1080 x 1920 (420 dpi)
CPU - x86
Target - Android 7.0
RAM - 1536 MB

Evaluation criteria

We will be creating a large number of text views …

Calling C++ native code from Java

Recently, I faced a lot of troubles in finding a good article that completely explains the process of calling a C++ native function from Java. I did some experiments and I finally succeeded. I will be sharing the instructions step-by-step.

In this article, I will be taking a very basic example of taking an array of numbers as input in Java, computing their sum using a native C++ code and then printing the output back to the console using Java. I would be keeping the article concise and would encourage you to explore the official documentation in case you run into some issues. Also, I will be using Windows and GCC compilers. A 32-bit C++ compiler is compatible with 32-bit Java compiler and a 64-bit C++ compiler is compatible with 64-bit Java compiler. MinGW doesn't publish x64 versions of GCC compilers for Windows (it is only available for Linux). So, in case you are using Windows make sure that you install 32-bit Java version. I am also assuming that you are using JDK 8 or some a…

Popular ethical hacking tricks on LAN

Birla Institute of Technology, Mesra has a large Local Area Network. Several computers are connected through hundreds of routers and switches. The local network has served several purposes whether it is file sharing through DC or organizing an online event. Such interconnection has made it vulnerable to attacks. The LAN is based on old ethernet technology. It is a good playground to practice ethical hacking. I am going to list you some working techniques that can be easily tried. I won't be telling you complete steps on how to do it. Please use it for learning purpose only.
1. Brute-force to any local website Everyone has to login to Cyberoam before they can access the fast Internet available on the ethernet. There are several automated scripts written in various languages to login to Cyberoam. Since Cyberoam is available on a local network, it is much faster to get the response for login credentials. Once the path is resolved, it takes a maximum of 5 hops for the packet to reach…

Setting up DC Hub on Raspberry Pi

Aditya Pal came to my room to check out a Raspberry Pi that I recently got as a gift. I told him, it a small credit card size computer. It powers on as soon as you plug in and boots up fast. I was already using it as a server for other purposes (hosting BitZoom). Our hostel at college had a strange network issue. The intra-hostel network worked smoothly. But, we had to face a lot of issues outside of the hostel (especially at Hostel 7 when it was disconnected from the external network for a month). The college's official DC was on the external network and it was inaccessible for quite a long time whenever we faced network issues. Aditya suggested me the idea of setting up DC on Raspberry Pi for the students of the hostel. We worked together for a few days to finally set up DC on Raspberry Pi named Raspbian. It remained active for over a year unless the college administration finally decided to shut it down due to network congestion. There were already 4 active hubs drawing traffi…

Computer Science and Engineering at Birla Institute of Technology, Mesra

I was admitted to Birla Institute of Technology, Mesra on 27th July 2015. 4 years have passed since then and I am going to share my academic experience with everyone. I hope this will help you with your college goals as well.
Semester 1
Physics - This course was the first. It explored Einstein's relativity, Dual nature of light, Maxwell's equation, Field Theory and Plasma physics. It instantly caught the attention of all my classmates. The course was lectured by Mr S.K. Rout. We used to have two-morning lectures and many slept through the class. There were 2 quizzes that were held and I scored 8/10 in both of them. An interesting thing is that most of the concepts were directly related to Intermediate Physics and so many found it easy to pick up. Others who were not well-acquainted with Integrals found in difficult.
Engineering Mathematics - This course explored trigonometric functions, approximations and integrals in details. The course was taken by Ms Sayeda Jabeen. The firs…