chaimoosh.github.io


Test Driven Development

I had an interview today and it was a really interesting experience. For starters rather than starting by asking anything about me and my background we just jumped straight into coding. What the interviewer did was just pair program with me doing some test driven development about implementing a set in Java. The way test driven development works is that rather than coding something and then testing to see if it works you write tests for what you want your program to do and then code to solve the failing tests. The advantages of doing it this way is that you’re less likely to have bugs and you know going in what you need to do. It also allows you to identify problems faster because you know what part of your code is doing what and if you have a bug it’s easier to find.


Some SQL Basics

The backend of every website contain some sort of data and that data is genrally stored in a SQL database. The way a SQL database works is that there are tables and in those table there are columns and in every column there are rows which have the data stored in them. It’s like an excel spreadsheet that you can think of every table as it’s own spreadsheet that has rows and columns and each of them. For example if you would have a tabel of cars you would have a column for the id of each car then you would have a column for the year then another one for the make and then anothe one for the model. The next step is that you probably have a few tables in each database and you want them to be able to interact with each other. There are multiple ways to do this and the way you do it really depends on what your needs are at any given time. Continuing on the example from before with the cars let’s say you had a list of dealers and each of those cars was by a specific dealer the way you would make that relationship is that you would add a column to the cars table that was called dealer id and every car would belong to a dealer and you would be able to find all the cars from a specific dealer by asking for all the cars with that dealer id.


Public, Private, and Protected

In Java when declaring a variable there are three specifiers you can choose from in deciding how that variable can be changed and where it can be changed. When you declare a variable in a class and you want to be able to access that variable in any other class directly and not through a setter or getter method you declare it public. If you want a variable to be accessible in child classes then you declare it protected and then you can access it directly in all child classes but not in any other class. If you want a variable to only be accessible in the class it’s declared and not be accessible anywhere else in the program then you declare it private. Generally it’s best practice to not let your variables be manipulated in any place where it’s not absolutely neccesary so when you’re able to declare it private you do and if not declare it protected and you use setters and getters to change it.


More Java Stuff

So as I progress in my learning Java I’m seeing how it’s less and less like Ruby. For starters you have to identify what any variable will be before you declare it which makes making variables much more tedious. For example if you want something to be an integer you have to write int myVariable= 4 rather than just declaring myVariable = 4 like you would in Javascript and if you decide do make that variable into some other data type it will give you this nasty looking error. Anotyher weird thing is that strings are not primitive data types in Java so if you want to create a string you have to make a new instance of the String class and intialize it so you can’t just declare a variable as a string.


Java Arrays

As I continue learning Java I’m starting to see how similar it is to what I’ve already learned in Ruby and Javascript. However there are some very apparent differences as well. At first glance it looks pretty similar to Javascript because the both use brackets to contain everything within functions and they use some similar words. But in some ways they are really different. Like when it comes to arrays in Javascript you can make an array and it can contain whatever you want like numbers or strings or objects but in Java when you declare an array you have to declare what type of values it will hold like if you want it to hold integers when you initialize the array you have to say it’s going to be an array of integers which is going to take some getting used to.