HTML Elements

The HTML element will be defined by the starting/<> tag . If the element has content, it will end with a closing tag</>, where the element name will be written inside both of them .

The p , h1, and div are all HTML element. There are some HTML elements which don’t need to be closed, for example : <img/>, <hr /> and <br /> elements. These are known as void elements.

There’s also nested elements !!

HTML elements can be nested where elements in an html document can contain other elements .most HTML documents are consist of nested HTML elements.

Good news come with those with patience , that went through the whole blog.

Rejoice !! HTML is not case sensitive . so <P> will be the same as <p> . Very merciful when your writing code , and your tired after working many hours !

Citation : https://www.w3schools.com/html/html_elements.asp , https://www.tutorialspoint.com/html/html_elements.htm

HTML – Basic

THE HTML DOCUMENT

all html documents have to begin with the declaring your document type you do this by writing this : <! DOCTYPE html >

after declaring it, the html will begin once you type <html> and don’t forget it’s end tag as well !!! </html>

remember that the visible part of the html document will be between the <body> tags </body>

HTML Headings : So you want to create headings let’s see how !

Every single heading must have <h#> !!!!

that was easy right ?!!

okay! but what if I want to write a paragraph in my web how do I do this ?

Don’t worry it’s just as easy . we just write the appropriate tag in this case is the <p> write your paragraph in here </p> .

OUTPUT WILL BE :

Links ! I want to show off link to my favorite music as well !!

HTML links are defined with the <a> tag:

Citations : https://www.w3schools.com/html/html_basic.asp , http://www.simplehtmlguide.com/basics.php , https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/HTML_basics

HTML – INTRO

HTML – stands for standard markup language for creating Web pages.

HTML – allows us to describe the structure of a web page. HTML contains elements that tell the browser what/how to display the content of the webpage. These elements are represented by tags. there’s many tags for example , headings , paragraphs , tables etc …

Example :

HTML Tags

for HTML the tags are element names surrounded by angle brackets: < >

Example : < the tagname here > the content < / tagname >

The only difference between start tag and end tag is the slash inside the end tag.

VISUALIZATION OF HTML PAGE STRUCTURE




HTML versions :

HTML1991
HTML 2.01995
HTML 3.21997
HTML 4.011999
XHTML2000
HTML52014

CITATIONS : https://www.w3schools.com/html/html_intro.asp , https://html.com/ , https://www.computerhope.com/jargon/h/html.htm

Parsing XML files with SIMPLE

SIMPLE XML serialization .

It’s an independent open source project , third party download for free at : http://simple.sourceforge.net

the simple API allows us to both read and write XML content using a annotated model, similar to JAXB , However much lightweight .

annotating a pojo properties : Placing annotation before class declarations or fields

@ Root , @ Attribute , @Element

We can also define a collection class just like in JAXB : by creating a separate class with a collection field , and an annotated class as a root element as children list.

Some of it’s Cons are : Large documents can cause Java to run out of heap space , the annotation model is unique to Simple, not portable to others APIs

Serializing and deserializing object using simple :

To serialize an instance of the above object a Persister is required. The persister object is then given an instance of the annotated object and an output result, which is a file in this example

Deserialization process is just as simple. The persister is given the class representing the serialized object and the source of the XML document. To deserialize the object the read method is used, which produces an instance of the annotated object.

Citation : David Gassner , http://simple.sourceforge.net/ , https://www.rhyous.com/2012/05/24/xml-serialization-in-java-using-simple/

Parsing XML files with JAXB

See the source image

Java Architecture for XML Binding (JAXB)

JAXB is a framework that can allows us java developers to map our java classes to xml representations. JAXB is known for two key features . One would be the ability to marshal java objects into XML , and secondly is the ability to unmarshall the those XML back into java objects.

JAXB , in other words is making it very easy to us to store, and retrieve data in memory in xml format. Without the actual need to implement a specific set of XML load/save routines depending on the programs class structure.

JAXB is particularly useful when the specification is complex and changing.

JAXB is a part of the Java SE platform and one of the APIs in the Java EE platform, and is part of the Java Web Services Development Pack (JWSDP).

JAXB 2 Tutorial

Let’s see the steps to convert java object into XML document.

  • Create POJO or bind the schema and generate the classes
  • Create the JAXBContext object
  • Create the Marshaller objects
  • Create the content tree by using set methods
  • Call the marshal method

@XmlRootElement specifies the root element for the xml document.

@XmlAttribute specifies the attribute for the root element.

@XmlElement specifies the sub element for the root element.

See the source image

Citation : David Gassner Creating and parsing with JAXB, https://www.oracle.com/technetwork/articles/javase/index-140168.html, https://www.javatpoint.com/jaxb-tutorial , https://en.wikipedia.org/wiki/Java_Architecture_for_XML_Binding

Parsing XML files with DOM

DOM = Document Object Model.

It creates a standard from/way that we can access and manipulate documents. DOM is a programming API for both XML and also HTML documents . It provides a definition of the structural logic of the documents ,and a wat that a document id accessed and manipulated

DOM node tree

The XML DOM create a tree structure view for the xml document. In here we are able to access all the elements through the tree. Modifying , deleting their content and creating new elements , content(nodes).

: XML DOM Properties :

  • x.nodeName – the name of x
  • x.nodeValue – the value of x
  • x.parentNode – the parent node of x
  • x.childNodes – the child nodes of x
  • x.attributes – the attributes nodes of x

XML DOM Methods

  • x.getElementsByTagName(name) – get all elements with a specified tag name
  • x.appendChild(node) – insert a child node to x
  • x.removeChild(node) – remove a child node from x

The XML Document Object Model (DOM) class is an in-memory representation of an XML document. The DOM allows you to programmatically read, manipulate, and modify an XML document. The XmlReader class also reads XML; however, it provides non-cached, forward-only, read-only access. This means that there are no capabilities to edit the values of an attribute or content of an element, or the ability to insert and remove nodes with the XmlReader. Editing is the primary function of the DOM. It is the common and structured way that XML data is represented in memory, although the actual XML data is stored in a linear fashion when in a file or coming in from another object.

See the source image

Citation : https://www.javatpoint.com/xml-dom , David Gassner , https://www.w3schools.com/XML/dom_intro.asp, https://docs.microsoft.com/en-us/dotnet/standard/data/xml/xml-document-object-model-dom

Parsing XML with SAX

See the source image

what does sax stand for : Simple API for XML. In real life you will want to use the SAX parse to process data and then use that data , as you wish.

When should we use SAX ? : Well , as previously we pointed out you want to use SAX when you convert existing xml to data. The key to the conversion process is to deliver SAX events as it reads the data.

SAX is efficient and fast , but with its event model makes it more useful for such state independent filtering.

See the source image

What’s independent filtering ? well, simply put it means that it does not depend on the elements that have come before it.

On the other hand if you have state dependent , you may want to utilize a pull parser API such as STAX .

With STAX you can read data from an xml file , track that data as is being collected , read cdata and its events.

Another incredible benefit of using SAX is that if you encounter a problem from an xml file.

for example : Tags that doesn’t match . You can still collect data from the xml file up to where that error code in the xml is encountered.

See the source image

Citation : David Gassner , Parsing Xml files using SAX , DOCS_ORACLE https://docs.oracle.com/javase/tutorial/jaxp/sax/parsing.html how to java :https://howtodoinjava.com/xml/sax-parser-read-xml-example/

XML Intro

Image result for XML

stands for eXtensible Markup Language. XML is a markup language much like HTML. XML was designed to store and transport data. XML was designed to be self-descriptive.

XML supports 3 types on tags .

<begin tag> , < /end tag> <empty tag/> APIs parse the tags for us . so don’t worry !

Image result for xml declaration

XML : declaration it’s at the top of the xml document , and the declarations are not required . EX : <? Version = “1.0”?>

XML Elements : -Logical component xml document , it’s divided into markup and content

Elements have text nodes : Which have child elements or child content


Citation : David Gassner , https://www.lynda.com/David-Gassner/87-1.html .

https://www.w3.org/XML/ , – Extensible Markup Language.
https://www.w3schools.com/xml/xml_whatis.asp – Introduction to XML

JDBC – Security

We want to keep our program while connecting to our database safe right ?

No evil doer can get into our database and alter information, cause harm , and possibly costing a lot of money for your company , and as a result compromising your job .

Let me help you , let’s get through some of the steps that we can take to make it safer.

and we keep our bosses happy with our data integrity safe , and secure .

First , let’s look at an example :

This small code that you wrote may seem harmless, and perfectly appropriate for your program correct ?!

🐍🦂🚨 BOOM they got you. The almighty user just got sensitive data because of this innocent code.

Why ? you may ask . well let’s look at the output .

first let’s make a program that depending on what the user is looking for in the database it will display it


ok now let’s run it back . what will be the output

I was looking for London , in the database , and I obtain the information. Hey that’s not secure what if this was sensitive information like bank accounts ! 😱😱😱

Don’t worry let’s re-write our code so it will still be functional , but this time it will hide the output.

Uff , that was close but now our code looks much safer. Beware however, this are but the first steps of something more insidious. SQL Injection !!!

We will also tackle that issue. Thank you for reading. For the complete code please click the link to the repository

https://github.com/ValorWind1/JDBC-security

SQL Joins

A JOIN clause is used to combine rows from two or more tables, based on a related column between them.

OK ! , 👌 now let’s make 2 table to show visually what JOIN is.


So , we have two tables one name : Orders , and Customer

Let’s Join them , By their CustomerID

OUTPUT IS ? :

Different Types of SQL JOINS

  • (INNER) JOIN: Returns records that have matching values in both tables
  • LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right table
  • RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left table
  • FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table

Truncate vs Deletion : Definition , and comparisson

DELETION : Will delete records one by one and makes an entry point for each and every deletion in the transaction log.

Truncate : Truncate will de-allocates pages and makes an entry for de-allocation of pages in the transaction log.

Image result for sql delete , truncate

However, there’s no difference between TRUNCATE and DELETE in term of rollback. Since, we can rollback with both of them as long as the commands are started inside the transaction

Data Integrity

It’s all about the accuracy as well as the consistency of the data that’s inside the database !. It also represents the integrity of constraints that business enforces. Depending on the rules they want to apply when they are entered into an application , or their database

Image result for data integrity sql

Let’s see some examples where data integrity could be at risk depending on different situations :

  • A user tries to enter a date outside an acceptable range.
  • A user tries to enter a phone number in the wrong format.
  • A bug in an application attempts to delete the wrong record.
  • While transferring data between two databases, the developer accidentally tries to insert the data into the wrong table.
  • While transferring data between two databases, the network went down.

This is why is so important to always adhere to all integrity rules , to minimize as much as possible , errors in your database.

4 Types of Data Integrity

  • Entity integrity
  • Referential integrity
  • Domain integrity
  • User-defined integrity

Entity Integrity

Entity integrity defines each row to be unique within its table. No two rows can be the same.

Referential Integrity

is concerned with relationships. When two or more tables have a relationship, we have to ensure that the foreign key value matches the primary key value at all times.

Domain Integrity

Domain integrity concerns the validity of entries for a given column. Selecting the appropriate data type for a column is the first step in maintaining domain integrity. 

User-Defined Integrity

User-defined integrity allows the user to apply business rules to the database that aren’t covered by any of the other three data integrity types.

Image result for data integrity sql
Image result for data integrity sql

DDL Data definition Language

Used to define databases, structure of the the schemas.

In other words DDL refers to a subset of SQL statements that change the structure of the database schema in some way.

What can you DDL do ?

We can Create = we can w=create objects such as databases or tables , for columns we need to alter

Alter = We can also manipulate objects such as rows databases , but again for columns we would need to alter the table first .

Drop = Delete / remove the tables , rows .

Truncate = this is useful if we want to empty everything inside the tables

Rename = Able to rename tables , columns. However this does not applies for a data base .

Lastly , We can also comment , and leave helpful feedback that may help us while writing code.

Clone

The default clone () . is a shallow copy .

To be able to use clone().We must first implement the interface Clonnable.

Object.clone() : It’s inherited by every class automatically

Clone : means the creation of exact copy of an object. Creating a new instance of the class current object and initializes all of its field with exactly the contents of the corresponding fields of this object

The difference between shallow copy and deep copy is that. Shallow copy of an object will have the exact copy of all fields of original object. The deep copy will have all fields of original object just like shallow. However , if original object has any references to other objects as fields, then copy of those objects are also created.

Remember to include implements Cloneable interface in order to be able to clone your objects

  • Thrown to indicate that the clone object has been called to clone an object. But that it does not implement the Clonnable interface . 

Why are we returning Super.Clone , and not This.Clone ???

It servers two purposes : 

  • Make clone() public (Object.clone() is protected)
  • Handle cases where a subclass doesn’t implement Clonnable. 

Let’s create two objects realmadrid , and Juventus .

Our goal is to have the same soccer player with the same jersey number for both teams .

Output from main :

Awesome we cloned both objects to return the same output , great !

Array of Objects

Additionally to being able to have arrays of primitive data types , we can also have arrays of objects .

Having an array. of primitive data it’s very useful. However an array of objects are even more powerful. It will allow us to model programs/applications more logically and cleanly.

So how do we do this ?

Let’s look at it using an example. First of all we have this Car class. With a set and get methods.

Next we will go to our main class.

Wow , Implementing an array of objects it’s the same as creating array. But we using our Class name instead of a data type.

Next, we will implement a for loop to go through the array , and all its objects that are inside it .

Let’s call our get method so it will display the result from our input .

I wonder what the output will be ?

Would you look at that the input that we entered. Was save as objects inside the array that we created ! How cool !

Remember array of objects it’s really an array that references variables !!