Monday, July 28, 2014

Posted by Anmol Sharma
An exception is any uncommon condition arising during execution of a program. There might be several conditions when an exception is encountered in a program but at most basic level examples of exceptions include file not found exception, dividing a number by 0, inputting a wrong data type values etc

It is necessary to handle exceptions otherwise an end user will not feel at home with the application and it is a sign of poor problem understanding. Just for example, if there is a program which accepts a string “thinkdigital” and converts it to uppercase “THINKDIGITAL” and vice a versa then there must be a facility which handles an event when a user enters a non-string input which cannot be understood by the program. This is just an example to make any layman understand about the logic of exception

In .net framework, we have System.Exception class which provides all possible exception handling facility in c#.

Any piece of code which can trigger an exception goes under the ‘try’ block, once an exception occurs, the control moves to the ‘catch’ block and handles the exception. A try block can have number of catch block depending upon different types of exceptions occurring during an operation. But always the base catch block executes first and if required child catch blocks are executed.  There is a ‘finally’ block which is optionally used for performing maintenance tasks like freeing memory, closing file stream connections etc.


// Illustration code

using System;
using System.IO; //required for file operations


class ExceptionExampleProgram
{
    public static void Main()
    {
        StreamReader streamReader = null;
        try //code which may trigger an exception comes under the try block
        {
            streamReader = new StreamReader("C:\\file\\info.txt"); //reads the content of the file specified
            Console.WriteLine(streamReader.ReadToEnd());
            streamReader.Close();

        }
        catch (FileNotFoundException Trial) // handles the exception using predefined properties in exception class or user defined message
        {

            //Console.WriteLine(FileNotFound.Message); // printing message using system defined 'Message' property
            Console.WriteLine("This program can not find the file specified {0}, Please check again", Trial.FileName); // printing user defined message to make things more clear
         
        }
        finally // to perform clean up tasks like closing connections and release memory for efficiency
        {
            if (streamReader !=null) // required as if stream reader is null then it cant be closed
            {
            streamReader.Close();
            }
            Console.WriteLine("Stream reader now closed, so is this article :P");
            Console.ReadLine();
        }
    }
}

Screenshots // click to open a higher resolution version

/* Normal Execution */

/* File Not Found Exception Handling */

/* Another type of exception which can occur if directory path is altered, 
another catch block is required for this */

Sunday, July 27, 2014

Posted by Anmol Sharma
While garbage collection is automated in java, still it provides system.gc() method which force run the garbage collector and perform clean-up tasks. And at the same time, it is never recommended to run the garbage collector explicitly which causes the system to be inefficient and even the JVM will ignore the explicit method in most cases.

 There are various reasons not to use explicit gc but it is not the matter of discussion. The point of discussion is that many times it is asked in what circumstances or applications System.gc() should be used. Why it all exist then? First of all at beginners level like us we should hardly bother about using System.gc() at all. Let the automatic garbage collection do the job. But for a general idea it is interesting to note that there are some applications and circumstances where explicit garbage collections proves to be quite useful. And that’s why this method is not deprecated from java.

- In applications when user actually wants to know how much memory is lying unused by expired instances, in other words to find about memory leaks called as profiling.

- In android applications while creating bitmaps to prevent out of memory errors.

- Some task managers where user clicks a button and kills the task.

- Before performing benchmarking tests of an application.

- During development, debugging and testing phases of an applications

- When you want to prove yourself as a bad computer science student :P

I just cannot come across any other reason why one should even bother about manual resource collector when we have automatic memory management which is quite efficient.

Just in case you didn’t understand the above text then I am sure you will understand about this with the help of following piece of witticism  I just wrote while thinking all about this ;P

/* Me during a hypothetical (kalpanik) job interview in an IT company... */

Interviewer – Can we perform explicit garbage collection using system.gc() in java? Explain in most simple words taking real life example…?

Me – Yes, we can perform explicit garbage collection using system.gc() in java but mostly it will be totally ignored by JVM. There is no guarantee if JVM will even bother about the presence of the system.gc() method.
Taking a real life example, It’s actually like proposing a girl or asking her out for a cup of coffee but there is no guarantee that she will accept your request or not. It will be totally ignored mostly. So let the garbage collector run on its own  explicit garbage collection matlab ek tarfa pyaar  …err Dil ki baat thodi technical hogai ://

Interviewer with tears in eyes – Bhai Single lagtey ho  …Kitni salary loge?

PS - Do not imitate this in real life interview, you just might be blacklisted forever from that company ;P :--D

In the next article I will try to explain the overall garbage collection process in java and if possible try to compare with method in other languages.

So that’s all folks, thanks for reading.

Friday, July 18, 2014

Posted by Anmol Sharma
While both of them acts as base types, there are quite significant differences between abstract classes and interfaces in C#. Few noteworthy points are as follows –

-        -   Abstract classes can have access modifiers whereas interfaces doesn’t have access modifiers

-          - Abstract class can inherit either from another abstract class or another interface while an interface can         inherit only from an interface.

-         -  A class can inherit more than one interface, while a class cannot inherit multiple classes at the same time.

-         -  While interfaces can’t have implementation of any members, abstract classes can have.


   Illustration code
using System;

    public abstract class JIMS
    {
        int RollNo;
        public void print() //abstract class can have implemetations
        {
            Console.WriteLine("This is a print method");
        }
    }

 public interface iJIMS
    {
        /* public void print() // interfaces can not have implementations nor access specifier and it will give an error.
        {                      
            Console.WriteLine("This is a print method");
        }*/
     //int RollNo; // interfaces can not have fields while abstract classes can have 
     void Print();

    }


 public class Program
 {
     public static void Main()
     {
         Console.WriteLine("46geekslab - Difference between abstract classes and Interfaces in c#");
         Console.ReadLine();
     }
 }




Posted by Anmol Sharma

[Tips & Tricks] Do You Really Need to Regularly Reinstall Windows?


reinstalling-windows

For many people, Windows seems to slow down over time. Quite a few people fix this by regularly reinstalling Windows. But do you really need to regularly reinstall Windows? And, if so, how regularly do you need to reinstall it?
Reinstalling Windows is inconvenient. You have to back up all your data, go through the install process, reinstall all your favorite programs, and restore that data. This sucks up valuable time.

Why Windows Slows Down Over Time

The main reason people reinstall Windows is because it slows down over time. But why do Windows systems slow down over time?
  • Startup Programs: Examine a Windows system that’s slowed down and you’ll likely to find many additional startup programs have been installed, lengthening the boot process, cluttering the system tray with useless icons, and consuming CPU, memory, and other system resources in the background. Worse yet, some computers may come with a huge amount of useless startup programs out of the box thanks to manufacturer-installed bloatware.
  • Explorer Plug-ins, Services, and More: Applications that add shortcuts to Windows Explorer’s context menu can make right-clicking on files take much longer if they’re badly programmed. Other programs may install themselves as a system service, so they’re running in the background even though you can’t see them. Even if they aren’t in the system tray, useless programs can slow down your PC.
  • Heavy Security Suites: Security suites like Norton are often very heavy, consuming a lot of resources  to perform all their functions. You don’t really need a full security suite — just an antivirus program.
  • PC Cleaning Tools: PC cleaning tools are generally scams. Paradoxically, they can make your computer even slower if they add themselves as a startup program and run in the background. The scammiest PC cleaning programs may even install additional spyware and other junk. Use the free CCleaner instead of paid PC cleaning tools.
  • Other Junk: Poorly written applications may clutter your system with useless DLL files and fill your registry with useless entries. The worst applications may not clean up properly after themselves, leaving this stuff on your system even after you uninstall them.
  • Browser Toolbars: Legitimate browser extensions can slow down your browser enough, but junk add-ons like the terrible Ask.com toolbar can slow things down even more.
In other words, the main cause of a Windows system slowing down over time is installing junk software.


How To Prevent Windows From Slowing Down Over Time

To keep your Windows system running like new, you need to take proper care of it.
  • Install only software you’ll actually use. Choose well-written, lightweight programs that respect your system instead of slowing it down.
  • Pay attention when installing software and avoid installing browser toolbars, spyware, and other garbage software that can slow down your computer.
  • Regularly uninstall software you don’t use from the Control Panel. Even useful software may run in the background and slow things down.
  • Occasionally use a tool like CCleaner or Disk Cleanup to remove the temporary files wasting space on your hard drive. You don’t have to reinstall Windows to get rid of these.
  • Take proper care of your web browser, too. Use a minimal selection of browser extensions. If you don’t use a browser extension, uninstall it — it’s just taking up system resources and slowing your browser down for no good reason.
  • Carefully select lightweight, minimal security programs. All you really need to install on Windows now is an antivirus — and Windows 8 users don’t even need to install that.
  • Use a startup manager tool like the one included with CCleaner or the one built into Windows 8 to prune useless programs from your startup process.

So When Do I Need to Reinstall Windows?

If you’re taking proper care of Windows, you shouldn’t need to regularly reinstall it. There’s one exception, however: You should reinstall Windows when upgrading to a new version of Windows. Skip the upgrade install and go straight for a clean install, which will work better. Performing an upgrade install can result in a variety of issues — it’s better to start with a clean slate.
Obviously, if your Windows system has slowed down and isn’t speeding up no matter how many programs you uninstall, you should consider reinstalling Windows. Reinstalling Windows may often be a faster way to get rid of malware and fix other system issues than actually troubleshooting and fixing the specific problem. However, you should try to take better care of Windows in the future.
If your Windows computer is running fine, you don’t need to spend hours reinstalling your operating system — even if it’s been years since you last reinstalled Windows. That’s a sign you’re doing a good job of taking care of your Windows system.

How To Quickly Reinstall Windows

If you are going to reinstall Windows, Windows 8 actually makes this much easier. Windows 8′s “Refresh Your PC” feature effectively performs a quick reinstall of Windows, removing all your installed desktop programs and any other system modifications, while preserving your personal files. You don’t even need a Windows disc to do this.
If you’re using a previous version of Windows, you can reinstall Windows from a Windows installation disc or restore it from your computer’s recovery partition. Before you reinstall Windows from the disc or recovery partition, make sure you have backups of all your important files.



There are other reasons to reinstall Windows. Maybe you really like that clean, “like new” Windows environment. However, if you carefully select the software you install and take proper care of your Windows system, you shouldn’t have to regularly reinstall Windows.
Sure, file system fragmentation can cause Windows to slow down over time as well — but Windows automatically defragments your hard drive and defragmentation isn’t even necessary on SSDs.

By - Dollar Dhingra
Posted by Anmol Sharma
APK or Android Package File is a file format used to install applications on an android phone. Extended form of .apk is ZIP format.

Following steps will retrieve Java & XML/HTML source code from an apk file:

Step 1

Change the extension of apk file to .zip and then extract the zip file to a new folder. Copy the classes.dex file and follow next step.

Step 2

Download dex2jar. Extract dex2jar in a folder and paste the classes.dex file into it. Now open the cmd, change path to dex2jar folder and execute the following command “dex2jar classes.dex”. This will create a new file called “classes.dex.dex2jar”.

Step 3

Download java decompiler. Open the jd-gui and open “classes.dex.dex2jar” file created during step 2. Click on file & click ‘save all sources’ in jd-gui; this will create a new folder with java source files. Next step will retrieve the XML files.

Step 4

Download apktool, apktool install window & framework-res.apk. Put all these files in a new folder with the apk file you need to decode. Open the cmd, change path to current folder and execute following two commands back to back -

apktool if framework-res.apk

apktool d "myapp".apk  (myapp = name of apk you want to decode)

A folder will be created containing XML files in the current folder .Merge folders created in step 2 & 5 and you will have both set of java & xml source files for that particular apk.

This method may not work for obfuscated/encrypted apks.

Feel free to drop a message in comments section below in case of any query. Good luck!


Tuesday, July 15, 2014

Posted by Dollar Dhingra


How many times do you open a Web Browser ??? Many a times, I am sure.
We have collected some of the "You Should Know Them" browsing tricks that will make your life easy.

Most of them would be known to you if you are a TechGeek ! ;)

 

Automatically add www. and .com/.net to a URL  

You can save a couple of seconds typing in a URL by simply click CTRL + Enter after you type the name of the site. Need .net instead of .com ? Press CTRL + Shift + Enter instead.


Jump to address bar 

There are a number of ways to jump right to the address bar from anywhere in browser. Pressing CTRL + L, F6, and ALT + D all accomplish this goal. You can test it right here.

Bring back a closed tab 

Accidentally closed a tab? Simply press CTRL + Shift + T to reopen the most recently closed tab and get back to what you were doing.

Use private browsing 

The uses for not having cookies and history saved are obvious for certain activities, you know, like online shopping for gifts or performing online banking etc on a shared computer (of course!). Pressing CTRL + Shift + N will launch a new private in Chrome, CTRL + Shift + P will do it in Firefox and Internet Explorer.



Cycle through open tabs 

Pressing CTRL + TAB while in a browser will flip between each one. This can be much faster than moving the mouse and clicking on a tab. CTRL + NUM (1, 2, 3, 4, n..) will also take you to certain tab in that numeric order.