Wednesday, 29 November 2023

Let Me Tell You About Them Coding Black Females!

 I know you have NOT been wondering where I’ve been these past few months or why I haven’t been posting. 

I have spent the past 6 months completing a Java course with and amazing organization called Coding Black Females founded by the one and only Charlene Hunter. After life took an unexpected turn at the end of last year, I slowed down on attending tech events, my first one was in April 2023 for Coding Black Females launch event for ‘Entry to Tech’ with the UBS Bank. Little did I know when I arrived at the event that we were there to listen to the fantastic program that they were running that would teach an in-depth guide to Java over 28 weeks. I decided to throw my hat in the ring and see what happened. Stepping out of our comfort zone remember. I was blessed enough to be one of the few amazing women to win a place on the course and have been on a journey ever since. The course is taught with the help of an amazing group of teachers, with self-learning, lessons from the sponsored employer and assessments that showcase live learning throughout. 


I have previously learned JavaScript MERN with another amazing group of people and if you don’t know by now, check out Leon Noel and his 100Devs. But allow me to tell you that Java is a bigger Badder older brother, going from JS to Java was like hitting a wall, but I climbed it and still continue to do so. I’ve had one hell of a journey over the last 6 months so let me tell you a little bit about it. 

JavaScript / Java only difference is the name, right? 

So coming from a JavaScript to Java background let me tell you, they sound alike but are actually very different especially when it comes to handling data types. Java prefers the elegance of static typing. Picture this: in Java, you define your variables and their types upfront and stick to them throughout. See Java is statically typed, meaning variables must be declared with a specific data type that cannot change during execution. This ensures strict adherence to data types—integers, strings, etc.—right from the start. For example, when creating a variable to hold an integer in Java, you explicitly define it as an int. Think of it like picking a lane and staying in it. This rigid structure at the start helps catch errors early and keeps the codebase sturdy. 

On the other hand, JavaScript loves the freedom of dynamic typing. You want a variable to hold a number? Great! 10 minutes later, it can be a string or an array—no rules. JavaScript is dynamically typed, allowing variables to hold different types of data over time. This flexibility can make coding faster and more adaptable initially, as variables can be assigned any type without strict predefinition. However, this dynamic nature can lead to unexpected errors during execution, especially when handling complex programs where data types might change unexpectedly. 

What are you even Talking About? 

In Java, think of data types as labels for different kinds of information. Integers, strings, and booleans—each has its own box. Then come collections. You've got your ArrayLists, Stacks, HashMaps—collections are like containers holding a bunch of items. 


ArrayList? It's a type of collection that can change size as you add or remove things, but Java wants you to specify what goes in there. No one-size-fits-all here. If you want a more fixed collection, there's an array, but it's less flexible once declared.

Lets have a look using that classic interview question FizzBuzz. You know the problem count the numbers from 1 to ‘n’, if number is divisible by 3 type “Fizz”, is its divisible by 5 type “Buzz” and if divisible by both 3 and 5 type “FizzBuzz”, otherwise type the relevant number. 

So in JavaScript its relatively simple              

  1.  Line 3 - Create a method for our puzzle to go in. 
  2. Line 4 - We declare our array and initialize it with variable. 
  3. Line 5 - We start our loop declaring ‘i’ with ‘let’, detailing our end point and conditional increment. 
  4. Lines 6, 8, 10, 12 - I've decided to use an if else conditional so it's easier to see. Depending on what our conditions are. 
  5. Notice when labelling our conditionals, we use 2 ‘==’ and not 3, why? Because Java isnt programmed to have 3 ‘===’ so if you use it your IDE will start complaining. 
  6. Lines 7, 9, 11, 13 - We push the relevant outcome that meet the terms of our conditional to our array. 
  7. Line16 - We console log our result. 
  8. Notice here that although it is better practice, the semi colons at the end of each line of code baring those with a curly brace is kind of optional and our code will still execute with or without them. 
  9. console.log(arr)

Output:  [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz', 16, 17, 'Fizz', 19, 'Buzz'] 


Now let's do the same thing but in Java
 

  1. Line 1 – we declare out package, this is essential in making this work. 
  2. Line 6 – declare your class and label its visibility, this class is public so it can be reached from anywhere inside of the package, but we also have private classes 
  3. Line 8 – so here we declare the access level of the method and the return type. Then we tell the program that it’s the main method entry point for Java to do its thing and we take an array of strings as an input. 
  4. Line 11 - We once again declared our array and created a new one.  This time I have chosen a List of type ArrayList  
  5. (lines 3 &4 - We have to import List and ArrayList in order for us to use “import java.util.ArrayList; import java.util.List;” 
  6. While we declare our ArrayList we also have to tell it what type of data it will hold. So FizzBuzz means that it will hold integers and strings, since Java doesn’t allow you to be able to have a ‘one size fits all type of array like JavaScript, we have to use an Object type. <Object> 
  7. Line 12 - Once again, we start our loop, instead of ‘let’ we use ‘int’ so we let Java know we are incrementing through and index of integers. 
  8. Lines 13, 15 , 17, 19 - We set out our terms in our if else conditional. 
  9. Lines 14, 16, 18, 20 - We ‘add’ the relevant outcome to our array. Now depending on what type of collection I chose some of them could still accept pushing and popping as with JavaScript. An ArrayList is not one of the ones that accept this. 
  10. Line 23 - Lastly, we System.out.println(arr); our outcome and when we compile it runs in our terminal. 
  11. *Note*that all lines of code not ending with curly braces MUST have semicolons or your code doesn’t run
  12. Now to be fair lines 11 – 24 – could and should be wrapped in a static method that allows main to access it when called, but we have done this in such a way that it isn't needed. Our outputs for both of these are very much the same and can be condensed down into shorter code but the way that you get there is a little bit different. 


Output: [1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17,  Fizz, 19] 

28 weeks ago I was OBLIVIOUS to this, but CBF and UBS have sparked my imagination and taught me so many new lessons. I can’t wait to share more with you! 

If youre a coding black female in, this is our tribe! Join us!!!



No comments:

Post a Comment

Let Me Tell You About Them Coding Black Females!

  I know you have NOT been wondering where I’ve been these past few months or why I haven’t been posting.  I have spent the past 6 months co...