Whew! It's about time that I re-visit my beloved blog before Weebly start thinking that this blog space has been abandoned.
(Thank God, it's not a pet. AHAHA, I'd love to elaborate on how partial I would be if it's actually a living thing and how strict I am when it comes to my cat's meals... speaking of cat food, each pet parent has his own feeding style. Some like to stick to all-dry food, some believe in the benefits of raw food, while others only feed their pets with wet food due to various preferences or their pets' unique biological features, health histories or responses to certain foods. I respect my fellow pet parents' feeding styles, but it is always a good reminder that cats need more water intake if they are only fed with dry food, or to make it a habit to brush their teeth regularly if they are on an all-wet food diet. I like to give my cat one-half can of wet food in the morning and one-half bowl of dry food in the evening with occasional healthy treats for good behavior. As for raw food, well, I'm not open to it just yet. Anyway, we also need to ensure that our cats' meals have complete nutrition esp. for cats who are 6 yrs. old and above. Pet food brands also matter. Read the ingredients carefully! OK. This is not my original topic so I'll stop it here before it gets any broader. My salute to our dearest Vets out there who take their time to educate people on proper pet care for free; I'm one of the blessed ones who learned so thank you. Pet shops in the neighborhoods should definitely schedule more workshops with free consultations so that more people can attend. (^_^) This is supposed to be about JAVA and Python, so let's get started.)
A little introduction about the two: James Gosling's JAVA of Sun Microsystems is a compiled language that, as one of my University instructors described, is a "strongly-typed" language which requires a high level of specification in order for the computer running a JVM (JAVA Virtual Machine) to be able to understand you, and the technical terminology for this is called static typing. Python, on the other hand, is a "loosely-typed" scripting language that somehow resembles JavaScript and can be interpreted by the computer with ease so long as you don't break the syntax rules, although your results still depend on your code's logic. This is called dynamic typing. An example of this is the immediate availability of variable use without the need to specify their data types. You'll see more of this in a moment. What's underneath the classification of languages can be a broad topic and is outside the scope of this blog post so I'll save that for the future, if God permits. Appdynamics.com describes JAVA as having an "execution model" that "is more machine-centered than purely interpreted languages, such as Python and Perl."
Keeping up with the trend, Python's popularity has, without a doubt, increased over the last 2 years that made numerous headlines in many technical articles across the web that programmers like myself can consider valid (judging the article by its content alone and not where it came from or which organization it represents). The claims were astounding, but they were backed up by some statistics data and can be reflected in your daily life especially if you're in-sync with the technical community. Let me share some of these with you:
I've also come across some 2017 Youtube videos of programmers who included Python in their "Top 10" list of programming languages, and some of Python's best strengths were emphasized: low learning curve, build more with less code a.k.a. "less is more", readability and flexibility. Some even talked about the future outlook of JAVA. Hmm. I think that until we can produce a "machine-centered" language that we won't have to re-write when we jump from one operating system to another that's at par with JVM's efficiency, JAVA will remain alive and kicking.
That being said, JAVA's capacity to distinguish the visibility of its class objects through its modifiers comes into play when building app security, whereas in Python, as of today, all objects are available for public and can be seen by all the other objects in your codebase. There are pros and cons when choosing a programming language for a project but ultimately, the basis of your choice should come down to 2 major criteria: purpose and resources.
(Thank God, it's not a pet. AHAHA, I'd love to elaborate on how partial I would be if it's actually a living thing and how strict I am when it comes to my cat's meals... speaking of cat food, each pet parent has his own feeding style. Some like to stick to all-dry food, some believe in the benefits of raw food, while others only feed their pets with wet food due to various preferences or their pets' unique biological features, health histories or responses to certain foods. I respect my fellow pet parents' feeding styles, but it is always a good reminder that cats need more water intake if they are only fed with dry food, or to make it a habit to brush their teeth regularly if they are on an all-wet food diet. I like to give my cat one-half can of wet food in the morning and one-half bowl of dry food in the evening with occasional healthy treats for good behavior. As for raw food, well, I'm not open to it just yet. Anyway, we also need to ensure that our cats' meals have complete nutrition esp. for cats who are 6 yrs. old and above. Pet food brands also matter. Read the ingredients carefully! OK. This is not my original topic so I'll stop it here before it gets any broader. My salute to our dearest Vets out there who take their time to educate people on proper pet care for free; I'm one of the blessed ones who learned so thank you. Pet shops in the neighborhoods should definitely schedule more workshops with free consultations so that more people can attend. (^_^) This is supposed to be about JAVA and Python, so let's get started.)
A little introduction about the two: James Gosling's JAVA of Sun Microsystems is a compiled language that, as one of my University instructors described, is a "strongly-typed" language which requires a high level of specification in order for the computer running a JVM (JAVA Virtual Machine) to be able to understand you, and the technical terminology for this is called static typing. Python, on the other hand, is a "loosely-typed" scripting language that somehow resembles JavaScript and can be interpreted by the computer with ease so long as you don't break the syntax rules, although your results still depend on your code's logic. This is called dynamic typing. An example of this is the immediate availability of variable use without the need to specify their data types. You'll see more of this in a moment. What's underneath the classification of languages can be a broad topic and is outside the scope of this blog post so I'll save that for the future, if God permits. Appdynamics.com describes JAVA as having an "execution model" that "is more machine-centered than purely interpreted languages, such as Python and Perl."
Keeping up with the trend, Python's popularity has, without a doubt, increased over the last 2 years that made numerous headlines in many technical articles across the web that programmers like myself can consider valid (judging the article by its content alone and not where it came from or which organization it represents). The claims were astounding, but they were backed up by some statistics data and can be reflected in your daily life especially if you're in-sync with the technical community. Let me share some of these with you:
- Python 'Fastest-Growing Major Programming Language' Says Stack Overflow (Adtmag.com)
- Python Tops 2017’s Most Popular Programming Languages (ExtremeTech.com)
- Python grabs top honors as 2017's most popular language, Go growing rapidly (Neowin.net)
I've also come across some 2017 Youtube videos of programmers who included Python in their "Top 10" list of programming languages, and some of Python's best strengths were emphasized: low learning curve, build more with less code a.k.a. "less is more", readability and flexibility. Some even talked about the future outlook of JAVA. Hmm. I think that until we can produce a "machine-centered" language that we won't have to re-write when we jump from one operating system to another that's at par with JVM's efficiency, JAVA will remain alive and kicking.
That being said, JAVA's capacity to distinguish the visibility of its class objects through its modifiers comes into play when building app security, whereas in Python, as of today, all objects are available for public and can be seen by all the other objects in your codebase. There are pros and cons when choosing a programming language for a project but ultimately, the basis of your choice should come down to 2 major criteria: purpose and resources.
Now, for the fun part ("fun" refers to what I really wanted to write about). In order to visualize this concept, let's make the simplest possible example of a table comparison based on these languages' most recent versions used as of today: 8 (not 9!) for JAVA, and 3.6 for Python.
1. For-Loop
a.) Start at 1st Index, Stop at 10th Index (0 to 9)
1. For-Loop
a.) Start at 1st Index, Stop at 10th Index (0 to 9)
JAVA 8 for(int i=0; i<10; i++) { // your code here } | Python 3.6 for i in range(10): # your code here |
b.) For each item in the list
JAVA 8 int[] numbers = {1,2,3,4,5} for(int item: numbers) { // your code here } NOTE: This feature resembles PHP's foreach. Kudos to JAVA for finally adapting and having made this improvement. JAVA 8's Streams is also noteworthy as its chaining capacity allows for different types of operations on a single element in a list, or a collection. | Python 3.6 numbers = [1,2,3,4,5] for item in numbers: # your code here |
c.) Start at 20th Index, Stop at 2nd Index, Skip by -2 Steps (from 19 to 1)
JAVA 8 for(int i=19; i>0; i-=2) { // your code here } | Python 3.6 for i in range(19,0,-2): # your code here |
2. Arithmetic
a.) Exponent: 5 to the power of 3
a.) Exponent: 5 to the power of 3
JAVA 8 Math.pow(5, 3) - or - 5 * 5 * 5 | Python 3.6 5**3 - or - math.pow(5,3) - or - 5 * 5 * 5 |
b.) Find the quotient rounded downward to its nearest whole number.
JAVA 8 Math.floor(5/2) - or - int op = 5 / 2; - or - double op = 5 / 2; - or - 5 / 2.0 - or - 5.0 / 2 - or - double op = 5 / 2; int op2 = (int)op; | Python 3.6 5 // 2 - or - math.floor(5/2) |
3. Strings
a.) Check if 'w' exists in 'sunflower' and display the boolean result
a.) Check if 'w' exists in 'sunflower' and display the boolean result
JAVA 8 String flower = "sunflower"; System.out.println(flower.contains("w")); | Python 3.6 flower = "sunflower" print("s" in "sunflower") |
b.) Find index of 'w' in "sunflower" and display the result
JAVA 8 String flower = "sunflower"; System.out.println(flower.indexOf("w")); | Python 3.6 print("sunflower".index('w')) - or - flower = "sunflower" print(flower.index('w')) |
4. Defining Methods
a.) Create a method that prints "Hello, World!"
a.) Create a method that prints "Hello, World!"
JAVA 8 public static void printHelloWorld() { System.out.println("Hello, World!"); } | Python 3.6 def printHelloWorld(): print("Hello, World!") |
5. Lists
a.) Print every 2nd element of a list. Start at 1st element. Stop at 5th element. (0 to 4)
a.) Print every 2nd element of a list. Start at 1st element. Stop at 5th element. (0 to 4)
JAVA 8 List<Integer> numbers = Arrays.asList(8,145,32,47,98); List<Integer> filtered = numbers.stream() .filter(i -> numbers.indexOf(i) % 2 == 0) .limit(3) .collect(Collectors.toList()); filtered.forEach(System.out::println); - or - int[] nums = {8,145,32,47,98}; for(int i=0; i<nums.length; i+=2) { System.out.println(nums[i]); } | Python 3.6 nums = [8,145,32,47,98] print(nums[0:5:2]) - or - nums = [8,145,32,47,98] print(nums[:5:2]) |
...and the list goes on. There's a couple more key differences but I will wrap it up here and leave the rest for you to explore.
Happy Reading Week! (@__@)
Happy Reading Week! (@__@)