Posts

Showing posts from 2012

Playing with Numbers and Variables in Python

Image
We will try to learn how to do declare number types (integer, floating points) arithmetic expressions in python. Lets start: First we will try doing simple arithmetic expressions on numbers : For Addition, use '+' For Subtraction, use '-' For Multiplication, use '*' For Floating point division, use '/' For Integer division, use '//' For a raise to b, use a ** b. Lets demonstrate : if you want to find the speed of a train, the formula is : speed = distance / time Instead of repeatedly using values, you can use variables, lets try it out : And yes, you can use '#' to write comments whatever you write after '#' will not be processed!!! :)

Overriding toString() method in JAVA

Image
The toString() method returns the string representation that describes the object. Consider the following java program : --------------------------------------- class Demo001 { String name;  public Demo001(String name) {       this.name= name;  } } class Demo001Test { public static void main(String[] args) {      Demo001 d1 = new Demo001("Ravi");      System.out.println("Demo001 : "+d1);      System.out.println("Demo001.toString() : "+d1.toString()); } } ---------------------------------------- When we run it, we get a output similar to this :   This is not what we expected. We should be getting some valuable information from the object. This can be done by overridding toString() method. Example : ---------------------------------------- class Demo002 { String name; public Demo002(String name) { this.name = name; } public String toString() { return name; } } class Demo002Test { public static void main(String[]

First Python Program!

Image
Lets start with writing the program, all the beginners write : Oh.. Isn't it like really great! Your first python program. In IDLE!!! So how does this work??? Just type anything you want to, in single quotes (' ') and all that will be printed. No what if you want to print 'Hey isn't this a wonderful day?' OOPS... Syntax Error. Reason?? Python finds for the next '. So it thinks that the string is 'Hey isn' and since it is not able to decode what the next part of the string ie. t this a wonderful day?' is., so it throws the ERROR. (Observe the color of the content written inside print() ) How to fix it?? Many ways. Lets look at some : The use of double quotes (" ") and escape character ( \ in this case) did the trick! :)

Starting with Python!

Image
Hi... Download Python Go to this site. download the python version 3 or above . Just run the installable. Don't worry about the security. Just run it. Follow the steps for installation. They are really simple. Use "IDLE" to run python programs!

Member Inner Classes

Sub type of Inner Classes!!! It is defined at the same level as the member functions, constructors and fields. Instantiating object of the Member Inner Class : -Create an object of the outer class. -Using object of the outer class create object of the inner class. -If you want to use the inner class within the class ( say inside a method ), just create an object of the inner class there. Thats it! When we compile the java class ( OuterClass ) which has a inner class ( InnerClass ) , two class files are created : 1. OuterClass.class 2. OuterClass$InnerClass.class

Inner Classes

Inner classes is a subtype of nested classes. Inner Class is neither explicitly nor implicitly declared static. Types : 1. The Member Inner Class 2. The Local Inner Class 3. The Anonymous Class

Nested Classes in JAVA!

Nested Classes - since Java 1.1. - commonly used in event handlers. - encourages OOP. Nested classes can be : 1. Inner Classes 2. Static nested Classes

ls

ls is another basic command in unix. just type it and you will get the list of all the files, directories in your current directory (pwd) :> ls myDetails.txt websites.txt newDirectory But which of these are files? which are directories? here names suggest which is a file and which is a folder. But what if its more difficult to understand? simple... use the ls -lrt command. :> ls -lrt total 150000 drwxr-xr-x myself someusr 50000 Nov 1 2010 newDirectory -rw-r--r-- myself someusr 50000 Dec 10 2011 websites.txt -rwxr--r-- some1 someusr 50000 May 4 2012 myDetails.txt The first line tells us the total size of the current directory then as you can see, there are 6 columns that follow. The first column tell you whether it is a directory or a file and what permissions it has (read chmod later) The second column tells you about the user who has created the file/directory. The 4th column tells us the size of the file/directory. (in bytes) The next one tells on which date

pwd

the most basic command of unix is pwd. It displays the current directory. just type :> pwd :> /home/myname/currentDirectory So you know... where are you.. and where your changes will be applied