Monday 30 November 2009

Unix Shell Differences

To check the differences between various types of shells of Unix, I searched on net and found something good. This doesn’t give everything in detail but gives some picture. History given here is good.

http://www.faqs.org/faqs/unix-faq/shell/shell-differences/

The list of shells that are developed till now are -
bourne shell – sh – input language: bourne shell language
c shell – csh - input language: c language
T shell – tcsh - input language: c language – enhanced c shell
Korn shell – by At&T – ksh – POSIX compatible - input language: bourne shell language
Bourne Again shell – by GNU – bash – POSIX compatible – input language: bourne shell language
Ksh and bash are almost similar – but the first is not free and later is free.
RC – it got enhanced later to es.
Zsh – the recent shell

(Next time something in detail about every shell)

We can also find some of the shells in detail over here on the same site. Also I got some harry potter sites. ;)

Also, the file name completion, command completion; it is called TENEX style completion. I didn’t know this.

Monday 23 November 2009

varargs

- This is about varargs in Java. They are called Variadic arguments.And the function having such arguments is called Variadic Function.
- They are to be used when you need to use unknown number of arguments of same type.
e.g. log function where you need to print a string which can be formed of any number of string objects.
- This argument must be the last parameter of a method.

For examples -
click

This works nice in case of polymorphism.


public class Test
{
public static void fun(Parent... args){
for (Parent i : args){
i.setA(5);
System.out.println("a is " + i.getA());
}
}


public static void main(String args[])
{
Parent p = new Parent();
ChildA a = new ChildA();
ChildB b = new ChildB();
fun(p,a,b);
}
}

Thursday 20 August 2009

Small tip

A small tip for me while learning any tool:
Check Features and Release notes of the tool on internet and then accordingly try doing them.

Tuesday 14 April 2009

Hiding Vs Overriding! Interesting!!

package test;

class FieldHiding { 

public String InstanceField = "Instance Field in SuperClass"; 

public static String StaticField = "Static Field in SuperClass"; 

public static int StaticIntField = 1; 

}

public class FieldHidingDemo extends FieldHiding { 

public String InstanceField = "Instance Field in SubClass"; 

public String StaticField = "Static Field changed to Instance Field in SubClass"; 

protected String StaticIntField = "public static int in super class -> protected String in subclass";


public static void main(String[] args) { 

FieldHiding fieldHiding1 = new FieldHiding(); 

FieldHiding fieldHiding2 = new FieldHidingDemo(); 

FieldHidingDemo fhd = new FieldHidingDemo();


System.out.println(fieldHiding1.InstanceField); 

System.out.println(fieldHiding1.StaticField); 

System.out.println(FieldHiding.StaticField); 

System.out.println(fieldHiding1.StaticIntField); 

System.out.println(FieldHiding.StaticIntField); 


System.out.println(fieldHiding2.InstanceField); 

System.out.println(fieldHiding2.StaticField); 

System.out.println(fieldHiding2.StaticIntField); 


System.out.println(fhd.InstanceField); 

System.out.println(fhd.StaticField); 

System.out.println(fhd.StaticIntField); 

}


This example is from geekexplains.blogspot.com

 

Fields and static methods cannot be overridden. They are just hidden.

 

What is overriding?

Binding is done depending upon the type of calling object, not on the type of reference used.

 

And what is hiding?

Binding is done depending upon the type of reference used, not on the type of calling object.

 

Field Hiding:

We can narrow or widen the visibility of variables. i.e. a public variable in superclass can be made private in subclass and vice-versa.

 

Static Method Hiding:

We cannot narrow the visibility of functions. But we can widen.

 

Good link for this. Specially the last question. ;)


Update:

In java, non-static methods are always overridden and static methods are always hidden when they are redefined in subclass. 

But in C#, there are options to either hide or override the method. It is possible with some combinations of keywords new, virtual and override.

Saturday 28 March 2009

Playing with Exception Handling

This is the conversation between Guido and Pranali. Recently I saw the movie - Life is Beautiful. And Guido is the character from that movie. For now he is the friend of mine and going to discuss Exception handling with me. Yes, it appears to be very funny!! But why can't I use this name? So lets go ahead with the conversation. Those who feel I am crazy for them - Yes, I am!! :-)


Guido: Bongiorno Princepessa!!
me: :-)

Guido: Why have you kept mum since long? Why aren't you speaking anything about your technical journey which you started few days ago? You were reading something about exception handling in Java. Can you elaborate why does it exist in Java?
me: To handle risky behaviour of your code.

Guido: And What do you mean exactly by risky behaviour?
me: It is something like - "If we are not sure whether things will go as we want them to, then it's a risk. It is called exception in the world of programming.Any code can result into this unwanted behaviour. This is called risky behaviour.

Guido: OK, got. What do you do to handle this risky behaviour?
me: I make my compiler to examine some part of code carefully and if anything unwanted happens in that part, I make the compiler to catch the risk(exception) which is occurred.

Guido: Catch the risk? Is it some ball that you are making compiler to catch it? And who is throwing that?
me: For now consider it is an entity. My function is throwing it and compiler is catching it. My Compiler has very well fielders that it doesn't allow the exception to just run away after harming my application.

Guido: Wow!! Cricket? or Cops and thief? :P Jokes apart!! So you mean compiler will pick up the exception if it occurs. But then what will it do with that?
me: If that exception is handled in the same function itself, the handling part will be executed and rest of the functioning is continued.

Guido: What do you mean by handling?
me: Oh, handling is the mechanism to save the application after the exception occurred. You can say it is a set of some instructions those will be followed after the exception has occurred.

Guido: Interesting!! When thief steals something from you, you need to follow some steps to recover yourself from the harm occurred. Can we make this analogy here?
me: Yes Guido!! You are on the right track.

Guido: Great!! :-)
Now you said - "If that exception is handled in the same function itself, the handling part will be executed and rest of the functioning in continued." And if it is not handled in the same function, then?
me: Then the exception is thrown to the caller function. If it has the handling part, that will be executed. If not then again it will be given to the caller function. and so on...

Guido: ah, OK. Tell me, Can we compare it with the fielding of cricket? If the bowler(the function where exception occurs) can't catch the ball, then the fielder present at nearest peripheral part of it(caller function) will handle it. If he can't, the next peripheral fielder will handle it. And so on....
me: Exactly!!

Guido: Nah Nah!! Tell me first, if no fielder can handle it, then?
me: Then the ball goes out of the boundary!!

Guido: Please explain me technically now!!
me: Sure! See. Here, main() function acts like a fielder present at the boundary. If main() also doesn't handle it then the exception is not under the control of compiler. JVM will stop there itself.

Guido: OK. Got it!!
me: But Guido, remember whatever I told you about the journey of exception from function to the main function, it can happen only if every function on the way is throwing it. And every function on the way has to throw it, until exception is solved i.e. handled. Else compiler doesn't allow you to go ahead with the coding.

Guido: How Strict!!
me:It has to be. Otherwise your application will keep getting harmed with cruelty of risks.

Guido: Hmmm!! Right!!
So a function has to handle it or throw it. Right?
me:Yes! No function can keep the risk with it. To handle every risk, there are two options. Either you solve it or you just throw it. You can't live with the risk above your head. The same way function either handles it with the catch block or it just throws it. How logical it is!! This is also the principle of life. If you stay with the problem, you won't proceed further in life. If you throw it, you can delay the death. If you solve it, you can continue the happy living. Wow!!!!! I really love OOP for such analogies with the principles of life.

Guido: :-)
Now one more question!! There is a possibility that compiler wouldn't know whether exception will occur or not. e.g. If you have 2 variables a and b. You want to divide a by b. But the values of a and b are retrieved during run-time. While compiling how will the compiler know about it?
me: Well, this is called a runtime exception. You can throw them in your program, but compiler just ignores them. Hence they are also called unchecked exceptions.

Guido: A last question! Can we throw and handle multiple exceptions?
me: Yes. This is not analogous to cricket here. We can have multiple risk balls.

Guido: Still, La Vita e Bella!! :-)

Wednesday 18 March 2009

Types of Computers

I happened to read an article about Netbooks in the morning. And i did wiki on it. So it navigated me to Nettops. And this navigated to Tablet PC.

Desktop
Laptop = Notebook
Netbook = small sized less powerful laptop
Nettop = small sized less powerful desktop
Tablet PC = Looks like a slate. It may not have a dedicated keyboard. But we can use wireless keyboard for it. Usually, it has touch screen. So dedicated keyboard is not required.Slate seems to be somewhat same.
Convertibles = the base of a convertible attaches to the display at a single joint called a swivel hinge or rotating hinge. The joint allows the screen to rotate around 180° and fold down on top of the keyboard to provide a flat writing surface.(this definition is from wikipedia)
Hybrids = combination of Convertibles and slates.
Web Tablet = Provides more mobility than laptops. This is for wireless internet connection and information acces.
CrunchPad = Low cost Web tablet
Chumby = The Chumby is an ambient consumer electronics product made by Chumby Industries, Inc.. It is an embedded computer which provides Internet and LAN access via a Wi-Fi connection. Through this connection, the Chumby runs various software widgets.(again from wiki)

Now i am moving from general computers (to which we actually call computer) to any computing device. So i will stop here. But there so many of these. We can find them any time. :)

Wednesday 11 March 2009

Some random things about java

Those who know java well,this post is not for you. These things are in your blood. I’m sure you’ll get bored while reading it again.

1)Java version 1.2 onwards come in 3 flavours : Micro edition, J2SE : Standard Edition, J2EE : Enterprise Edition

2)To define a global method in Java or in any OOPL, we make it public and static. Whereas to define a global constant variable we make it public, static and final.

3)Dog d = new Dog();
Left part creates reference for the object of class Dog.
Right part creates the actual object. And assignment operator does linking between them. In java, there are all references to the objects of class.Everything is a reference, no actual variable.

4)Getters and setters are to protect private variables from getting accessed by unwanted entities and also to perform validation on the values set for variables when required. When I had started learning OOP, I had felt what timepass we do when we use get and set methods!! But there is always a reason . for everything. We just need to find it.

5)The difference between instance variables and local variables : Instance variables are declared inside class definition whereas local variables are defined inside a method definition. Instance variables need not be initialized before using them as they get assigned with default values. (number variables and char have 0, booleans have false and object references have null default values.) Whereas. Local variable must be initialized before their use.

6)Extreme Programming : Developing in Iterations. Agile Methodology. Galileo. All are similar. Amdocs is despensing Galileo technique.
For more information on it : Click or wiki on it.

7)import statements are not like include statements. They don’t put the while class definition in the file where we write import statement. They just allow us not to write the whole class name ( like java.util.ArrayList)

8) How javax came into picture? Why this x?
-> This is a nice story. I don’t want to write it here. If I start writing, I won’t be able to finish writing this post today. If I get some link I will post it here.

9)Why interfaces in Java? Why not multiple inheritance? Both answers are complimentary to each other. To avoid complexities java doesn’t support multiple inheritance and hence introduces interfaces.

10)When to use interface and when to inherit class? When the entity is something e.g.Dog is an animal so it extends class animal. But a pet dog does some functions. So it will implement interface – Pet. When you are something, that's because you inherit it. But when you do something that’s because you implement something.

Saturday 21 February 2009

Inheritance

As long as i keep writing this blog, i will say, I'm learning something new. Wow, so now i can count the days too when i'm in hibernation mode!! :D

I have started learning Java just few days back. I had heard that Java is slow. But that doesn't mean you should also be slow in learning, Pranali. :D

So, my topic is Inheritance today.

After reading inheritance from a highly recommended book of C++ (recommended by professors, by almost everyone i had met), I read it in Head First Java. I had never heard about this book, before coming in amdocs. So fast I am!! :D

I was aware of the biological definition of Inheritance.
As many OO concepts can be given analogies of the real world non-technical concepts, I used the same attitude while reading from the highly recommended book, but in rigid manner.
My Perception was -
1)We can inherit some class as children inherit from their parents.
2)There are few types of inheritance. Single , multiple etc.
3)If i want some feature in my class which is already present somewhere in other class, I will extend that class.
4)And yes, i knew one more thing - Inheritance is called Reusabilty too.

So i was aware of things in rigid manner. I never developed an insight for this concept. I don't even remember whether i had tried to develop that too. :(

After reading that highly recommended book around 3 times, I was very confident that i know OO, i know inheritance. But how wrong i was!! (This was the reason why i couldn't think of inheritance when i had done my first assignment in amdocs. )

In the third week of amdocs training , we happened to get a training for Java for single day. That day, i had heard a sentence from him which made me think of something else other than the rigid things i had stamped on my small brain. He had given a simple usual example of inheritance - Animals. Dog inherits Animal. i.e. "Dog is an animal." :)

Any technical reader now will think Its very simple and why the heck is this girl writing a big post for it??? I'd say, yes things are simple when we know them. But they are is inspiring when we come to know about them for the first time. :)

What a simple sentence! And changed my view towards inheritance. Now inheritance is not only above four things to me. Now i can think of the superclass, design it and can inherit it by a subclass. Not only when i'm told to do so. Anytime i will feel this will help me making my code flexible to change.

Now dog is an animal. My subclass is its superclass. But what's this? A child is its mother? its father? :O:O How is it possible??

Child is neither its mother nor its father. It is the entity which comes into picture when two other entities come together. This is multiple inheritance. Different from "IS-A" concept.
But why is it so different that when Inheritance is called "IS-A" relationship so widely? (This may be the reason why Java doesn't support it.)
So is multiple inheritance not a pure inheritance? If it is so, then what about the biological term? Doesn't child INHERIT from its parents? Or we can't give this analogy for OO inheritance? What is that?

This post will be updated when i will get answers to my questions.

Monday 16 February 2009

Tips for programming!!

While writing a code for a simple dotcom game on my own, I found few tips, which worked fine for my first code in java. I don't know whether they will work in future too.
They are -
1)Try to do things on your own first. Walking on unknown path with incomplete map, getting lost somewhere and finding back the way to home is fun rather than walking on a path told by someone else.

2)Don't implement the whole solution at the first step. Such code is hard to debug. Instead, write the simplest solution with least functionality and enhance it later. Make iterations.

3)Try to make it as flexible as possible. Show it to someone who will find bugs in it.
If you don't find anyone, think of the boss of Bob (or some other name) in first chapter of Head First Design Patterns.

Sunday 15 February 2009

Why This Techie Beginning?

After spending more than an hour in playing with the settings of new blog and getting nothing, I have begun to write for the beginning.

On wasting 4 years in college, then joining Amdocs, suddenly some day I realized that whatever I know about software that is equivalent to nothing. At one point I felt like giving up, but then I felt I should not be so harsh to myself. And then I gave myself one more chance to see if I can do anything more. I restarted from basics. And it is a fun!!

With guidance from real techie guys, I realized how wrong my way of learning was!! But now I can keep hopes.

As I am/was so used to my old habits of learning, in the course of acquiring new habits, many times I happen to forget the tips given to me by people or by myself. So to visualize those tips, I have started writing this blog which will remind me of those tips and will be strictly for technical things that I learn everyday. (Hope so. :D)