public String javaBlog(String blog){ return blog}

Johnson Kow
3 min readMar 24, 2021
Photo by Tracy

It has marked just over a year since I’ve picked up a keyboard to transition into the magical world of software engineering and it’s been a humbling experience so far. This year, I’ve started a job with a company that uses Java which forces me to learn it.

Here is my biggest caveat with Java and I don’t know if I’m in the minority here for this but Java is so explicit. Unlike Javascript where you can define a variable and then initialize it to whatever datatype, java requires datatype initializing. Whats that mean? Take a look below.

Javascript 
let a = 6;
Java
int a = 6;
--------------
Javascript
let name = "Johnson";
Java
String name = "Johnson";
--------------
Javascript
let linkedList = new LinkedList();
Java
LinkedList linkedlist = new LinkedList();

In my mind, it’s just too repetitive. I enjoyed that javascript new exactly what it would be after variable initialization and declaration. One other thing is that you cannot forget to use the semicolon in Java. It’s meant to define that you’ve moved on to a new line but it would be nice if it weren’t necessary. Many times I get an error because I’m just missing a semicolon.

One other thing I’ve noticed in Java is that method syntax is much more involved. Let’s take a look at those difference so that you can see what I’m talking about.

Javascript 
function addNumbers(num1, num2, num3){};
Java
public void addNumbers(int num1, int num2, int num3){};
Java
public int addNumbers(int num1, int num2, int num3){};

When creating a method inside of Java, you need to create an access modifier, the return type, and the name whereas in Javascript, you really just need to worry about the name. I’ve set two examples for Java, one using the void keyword and another using int.

The return type matters as you need to tell java wether the method should return something or not. In the first case (void), nothing needs to be returned but in the second case (int) an integer must be returned. Also notice how inside the parameters you need to include the datatype of each parameter.

Let’s talk numbers. It’s something I’m still getting use to but there are various types of datatypes for numbers all of which differ in terms of byte sizing. You have your int, double, short, long, float, and I’m sure I’m forgetting one or two. These differ in byte size and how they will be initialized. Also, you need to be aware of implicit type conversioning meaning int’s can become long can become float can become double but not the other way around unless mentioned explicitly. If you go from a larger type to smaller without explicit conversioning, you will get an error. What.a.headache.

// I know I Exaggerated values but this is to prove a point (to all you Java lovers)Java 
int num1 = 4;
long num2 = 31423235235L;
float num3 = 3.14f;
double num4 = 34214342354534;
int num5 = (int) num4; // Explicit Conversion
Javascript
let num1 = 4;
let num2 = 31423235235;
let num3 = 3.14;
let num4 = 34214342354534;
let num5 = num4;

Creating an array in Java is something I don’t know if I can get use to because if I do, I’ll forget that Javascript is so much more lenient on it. To create an array, there are a few way of doing it. You can initialize a new array or declare and initialize it.

Java
long[] restaurantContacts = {1234567L, 12345678L, 1236789L};
OR long[] restaurantContacts = new long[3];
restaurantContacts[0] = 1234567L;

You can also use the ‘new’ keyword with javascript but needing to explicitly mention the size and types that it expects to hold is pretty insane to me. AND they use curly braces for arrays which almost feels like I’m breaking an unspoken law in programming. I enjoy the free range that Javascript provides because I can make an array that looks like this [“Johnson”, 85, “Hello there”]. These restrictions are things I’ll need to get use to .

If it seems like I’m not a fan of it, I’m not but only time will tell. Thanks for reading!

--

--

Johnson Kow

Software Engineer based out of NYC. Learning more about programming everyday 👍