Python vs. Java – Part 1

I am comparing these two languages with some simple coding.

Hello world

  Java

 public class HelloWorld   {  
  public static void main (String[] args)   
    {       
       System.out.println(“Hello, world!”); 
     }
}

Python 

print “Hello, world!” 

For Loop

 Java 

//print the integers from 1 to 100
    for (int i = 1; i < 100; i++) 
     {  
         System.out.println(i);
     } 

//Print a name from name list (using  java.util.Vector) 

  for (int i = 1; i < stringList.size(); i++)
   {    
     System.out.println(stringList.elementAt(i));
   } 

Python 

       # print the integers from 1 to 9

for i in range(1,10):  
    print i 

//Print a name from name list 

for name in name_list:    
    print name

Remove leading and trailing whitespace from string str

   Java
       str.trim() 
   Python 
      
str.strip() 

Remove leading whitespace from string str 
   Java
       (Not available) 
   Python 
      
str.lstrip()   

Remove trailing whitespace from string str 
   Java
       (Not available) 
   Python 
       str.rstrip()

 Python is compared with Java at www.python.org.

Several other valuable comparison here

Advertisements

One Response to Python vs. Java – Part 1

  1. girish says:

    hi
    watch http://www.canaravideo.com which has simmillar topic video clippings

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: