Friday, 26 April 2013

What are the Meta, Super, and Hyper keys in Linux/Unix?

Meta, Super and Hyper keys are referenced most often in various Linux Distros but many users are unaware what these really are.So let me explain each -


  •  Meta :
    The Meta key is not found on modern keyboard, it's use is sometimes emulated with AltGr (on some international layouts) or the right Alt key on the others. In addition:
    1. Sun keyboards have a meta key () as well
    2. Emacs calls Esc the Meta key
  •  Super :
    The Super key is equivalent to the windows logo key or the (command) key. In Ubuntu, it's just another name for the windows logo key.
  • Hyper :
    Hyper is the fourth (counting Ctrl) and last modifier on the Space cadet keyboard. In Ubuntu, its function is undefined (I think), but it can be mapped, as in the screen shot above, to the windows logo key, should it be needed
Though above are default setting you can change the mappings.
I am using Ubuntu 12.04 LTS and in this we can change this mapping from

System Settings -> Keyboard Layout -> options -> Alt/Win key behavior.



Wednesday, 24 April 2013

Linux Command Line Cheat Sheet

Bash Commands

 uname -a Show system and kernel
head -n1 /etc/issue Show distri­bution
mount Show mounted filesy­stems
date Show system date
uptime Show uptime
whoami Show your username
man command Show manual for command

Directory option

pwd Show current directory
mkdir dir Make directory dir
cd dir Change directory to dir
cd .. Go up a directory
ls List files

ls commands

-a Show all (including hidden)
-R Recursive list
-r Reverse order
-t Sort by last modified
-S Sort by file size
-l Long listing format
-1 One file per line
-m Comma-­sep­arated output
-Q Quoted output

Search Files

grep pattern files Search for pattern in files
grep -i Case insens­itive search
grep -r Recursive search
grep -v Inverted search
grep -o Show matched part of file only
find /dir/ -name name* Find files starting with name in dir
find /dir/ -user name Find files owned by name in dir
find /dir/ -mmin num Find files modifed less than num minutes ago in dir
whereis command Find binary / source / manual for command
locate file Find file (quick search of system index)

File operations

touch file1 Create file1
cat file1 file2 Concat­enate files and output
less file1 View and paginate file1
file file1 Get type of file1
cp file1 file2 Copy file1 to file2
mv file1 file2 Move file1 to file2
rm file1 Delete file1
head file1 Show first 10 lines of file1
tail file1 Show last 10 lines of file1
tail -f file1 Output last lines of file1 as it changes

Process management

ps Show snapshot of processes
top Show real time processes
kill pid Kill process with id pid
pkill name Kill process with name name
killall name Kill all processes with names beginning name

File Permissions

chmod 775 file Change mode of file to 775
chmod -R 600 folder Recurs­ively chmod folder to 600
chown user­:g­roup file Change file owner to user and group to group

Tuesday, 23 April 2013

Interfaces in Java

Having learned what are abstract classes and functions we are all set to dig a bit more into polymorphism. Interfaces are based on these two features.



We saw Java does not support multiple inheritance to avoid the problem of Deadly Diamond of Death. To provide functionalities that multiple inheritance support Java provides Interfaces. Interfaces are entities just like classes. We define them one per file and file name must be same as the interface name.

   Synatx for creating an interface is as follows -

    public interface interfaceName{ //code goes here}

Example of an interface is as follows -

public interface Animal{
    public void move();
}


Couple of things to note in Interfaces
  • All functions in an interface are public and  abstract by default. This means all interface contains is function prototype. It's concrete implementation will be in the class which implements it.Note the semicolon after the function. No implementation.
  • For sub class inheriting from super class we say classA extends classB whereas for interfaces we say classA implements interfaceB.
  • You can define variables in interfaces but they are final and static by default.
  • You cannot create objects of interfaces. You can think them as abstract classes for your understanding because after all it contains abstract functions and we know that non-abstract classes can't have abstract function. only abstract classes can.
 Note : If you have an abstract class will all abstract methods as per convention you should go for interface rather than abstract class (As per Java specs).
Let take a look at any class that may implement interface defined above.

 public class Dog implements Animal{
    public void move() {
        System.out.println("Moving..");
    }

    public static void main(String args[]) {
        Animal animal = new Dog();
        animal.move();
    }
}


output Moving..
as expected.


Note in above code we have made use of polymorphism. We are using a Animal reference to refer to a Dog object. All rules of polymorphism will follow.

Note :  We can use interface as polymorphic references in method arguments and return types. Meaning you can have a method that return Object of type Animal. At runtime you can return any class Object that implements Animal interface.


Why are the advantages of using interfaces?

  • A class can implement multiple interfaces but can extend only one class.
  • Interfaces can be used across inheritance trees. This means a class from one inheritance tree can implement interface from another inheritance tree.
  • Advantages of polymorphism follows.
  • In later parts of tutorials on Java you will realize generics , design pattens etc depend on this.

One of the OOP principle is "Code for the interface not for implementation" meaning always thing how to design your interface then to worry about your implementation.

Note :  If you have abstract class with all abstract methods (no non-abstract methods) it is better to go for an interface.

Sunday, 21 April 2013

Why do we use Linux?


We tell people we use Linux because it's secure or it's free or it's customizable or it has excellent community support.
     But all of this is just marketing bullshit. We tell that to non Linux users because they wouldn't understand the real reason and when we say those false reasons enough we might even start to believe them ourselves.

   But deep underneath , the real reason remain - We use Linux because it's fun! It's fun to tinker with your system. It's fun to change all the settings, break the system, then have to go back to recovery mode to fix it.It's fun to have a 100 distros to choose from.It's fun to use command line.
    Let me say that again - it's fun to use command line.No wonder non Linux users won't understand.

     The point with Linux fan is we use Linux for it's own sake.Sure, we like to get work done. Sure, we like to be secure from virus.Sure, we like to save money but these are only the side effects.What we really like is playing with the system, poking around and discovering fascinating facts about the software that lies underneath it.
 

Saturday, 20 April 2013

Interview Question #9 Why multiple inheritance is not supported by Java?

Multiple inheritance has a problem known as The Deadly Diamond of Death.

Refer to the following diagram to understand The Deadly Diamond of Death-


Explanation -  

     Suppose you have class C which extends two classes A and B.Lets say A and B both have a function with same prototype eg. public int getData(). Now if we create an object of class C and call the function i.e ObjC.getData() which function will be called? Decision is ambiguous unless we have set some rules and priorities. To avoid such ambiguity Java does not allow multiple inheritance.


A language that allows Deadly Diamond of Death can lead to some ugly complexities, because you have to have special rules to deal with the potential ambiguities.

Java is designed to be simple. Java (unlike C++) protects you from having to think about Deadly Death of Diamond.

To provide similar functionality Java provides interfaces.
So Java can implement two or more interfaces but can extends only one super class.
t> UA-39527780-1 back to top