Yellowcop is everywhere.

It can see and hear everything. It can track where you are in the physical world and what you do in the virtual one. This panoptic surveillance network is legal and built into in every electronic…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Brownfields Web Dev Project

Lets start right at the beginning, at the version control tool. Gitlab is wtc preferred choice; working with Gitlab has so many advantages. Firstly, its easy to manage working with others as everyone can work on individual branch and then create merge requests. Secondly, it gives you the freedom to push your work (as many times as you’d like) without you worrying about losing the progress amongst other things.

Now that we have created a repository for our project, we can talk about the src directory, the source directory (src) stores all the code written by the programmer for the program. All classes, files and tests associated with the project need to be stored in appropriate directories inside the src directory.

src directory

From time-to-time we will work with work that needs some sort of library, or dependency inorder to build our project up. So the pom file will do this for us, it will store all details pertaining to this project inside it. If you do not have the dependencies installed in the project, then you can use maven install command and install the missing dependencies, or copy and paste the required dependency online.

POM file where all maven dependencies are stored

Its time now to see the project requirements, I’ve spilt it up into four parts, each part covering the different part of the project.

REQUIREMENTS:

All files that are not .java classes need to be stored in the resources directory, so “.sql” files will be found in a directory inside resources as shown below.

REQUIREMENTS:

A table called Genres was created that had two rows, one that took in a code and the other description, both were expected to be “NOT NULL”, meaning that at all times it can’t be empty, both were “TEXT” values and the code was “UNIQUE”, which means that there can only be one of this specific code stored inside the data base and the code was also the “PRIMARY KEY”, which is used to define a record and helps in retrieving the specific information you are looking for,

Now that our tables are created, its time to Insert data into them, I’ll give an example of either. For the Genres table “INSERT INTO Genres VALUES(“SCIFI”, “SCIENCE FICTION”);” Note that inside the .sql file the query wasn’t inside double quotation marks. You can insert as many times as you need to or like to.

So now an example of the Books Table “INSERT INTO Books VALUES(“Test Driven Development”, “PROG”);”, but wait why are there only two values inside the Books table, shouldn’t there be three. The reason is because the id has a value of “AUTOINCREMENT”, so it should increment automatically for us.

Now that we have inserted data into out tables, we can look for some data inside it, an example would be “SELECT * FROM Genres;”, which basically is saying, go into the Genres table and give me everything that is inside the table. The “*” means everything. The structure of the program is just below.

REQUIREMENTS:

The JDBC part was a little trickier than the plain SQL one, since this time the queries are merged inside of the Java code. So first, a function for a table needs to be created, so that we create multiple tables without having redundant code. The createTable() funtion takes in a parameter of an sql string, and then we do some validation inside the function to check whether the argument is a valid SQL query and if it is then we go ahead and create our try, catch statement that creates the prepareStatement.

After that we can create multiple tables with the same function, so our two tables will be created the same way that we did above but this time it will be in a function that calls the createTable() function.

Now that the tables are validated and created, we can insert data into them. With JDBC, everytime you want to create a command, you need to create a connection. There was data given, inside a Map Object that needed to be persisted into the database. Inside insertGenres(), create a prepareStatement connection, then a for each loop, that loops through the Genre Map Object, so because the key is a key and the value is a new Instance of another object class, it was easier to loop through the values of the Map. Then store the returned values into the database.

Now we retrieve the data from the database, I created a new List Objects that stored Genre Objects, after that a new PreparedStatement was created and we execute that statement, after that we get the ResultSet, and loop through the resultset, and extract the information and store them in appropriate variables, after that I will add the data into the list I created above, by first creating a new Genre Object, then the I return the list. Below is the structure of the program.

REQUIREMENTS:

Also note that all .html and .css files are stored in resources.

The first part was creating a very basic html page, with an unordered list inside. The second was creating a form from scratch, ensuring that all sections of the form were filled in and creating an input type with a value “Register”.

In the .html file you create links in the head tags, and link the .css pages. After that, it was adding padding, margin, background-color, font-family, border, border-radius to the appropriate classes and ids.

Inside the form, the passwords needed to have a minimum length of 8 characters, and have at one number, and one uppercase letter. So regex was hinted at, and so I added that into my form tags to ensure that all requirements were met.

A DBMS is a computer program that solves the problem of storing, retrieving, manipulating data by creating and maintaining a database.

Below are some data management issues:

DBMS solves these issues, by restricting access to the data and avoiding data redundancy amongst other things. Commercial databases are databases that one needs to pay in order to use their services but the upside to it is that not everyone has access to the code and database, it also has a high level of security.

There are different types of Data Base Management Systems, but the main ones are relational, network and hierarchical.

Relational databases:- relational data base stores information in a tabular 2D form in the database.

Network database:- relationship are more related, and this type of data base is able to store more complex relationships between the data.

Object database:- Data and relationship between data is represented in an object. Objects that have similar traits are stored together in a “class”. According to Wikipedia, a class “is an extensible program-code-template for creating objects, providing initial values for state and implementation of behaviour”, so basically its just a collection of objects that share the same attributes and similarities. Methods are then used to retrieve and store information.

There are many user end tools one can use for DBMS, the one I used was SQL, it was relatively easy to understand and create the tables and insert data or retrieve data as shown in my example below.

example of an SQL query

Relational Data bases Management system was used, as it was easier to use tables and link them together with a foreign key. Relational database offers some great perks, as it displays the information in 2D and its easier for a beginner at programmer working with data, to be able to see if the information is getting stored, deleted or manipulated.

PROJECTS TEST

TDD was used a method to guide the functionality of the programs. For each functionality, there is a test and if the function meets the required requirements then the test should pass but should there be a problem then the tests will fail.

test example
test output in the terminal

I am adding an example of a failing test as well.

If you notice the squiggly line underneath findBooksAndGenres(), it is an indication of where your test has begun to fail.

failing test in the terminal

The exception error in the terminal tells us the exact cause of our problems, and that is that it cannot seem to find the Table Genres. So now we have to go back into our code and find where the Table isn’t being recognised and we can put lots of print statements as well debug our code to get it to pass.

A README was created with information about the project, also doc strings are also visible throughout the project as well. I have shared screenshots of parts of the README and doc strings.

“README” is available for anyone not knowing whats going on
doc strings

I learn’t about the types of databases, how to create GET and POST requests with a Javalin Server, how to use SQL statements with Java as well as SQL statements alone. I also learnt other invaluable lessons, like TDD testing, and moving between different languages.

Add a comment

Related posts:

All your Embrace2 Questions Answered

Since Embrace2 made its debut a few weeks ago, questions have poured in seeking to get better acquainted with the newest addition. So we thought it was only right to take you along for a quick…

PKKMB GALAXY UISI

Satu Dekade Mengangkasa, Menorehkan Cita dan Cinta. Perjalanan menjadi mahasiswa seutuhnya menjadi tantangan bersama para pembelajar pendidikan tinggi di Indonesia. Beranjak dari proses menyongsong…

Why you should do a podcast for your brand

It was recently International Podcast Day. Which means it’s time to shine a spotlight (or should that be, pass the microphone?) on the world of audio storytelling. As a producer of a podcast for a…