Regular Expressions in Java

This semester, I have a class in Java, specifically, Java EE. It’s about time I have another programming class. It’s been 2 years already since my last class in Java. So anyway, for our first exercise, the professor asked us to make a basic Java application. The requirement for the application is to use classes and packages. The classes should have private attributes, public methods, getter and setter methods. I figured I should try using regular expressions since one of the class attributes’ setter method seems to be screaming for one....

November 25, 2010 · 4 min · 796 words

Introspection in Python

I just finished reading a chapter about Introspection in the book that I’m reading. Learning the concept of introspection and doing it in Python is the trickiest challenge I’ve come across so far. Introspection, by definition, is determining and manipulating objects at runtime. The idea is that we know that there are objects that will definitely come across our program during run-time. We don’t know what they are exactly, but we want to do something about them in case our program encounters them....

November 3, 2010 · 8 min · 1583 words

Python and its weird boolean logic

I found some pretty interesting keywords in Python: and and or. Coming from a C background, this is somehow new to me since I’m used to using symbolic operators for boolean logic (&& and ||). One of the things I noticed was how Python interprets these keywords: 1 'a' and 'b' It returns ‘b’. Surprised? I know I am. One look and I immediately thought it would return something similar to True since both values aren’t null....

November 2, 2010 · 2 min · 238 words

Python and its different way of type casting

I tried to make a Fibonacci program in Python to experiment with getting user input, displaying output and type casting. This was the code that I came up with at first: 1 2 3 4 5 6 7 8 9 10 11 def fib(n): print 'n =', n if n > 1: return fib(n - 1) + fib(n - 2) else: print 'end of the line' return 1 n = raw_input('Input number: ') int(n) fib(n) When I tried running the program in the CLI, I have been successful in getting the user input....

November 1, 2010 · 3 min · 573 words

Optional Arguments, a gift from heaven

I’ve been messing around with functions in Python. One neat feature that I came across are optional arguments. Here’s some code that I’ve written to explain more about optional arguments: 1 2 3 4 5 def foo(length, bar = 5, foobar = 10): """A sample function demonstrating optional arguments. Takes 3 integer objects as its arguments""" print "Length is %d\nBar is %d\nFoobar is %d\n" % (length, bar, foobar) As with any other language out there, you can set default values for certain arguments in case they aren’t mentioned in a function call....

November 1, 2010 · 2 min · 232 words