SOAP Basics

What exactly is SOAP?

No, not THAT SOAP!

SOAP stands for Simple Object Access Protocol and it is an XML-based protocol for application element intercommunication. SOAP can be carried over a variety of other Internet protocols such as HTTP (Hypertext Transfer Protocol) so that it may carry out messaging with secure connections, support dynamic web services, and offer reliable delivery and failure recovery.

Many SOAP applications use WSDL (Web Services Definition Language) as SOAP already works written in XML. You can use SOAP to carry out CRUD (Create, Read, Update, Delete) commands such as altering an SQL database! Ironic isn’t it, that in the real world soap is used to remove crud, but online SOAP enables and furthers CRUD! What a world.

Spring Tool Suite left, SoapUI right

Using STS along with SoapUI and MySQL Workbench, I made a way to CRUD my online localhost database table with code written in STS through SoapUI.

HTML Basics

Hypertext Markup Language is the standard markup language for documents displayed in a web browser. It’s how most websites are made! WordPress here is made using PHP, but that’s beside the point. Using a few common HTML elements, you can make an amazing document to display as a site! Here is a basic skeleton for you to get started on fleshing out!

 <!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
    </head>
<body>

<h1>My First Heading</h1>
<p>My first paragraph!</p>

</body>
</html> 
  • The <!DOCTYPE html> declaration defines this document to be HTML5.
  • The <html> element is the root element of an HTML page.
  • The <head> element contains meta information about the document.
  • The <title> element specifies a title for the document.
  • The <body> element contains the visible page content.
  • The <h1> element defines a large heading.
  • The <p> element defines a paragraph.

Notice the <?> tags? These tags define elements which then go on to define webpage content. This is the formatting with which HTML is written. These are basic however so here are ten commonly used elements:

  1. Links: <a href=”https://www.w3schools.com”>My source used</a>
    The link’s destination is specified in the href attribute. Attributes are used as element parameters within tags to customize element use.
  2. Images: <img src=”w3schools.jpg” alt=”W3Schools.com” width=”104″ height=”142″>
    The source file (src), alternative text (alt), width, and height are img attributes.
  3. Buttons: <button>Click me!</button>
    Creates a button for user interaction. Must be configured though!
  4. Line Break: <br>
    <br> is interesting because it’s an empty element, meaning it lacks a closing tag.
  5. Bold/Strong: <b>Bold</b> <strong>Strong</strong>
    Bold and Strong are interchangeable and both define text.
  6. Small: <small>Small</small>
    This emphasizes tagged text as a smaller size. There are many more text formatting elements such as <mark> to highlight, <del> to strikethrough, <ins> to underline, and so on.
  7. Blockquote: <blockquote> [insert wall of text here] </blockquote>
    A <blockquote> is most commonly used when inserting a snippet or even full paragraph of text from elsewhere into your webpage. The cite attribute enables citation of the blockquote. There are more quotation elements in HTML such as <abbr> abbreviations and more!
  8. Comment: <!– This is a comment! –>
    While not exactly an element, comments are extremely useful for annotating, noting, and describing lines of HTML written as they are hidden from common view when the webpage is loaded.
  9. Style: <style>Style</style>
    Style uses numerous attributes to stylize its tagged content. See CSS for a wealth of information on how to give your webpages style and flair!
  10. List: <ol><li>One</li> <li>Two</li><li>Three</li></ol>
    There are two kinds of list elements: ordered and unordered. Ordered lists, which I have just used as demonstration, are numbered.

Have fun practicing HTML and remember that tags are not case-sensitive, but XHTML is if you plan to use that.

Java to XML: JAXB

JAXB. Sounds like a brand name doesn’t it? It stands for Java Architectural XML Binding. Being used to marshal (write) and unmarshal (read) XML documentation, it is simple to code in Java! All one needs is a few imports to get started:

import javax.xml.bind.annotation.XmlAttribute;  
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlElement;

The Root Element is for the XML document while the Element import is for the Root Element. Attribute annotation specifies root element attribute.

@XmlRootElement
public class Employee {
    private int id;
    private String name;
public Employee() {}
public Employee(int id, String name, float salary) {
    super();
    this.id = id;
    this.name = name;
}

The XmlRootElement annotates class data, XmlAttribute annotates Getter and Setter methods, and XmlElement would annotate Getter and Setter methods for each class data element, in this example values id and name.

To marshal an object, two objects must be created: a JAXBContext object using new instance of the root element class, then a marshal object using createMarshaller. Import the following: import javax.xml.bind.JAXBContext, import javax.xml.bind.Marshaller, and java.io.FileOutputStream

  JAXBContext contextObj = JAXBContext.newInstance(Employee.class);
  Marshaller marshallerObj = contextObj.createMarshaller();
  marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
  Employee emp1=new Employee(1,"John Smith");
  marshallerObj.marshal(emp1, new FileOutputStream("employee.xml"));

With this code, we can successfully export an XML file containing the data of one Employee!

Design Patterns: Builder

Builder pattern, similar to Factory pattern, is a creational design pattern. While there are other established Java design pattern categories such as structural and behavioral, I will be mainly covering creational design patterns for now.

Builder patterns are used to create objects made from other objects, being independent of the main object and also to hide creation of parts from the client, the builder knows all specifics and other classes involved know nothing about what’s going on.

This has several advantages:

  • It provides clear separation between the construction and representation of an object.
  • It provides better control over construction process.
  • It supports to change the internal representation of objects.
In this JavaTPoint example, BuilderDemo at runtime calls CDBuilder to Build a CD through the main method.

Unlike Factory, Builder is only truly needed when an object cannot be produced in one step.  Being less commonly used however does not make this an inferior design pattern as every design pattern is best for different programming needs. Use them as you see fit!

Follow the original code on my GitHub profile!

Design Patterns: Factory

Factory pattern would be used whenever you would need a method to return one of several possible classes that share a common superclass. This pattern could be used to create an enemy in a game. It is used when: not knowing ahead of time what class objects are needed, all potential classes are of the same subclass hierarchy, to centralize class selection code, to encapsulate object creation, to prevent the user from knowing every subclass.

Unlike Factory pattern, Abstract Factory pattern has total encapsulation: the method that orders the object, the factories that build the object, the final objects, and the final objects contain objects that use the Strategy pattern which uses composition a.k.a. class fields that are objects themselves.

An abstract factory pattern allows you to create families of related objects without specifying a concrete class which is extremely important because it provides the most flexibility. Many objects can be added or changed dynamically during runtime. This can easily become quite complicated.

How many do you need? It doesn’t matter, productivity is sky-high!

Follow the original code on my GitHub profile!

Design Patterns: Polymorphism

Polymorphism allows programmers to write methods that don’t need to change if new subclasses are created. Example: a subclass Dog can add a new method such as dig without affecting superclass Animal in any way. Also, subclasses may be referred to by their superclass type. You can then create subclasses from subclasses. You cannot however access methods this way if they’re only in the subclass.

Abstract classes grant all of the power of polymorphism without any of the work. There are no abstract fields or variables, all methods inside of an abstract class however do not need to be abstract – they can be static. You cannot create objects from an abstract class, but subclasses can still extend it which is its primary purpose.

Interface is a class with only abstract methods. You can add as many interfaces to a class using implements as you want, but you can only use public static and final fields if you choose to use them at all. Interfaces are flexible because classes from different inheritance trees can use a common interface.

Follow the original code on my GitHub profile!

Design Patterns: Inheritance

A class is a blueprint. It has fields i.e. instance variables and has objects and methods created from it. It also defines all methods or functions for its objects. This superclass grant its object (subclass) access to its methods and variables, the subclass inheriting from its superclass. This is all about inheritance.

All fields in a superclass become private, only to be altered by public methods such as Getters and Setters within the superclass. A subclass that extends from the superclass is granted all of the methods and variables which will be predefined. Only those variables that change within the subclass should be altered.

The main method creates objects and helps them interact with one another. Any newly created objects should ever have their values referenced/set directly within the main method.

Encapsulation protects all data from alteration. By handling data manipulation in main method with our superclass’ methods, it allows for checks and balances against accidental alteration of inherited/inheriting fields. Parameters are needed to define variables passed to a method and are isolated in scope so duplicate names will not interfere. Arguments are variables passed to methods when methods are used.

Abstraction allows us to hide our superclass data by making it private because again, we are using our methods to make changes to our private variables.

Instance fields/variables are declared inside of classes, but local variables are created in methods only for the method’s use.

How do you decide if a class should extend another class? One way is to use the “IS A” principle. Is a dog an animal? Yes! Inheritance should be used when a subclass needs most methods in the superclass where almost every method in the superclass works with the subclass. Do not use inheritance just to reuse code because a class may not be fit to use a superclass’ methods or variables.

Follow the original code on my GitHub profile!

MySQL 101 Interview Questions

With my new need for SQL usage comes new questions. What are key differences to remember and complex concepts in MySQL? Here are ten of them for you to ask yourself and answer in the comments below.

  1. When would one decide to use CHAR over VARCHAR for a faster performance with more limited data entry?
  2. How would one make a clustered index in a table?
  3. How do normalization and denormalization differ?
  4. What are triggers most commonly used for?
  5. Using sample database sakila, write a subquery to display information for an actor and all of the films that actor had been in.
  6. Explain constraints.
  7. List at least three different SQL constraints.
  8. How can you select unique records from a table?
  9. What is a stored procedure and how is it used?
  10. Which function can be used to replace specific parts of a string?

Here are my answers!

  1. Using fixed data in a column/attribute such as a Social Security number. After all, there are no SSN(s) holding more or less than 9 digits.
  2. A clustered index defines data order and is normally made by making a primary key as there can only be one of both. This new clustered index of unique numbered rows makes searching for data by rows much easier.
  3. Both different processes, normalization creates duplicates from existing overlapping data groups while denormalization removes those duplicates, making these data groups irregular in size, but not duplicated.
  4. Triggers are most commonly used to run when “triggered” by particular events such as when a statement inserts, updates, or deletes rows in the associated table.
  5. select * from film_actor where actor_id = (select actor_id from actor where last_name = ‘wahlberg’);
  6. Constraints are used to specify the limit on the data type of columns or the table. UNIQUE for example is a constraint that forbids duplicate data in any column.
  7. SQL constraints are: NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, DEFAULT
  8. You can select unique records from a table by using the DISTINCT clause.
  9. A stored procedure is a written routine in a database to be called upon and perform a list of commands. Handy for running multiple commands at once.
  10. The replace function. Syntax: REPLACE (string_expression, search_string, replacement_string)

These questions had been inspired from this article on Edureka.

Showcase: Spring Tools Suite

Today I would like to show off a new piece of software I downloaded: Spring Tools Suite! Based on Eclipse, it is a complex IDE (Integrated Developer Environment) for use with proper project management. Allow me to demonstrate how…

The launch of our more automated IDE.

Rather than creating a file, Spring Tool Suite allows you to create an entire project with packages and any files within. I will go over the initial tooltip line from left to right.

How Spring Tool Suite can be used to initially create full projects.
  • New: This comes with a drop-down menu and is also in File. It can help you create almost any project folders, packages, or anything else you may need.
  • Save: Self-explanatory. You’ll be using this alot.
  • Save All: Handy for when you’re working with multiple files.
  • Open a Terminal: For when the terminal must be used, such as compiling.
  • Skip All Breakpoints: Skips all breakpoints. Can be used when parsing code for lines’ scope or order errors.
  • Boot Dashboard: An additional view mode, this grants you the ability to both quickly access and run multiple applications simultaneously! For when you’re too busy debugging/testing too many different code files.
  • Debug: This may come with a drop-down to debug different project scripts.
  • Run: Instead of triggering run in the terminal, you can use this handy button here instead.
  • Run From Last: Grants different external tool usage.
  • Stop: Stops a running script.
  • Relaunch: Restarts a running script.

These are the core features of Spring Tool Suite that make it the superior IDE for usage with complex multi-file and even multi-package Java projects! I will certainly be using it in the future for any big projects that would require me to draw a UML flowchart, which I will soon be getting into. Cheers!

MySQL: Operator IN

While this is mainly a Java blog, I will soon need a database to use for an upcoming personal project. So I took up MySQL! Using its Workbench, I can make and host tables online. Here is a written example:

create testDB;
use testDB;
create table BLAZER_DAY (
id INT(1) NOT NULL AUTO_INCREMENT PRIMARY KEY,
day CHAR(10)
);

describe BLAZER_DAY;
use BLAZER_DAY;

After creating a database, we create a table. At my workplace there is a new fashion policy requiring us to wear blazer jackets each Monday and Thursday. We can demonstrate this policy using a table named BLAZER_DAY. Each table in MySQL has a primary key that numbers and increments along each row with our other column’s data, column name day. Column day will list characters up to ten digits in length.

Then we can see what this table would look like or be shaped like before we declare our usage of it, as we declared the use of our test database. Now that our database is created, we must populate it with our data!

INSERT INTO BLAZER_DAY (day) VALUES ('Sunday');
INSERT INTO BLAZER_DAY (day) VALUES ('Monday');
INSERT INTO BLAZER_DAY (day) VALUES ('Tuesday');
INSERT INTO BLAZER_DAY (day) VALUES ('Wednesday');
INSERT INTO BLAZER_DAY (day) VALUES ('Thursday');
INSERT INTO BLAZER_DAY (day) VALUES ('Friday');
INSERT INTO BLAZER_DAY (day) VALUES ('Saturday');

Our database now has the seven days of the week! Finally, we must update both blazer days with declarations of when we must wear blazer jackets.

UPDATE BLAZER_DAY SET day = "Blazerday!" WHERE id IN (2);
UPDATE BLAZER_DAY SET day = "Blazerday!" WHERE id IN (5);
What your final result should look like:

With this table, everything becomes clear! Everybody who sees this table should now know when to wear a blazer during the week.

Follow any of my SQL work on a separate GitHub repository!

Design a site like this with WordPress.com
Get started