<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andrew Capp</title>
    <description>The latest articles on DEV Community by Andrew Capp (@acappdev).</description>
    <link>https://dev.to/acappdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F475412%2Fa5c915d6-e1a4-4dd2-8298-f6859adfaa9f.jpeg</url>
      <title>DEV Community: Andrew Capp</title>
      <link>https://dev.to/acappdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/acappdev"/>
    <language>en</language>
    <item>
      <title>Java: Why Have Abstract Classes?</title>
      <dc:creator>Andrew Capp</dc:creator>
      <pubDate>Fri, 09 Oct 2020 20:13:12 +0000</pubDate>
      <link>https://dev.to/acappdev/java-why-have-abstract-classes-39ad</link>
      <guid>https://dev.to/acappdev/java-why-have-abstract-classes-39ad</guid>
      <description>&lt;p&gt;I’ve been learning Java recently and a new concept for me is the idea of abstract classes.  While the concept is already kind of “abstract” (pun intended), what I don’t understand is why you would use an abstract class when you can just use a regular class or an interface.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Abstraction in OOP (Object Oriented Programming)
&lt;/h2&gt;

&lt;p&gt;To review, the concept of abstraction in OOP is hiding the implementation details so the developer can focus on the functionality (how the item is used).  For example, a TV remote is an abstraction in that you don’t have to know how the remote works in order to use it – you just need to know which button to push.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an Abstract Class?
&lt;/h2&gt;

&lt;p&gt;In Java, there are two ways to create an abstract class:&lt;/p&gt;

&lt;p&gt;Use abstract keyword: &lt;code&gt;abstract class Car { // Code… }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;p&gt;Use interface keyword: &lt;code&gt;interface Animal { // Code… }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We are focusing on the abstract class here.  However, one of the differences between an abstract class and an interface is that 0-100% of the methods in an abstract class can be abstract while 100% of the methods in an interface are abstract (with some exceptions).&lt;/p&gt;

&lt;p&gt;An abstract class is similar to a regular class in Java with the following differences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Must be declared using the abstract keyword.&lt;/li&gt;
&lt;li&gt;It can have abstract and non-abstract methods.&lt;/li&gt;
&lt;li&gt;It cannot be instantiated (you cannot create objects directly from an abstract class).&lt;/li&gt;
&lt;li&gt;You must extend an abstract class (inherit from it) in order to use it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is an Abstract Method?
&lt;/h2&gt;

&lt;p&gt;An abstract method must also be declared using the abstract keyword:&lt;br&gt;
&lt;code&gt;abstract void drive();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It cannot have any code in the method – just a method signature like in the above example.&lt;/p&gt;

&lt;p&gt;Any regular class inheriting from an abstract class must implement every abstract method.  This means you are required to provide your own method to replace an abstract one.&lt;/p&gt;
&lt;h2&gt;
  
  
  What are Abstract Classes Used For?
&lt;/h2&gt;

&lt;p&gt;So back to my original question – why do we use them?  It turns out that abstract classes are very useful in Java.  They are used when you have common functionality and need to implement some custom behavior as well.  For example, let’s say that you need to download data from different internet sites.  You can use an abstract parent class to handle the communication and downloading of the data while the individual child classes implement their own way to handle the data that is downloaded.&lt;/p&gt;

&lt;p&gt;Going back to the OOP concept of abstraction - this makes sense.  We are letting the abstract parent class handle the details of communicating over the internet while we focus on handling the specific data being downloaded – which is likely to be different for each site we visit.&lt;/p&gt;

&lt;p&gt;An example of this might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class internetLink {
// methods to handle downloading data from the internet

abstract void handleData(); // method to handle the data to be implemented by our classes
}

class newsDownload extends internetLink {
void handleData() {
// code to handle the downloaded news data
}
}

class friendsDownload extends internetLink {
void handleData() {
// code to handle the downloaded friends data
}
}

class chatDownload extends internetLink {
void handleData() {
// code to handle the downloaded chat data
}
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So, each of our download classes handles different data.  We can write our internetLink class to handle the actual downloading while our download classes implement methods that handle the data.  In this case we only need to write a method to do something with the data.  We don’t have to worry about the actual downloading – the internetLink class handles that for us!&lt;/p&gt;

&lt;p&gt;This is called the Template Method Design Pattern and is a popular design pattern in object oriented programming languages.&lt;/p&gt;

&lt;p&gt;This concept makes more sense to me now and I hope this makes more sense to you as well!&lt;/p&gt;

</description>
      <category>java</category>
      <category>abstract</category>
    </item>
    <item>
      <title>Looping in Javascript</title>
      <dc:creator>Andrew Capp</dc:creator>
      <pubDate>Sat, 03 Oct 2020 18:31:31 +0000</pubDate>
      <link>https://dev.to/acappdev/looping-in-javascript-2gla</link>
      <guid>https://dev.to/acappdev/looping-in-javascript-2gla</guid>
      <description>&lt;p&gt;Knowledge of how to loop through objects as well as which type of loop to use in a particular situation is very important in order to be proficient in JavaScript. Following are five types of loops available and examples of when to use each:&lt;/p&gt;

&lt;h2&gt;
  
  
  For-in Loop:
&lt;/h2&gt;

&lt;p&gt;Used to iterate through objects.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;code&gt;const pet = { name: “Rex”, breed: “Pug”, color: “brown” }&lt;br&gt;
for (const key in pet) { console.log(pet[key]) } // =&amp;gt; Rex / Pug / brown&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: This works on any object with enumerable properties (non-symbols). So it works on an array, but it is much better to use a loop designed for arrays.&lt;/p&gt;

&lt;p&gt;Caution: Does not guarantee that the properties will be visited in the same order as the object. Should be avoided if you are modifying properties during the loop. A better option would be to use Object.keys(pet) which returns an array that can be used in a loop.&lt;/p&gt;
&lt;h2&gt;
  
  
  For-of Loop:
&lt;/h2&gt;

&lt;p&gt;Used to iterate through arrays.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const petArray = 
  [
    { name: “Rex”, breed: “Pug”, color: “brown” },
    { name: “Pebbles”, breed: “Dalmatian”, color: “white with 
      black spots” },
  ]

for (const element of petArray) { console.log(element[‘name’]) } //=&amp;gt; Rex / Pebbles
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note: This works on strings, arrays, and array-like objects.&lt;/p&gt;

&lt;p&gt;Example of looping through a string:&lt;br&gt;
&lt;code&gt;const stringArray = “this is a string”&lt;br&gt;
for (const letter of stringArray) { console.log(letter) } //=&amp;gt; t / h / i / s / …&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Caution: This is best used when need to visit each element and are not changing the elements. If you want to perform an action on each element, there are better methods such as map and reduce. If you want to control the iteration or access the index of the element in the loop then a basic for loop will work better.&lt;/p&gt;
&lt;h2&gt;
  
  
  For-Each Loop:
&lt;/h2&gt;

&lt;p&gt;Loops through an array using a callback function. Optional index, array, and thisArg arguments.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;code&gt;petArray.forEach( (element, index) =&amp;gt; console.log(index, element.name)) //=&amp;gt; 0 “Rex” / 1 “Pebbles”&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: This is similar to for-of loops, but requires a callback function. This is useful if you need access to the index or need to perform more complex actions. Again, this is best used when you need to visit each element in the array. For more complex situations a regular for loop might be better.&lt;/p&gt;
&lt;h2&gt;
  
  
  For Loop:
&lt;/h2&gt;

&lt;p&gt;Used for a loop with three optional expressions.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numbers = []

for (let i=0; i&amp;lt;5; i++) { numbers.push(i) }
console.log(numbers) //=&amp;gt; [0,1,2,3,4]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note: The expressions in parenthesis are optional and very flexible. It is easy to customize how they are handled in the loop. This makes the for loop a great option for more complicated situations.&lt;/p&gt;

&lt;p&gt;Caution: If you don’t specify the optional expressions, be sure to evaluate and update them in the loop. Otherwise you will get infinite loops and/or unexpected results.&lt;/p&gt;

&lt;h2&gt;
  
  
  While / Do-While:
&lt;/h2&gt;

&lt;p&gt;Used to loop until the specified condition evaluates to false.&lt;/p&gt;

&lt;p&gt;Example of while loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let i = 0

while (i &amp;lt; 5) {
  console.log(‘Hi!’, i)
  i++
} //=&amp;gt; Hi! 0 / Hi! 1 / Hi! 2 / Hi! 3 / Hi! 4
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note: The condition is checked at the beginning of the loop so if the condition immediately evaluates to false the while loop will not execute.&lt;/p&gt;

&lt;p&gt;Example of do-while loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let k = 5

do {
  console.log(‘Hi Again!’, k)
  k++
} while (k &amp;lt; 5) //=&amp;gt; Hi Again! 5
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note: This condition is checked at the end of the loop so the loop will always execute at least one time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Continue / Break:
&lt;/h2&gt;

&lt;p&gt;These are two useful keywords when working with loops.&lt;/p&gt;

&lt;h3&gt;
  
  
  Continue: Skip to the next iteration of the loop.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Break: Exits the loop
&lt;/h3&gt;

&lt;p&gt;This was a short summary of the loops available in JavaScript. Knowing these important concepts will help you become a better JavaScript programmer.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>forof</category>
      <category>forin</category>
    </item>
    <item>
      <title>Introduction to Responsive Webpages</title>
      <dc:creator>Andrew Capp</dc:creator>
      <pubDate>Fri, 02 Oct 2020 22:50:46 +0000</pubDate>
      <link>https://dev.to/acappdev/introduction-to-responsive-webpages-4l83</link>
      <guid>https://dev.to/acappdev/introduction-to-responsive-webpages-4l83</guid>
      <description>&lt;p&gt;While just about everyone uses mobile devices to access websites, most new web developers have limited practice writing applications for mobile devices.  This is because most training is done on a laptop computer.  If you haven’t had much practice coding websites for mobile, here are a few ideas on how to build responsiveness into your websites to make them better for mobile devices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Viewport
&lt;/h2&gt;

&lt;p&gt;An important first step in building a responsive webpage is telling the browser how to display the initial dimensions and scale.  This is done by including viewport settings in a  tag.&lt;/p&gt;

&lt;p&gt;Example: &lt;code&gt;&amp;lt;meta name=”viewport” content=”width=device-width”&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This should be placed in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; section of your webpage.  Note that you should make sure your elements are responsive before using the viewport settings.  Otherwise your webpage may actually look worse!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag#Common_viewport_sizes_for_mobile_and_tablet_devices"&gt;For a great discussion of viewport see this article on Mozilla&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Layout
&lt;/h2&gt;

&lt;p&gt;Your layout should be designed to be responsive from the ground up.  A popular way of accomplishing this is using a grid system.  Elements are strategically positioned on columns and the columns are adjusted to appear vertically when the screen size is small and horizontally on larger screens.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/css/css_grid.asp"&gt;W3schools.com has an excellent guide on how to use grids when designing your layout&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The latest HTML5 syntax introduced the flexbox which can be used in conjunction with grids to make aligning and spacing elements easier.  &lt;a href="https://developer.mozilla.org/enUS/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox"&gt;Here is a guide on how flexbox works&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Elements and Media
&lt;/h2&gt;

&lt;p&gt;Now that you have your basic layout design, you need to make sure the elements can adjust their size as needed.  This means avoiding absolute CSS units such as cm (centimeters), mm (millimeters), in (inches), px (pixels: 1/96 of 1 inch), pt (points), and pc (picas).&lt;/p&gt;

&lt;p&gt;Instead try to use relative units such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;em (relative to font-size of element)&lt;/li&gt;
&lt;li&gt;vw (relative to 1% of the width of the viewport) – remember the viewport above?&lt;/li&gt;
&lt;li&gt;vh (relative to 1% of the height of the viewport)&lt;/li&gt;
&lt;li&gt;% (relative to the parent element)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You may need to get creative with media elements like images and video.  In many cases you can set the width and let the height scale automatically.  Often it is a good idea to set maximum size values so quality isn’t compromised on larger screens.&lt;/p&gt;

&lt;h2&gt;
  
  
  @Media
&lt;/h2&gt;

&lt;p&gt;With the introduction of CSS3 we have Media Queries that can adjust content based on width, height, orientation, and resolution.  Note that this is not compatible with older browsers, but should work on modern browsers including mobile devices.&lt;/p&gt;

&lt;p&gt;This is where you can specify the number of columns on your layout grid above based on the width of the device.  Here you can also manually adjust the size of elements if you are not able to use the relative units above.  In fact, many times developers adjust the relative units for smaller screen so some elements appear larger and therefore easier to select with a finger.&lt;/p&gt;

&lt;p&gt;Example: &lt;code&gt;@media screen and (max-width: 620px) { CSS code… }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/css/css3_mediaqueries.asp"&gt;Refer to w3schools.com great overview of Media Queries&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Helpful Frameworks
&lt;/h2&gt;

&lt;p&gt;If you are thinking this is a lot of work you are right – it can be.  Fortunately there are many frameworks you can use that have responsiveness built in.  These frameworks can make building responsive webpages much quicker and easier.&lt;/p&gt;

&lt;p&gt;Some of these include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bootstrap: &lt;a href="https://getbootstrap.com"&gt;https://getbootstrap.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;W3schools: &lt;a href="https://www.w3schools.com/w3css/defaulT.asp"&gt;https://www.w3schools.com/w3css/defaulT.asp&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Foundation: &lt;a href="https://get.foundation"&gt;https://get.foundation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Pure: &lt;a href="https://purecss.io"&gt;https://purecss.io&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Semantic UI: &lt;a href="https://semantic-ui.com"&gt;https://semantic-ui.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Materialize: &lt;a href="https://materializecss.com"&gt;https://materializecss.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are many others so I encourage you to explore and find what is right for your project.&lt;/p&gt;

&lt;p&gt;Hopefully this introduction gives you a place to start learning to build responsive webpages.  It is extra work to build webpages that work equally well on mobile devices as they do on regular computers, but it is a must for building any professional website.&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>responsive</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Tips for 3rd Party Website Hosting</title>
      <dc:creator>Andrew Capp</dc:creator>
      <pubDate>Fri, 25 Sep 2020 22:04:29 +0000</pubDate>
      <link>https://dev.to/acappdev/tips-for-hosting-your-own-website-2ip8</link>
      <guid>https://dev.to/acappdev/tips-for-hosting-your-own-website-2ip8</guid>
      <description>&lt;p&gt;As a web developer, one of your most valuable marketing tools may be a personal portfolio website where you can showcase your projects, blogs, and more.  The good news is there are many options for hosting your website as well as tools to make the process easier.  The bad news is that it can be time consuming and difficult to narrow down the choices and figure out which tools you need to get your website up and running.  After setting up hosting for my own portfolio website, I have a few tips that might make the process easier for you.  My website is at &lt;a href="http://andrewcapp.com"&gt;http://andrewcapp.com&lt;/a&gt; if you would like to check it out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find a Hosting Service Provider
&lt;/h2&gt;

&lt;p&gt;There are many options for hosting your website at a wide range of price points.  I researched several well-known providers ranging from free to expensive.  I decided on a low cost provider with a positive social image (GreenGeeks.com) which has great service and support.  There are several websites that can help you compare various providers and I recommend looking at a couple to see if you get similar answers in more than one place.&lt;/p&gt;

&lt;p&gt;Some of the well-known providers have great service and lots of options, but be careful of extra fees and required add-ons that can really increase your cost.  If cost is an issue there are several free providers, but be aware that you will sacrifice something – either having to use their domain, not having many tools (like Cpanel), or not having the option to host more complex code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Your Domain
&lt;/h2&gt;

&lt;p&gt;This is easiest to complete once you select your hosting provider.  If you already have a domain registered on another site the transfer process is fairly simple, but does require time and effort on both ends.  If you don’t have a domain, then work with your selected provider to get one set up – a pretty easy process.&lt;/p&gt;

&lt;p&gt;I had to transfer my domain which required getting authorization codes, contacting support at my new hosting site, and waiting about a week for the transfer to complete.  When my site was ready to go live I couldn’t get it to work and found that the domain nameservers needed to be manually changed to the new hosting site’s servers.  I somehow missed this when reviewing my setup, but the support staff at GreenGeeks found the issue quickly once I asked for help.&lt;/p&gt;

&lt;h2&gt;
  
  
  Readying Your Code
&lt;/h2&gt;

&lt;p&gt;Many hosting sites have templates you can use to set up a basic website.  These are a great option if you don’t want to manually create your site.  As a web developer, I relished the opportunity to create my own website from scratch so I did not utilize any templates and instead had a great time building my site from the ground up.&lt;/p&gt;

&lt;p&gt;What I didn’t know was how to get my JavaScript and React framework code set up in a way that works on GreenGeeks.  Fortunately, a simple search found a great blog post by Amit Rai titled How To Deploy React App on Shared Hosting (Cpanel): &lt;a href="https://medium.com/@aforamitrai/how-to-deploy-react-app-on-shared-hosting-cpanel-d682b0342424"&gt;https://medium.com/@aforamitrai/how-to-deploy-react-app-on-shared-hosting-cpanel-d682b0342424&lt;/a&gt;.  This was a great help and I recommend utilizing this blog if you are uploading your own code to a hosting provider that has Cpanel.&lt;/p&gt;

&lt;p&gt;The nice thing is there is a simple command to get your code ready to upload:&lt;/p&gt;

&lt;p&gt;Simply type “npm run build” in your project directory and the needed files will be saved in a build folder and ready to go!&lt;/p&gt;

&lt;h2&gt;
  
  
  Uploading to the Hosting Site
&lt;/h2&gt;

&lt;p&gt;Once you have your files ready you will need an FTP application in order to transfer your files to the hosting site.  I followed the instructions on the GreenGeeks site which were well written.  I wasn’t able to connect to the FTP server until I fixed the aforementioned nameserver issues on my domain.  However, once that was fixed the instructions worked great.  There are also helpful instructions in Amit’s blog.&lt;/p&gt;

&lt;p&gt;One difference for me is I loaded the FTP files directly into the public_html directory on my host site.  There is probably a better way to do this, but I couldn’t get the instructions in Amit’s blog to work for me.&lt;/p&gt;

&lt;p&gt;Many providers have great support so if you are having problems getting your website to work don’t hesitate to reach out to them.  They certainly helped me more than once.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making Updates
&lt;/h2&gt;

&lt;p&gt;Congratulations on getting your website up and running!  If you are like me, you will have regular updates and will keep tweaking your website design.  Updating changes to your live site is simply a case of repeating the steps above to ready your files and upload to the host site.&lt;/p&gt;

&lt;p&gt;There are options to use Git Version Control and other tools to automate updating your site.  I will look into these in the near future and will let you know if I find some great automation for this.  Thank you for reading my blog and I hope you find this useful.&lt;/p&gt;

</description>
      <category>website</category>
      <category>domain</category>
      <category>greengeeks</category>
      <category>portfolio</category>
    </item>
  </channel>
</rss>
