<?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: John Hill</title>
    <description>The latest articles on DEV Community by John Hill (@jmhill91).</description>
    <link>https://dev.to/jmhill91</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%2F416220%2F1a9deb91-6aed-4fd8-917c-c3fd9c9e301c.jpeg</url>
      <title>DEV Community: John Hill</title>
      <link>https://dev.to/jmhill91</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jmhill91"/>
    <language>en</language>
    <item>
      <title>Super, Sub, and Abstract Classes</title>
      <dc:creator>John Hill</dc:creator>
      <pubDate>Mon, 03 Aug 2020 23:54:51 +0000</pubDate>
      <link>https://dev.to/jmhill91/super-sub-and-abstract-classes-1kgd</link>
      <guid>https://dev.to/jmhill91/super-sub-and-abstract-classes-1kgd</guid>
      <description>&lt;p&gt;When we get into coding anyone who has been coding for any period of time knows we want to keep our code DRY. Whenever you see yourself copying methods and variables from one class to another we may want to set up a relationship between the classes. &lt;/p&gt;

&lt;p&gt;An easy way to look at this would be a vehicle. If someone was to ask you to draw a vehicle some people may draw a car, a truck, or a motorcycle. Similarly if I google a picture of a car it shows me pictures of hundreds of different types of cars. In this regard the more abstract the concept the higher in the class it should be, with vehicle being the upmost Super class in this case. Similarly the more specific it gets the more sub it would be with maybe 2017 Ford Mustang GT being the most specific so being the final subclass in the tree. &lt;/p&gt;

&lt;p&gt;When we look at Super and sub classes it is important to know what is inherited vs what is accessible/callable. As you know if you have been working with java for any amount of time we designate things &lt;em&gt;private, public, and protected&lt;/em&gt;. A subclass inherits everything from a Superclass, but not everything is necessarily accessible in the subclass. If you have a &lt;em&gt;private&lt;/em&gt; method or variable you cannot call them directly in the subclass. As in other cases &lt;em&gt;public&lt;/em&gt; methods and variables are both accessible and are also inherited to the class. &lt;/p&gt;

&lt;p&gt;The biggest designation to get used to when using Super and subclasses would probably be &lt;em&gt;protected&lt;/em&gt;. A &lt;em&gt;protected&lt;/em&gt; method or variable is inherited and callable in the subclass but is not callable in non related classes. For instant if we had a protected method in car it could not be accessed in boat for instance, but that method would be callable in Ford. &lt;/p&gt;

&lt;p&gt;So how do we set up these relationships in Java. In Java we use &lt;strong&gt;&lt;em&gt;extends&lt;/em&gt;&lt;/strong&gt; to set up the relationship between classes. the subclass extends the superclass to let the compiler know it is the sublcass of the super.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Car extends Vehicle { 

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this set up there is a flaw though we want to have the super class vehicle and we want a method drive in this super class but each subclass needs to implement drive in its own way and we don't want people to be able to create a vehicle because technically vehicles don't exist on their own. This is where abstract classes and methods come into play.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
public abstract class Vehicle {

protected abstract void drive();

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Above we have created the abstract class vehicle which contains the abstract method drive. It is import that any subclass of vehicle must implement the method drive. Any subclass that does not implement the abstract method will become an abstract class. &lt;/p&gt;

&lt;p&gt;Now there is a lot more we could go into depth to include constructors and how those are implemented but I will go over that more in a future post.&lt;/p&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>Arrays in Java</title>
      <dc:creator>John Hill</dc:creator>
      <pubDate>Thu, 23 Jul 2020 19:15:23 +0000</pubDate>
      <link>https://dev.to/jmhill91/arrays-in-java-4mma</link>
      <guid>https://dev.to/jmhill91/arrays-in-java-4mma</guid>
      <description>&lt;p&gt;If you have used a language similar to Ruby or JavaScript Arrays grow and shrink as you need them to. If you need to add or remove an item to an array there are methods that make it pretty simple. If you want an integer, string, and boolean value all in one array you could do that too. In Java with just a normal array it's not that simple.&lt;/p&gt;

&lt;p&gt;In Java when you declare an array you also have to declare the type of array you want. Which means unlike other languages you can't have multiple datatypes in a single array. The array can only hold the type of information you set at declaration. This means you cannot have an array with a string, integer, and boolean all in a single array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] arryInt; //declaration only
String[] strArr;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Also in Java when you create an array it is set at the length you set at creation. You can do this in two ways, you can set the length or create it with the initial information you need in it. You cannot make it bigger or smaller after creating it, based on you data. Once the length is set on the array that will be the length of that array for the entirety of the program. Say for instance you have an array which is the length if 10 but only have 8 number stored in it, the remain 2 indices would still have an integer stored in it, it would be default to 0. So this would be fine if we have a fixed set of data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] intArr = new int[5];   //this declares and creates intArr 
                               with a length of 5
String nameArr = { Sam, Becky, Vincent, Katie }; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In Java the first index of an array is index 0. In Java if you have an array with a length of 10 the last index would be 9. When you add an item to an array you just add this to the specific index where you want to put the information. If in our code we then try to add an item to index 10 we would get an IndexOutOfBounds error because although there are 10 indices the last index if 9 because we start at 0. Similarly to get or use the information out of the array we would just use the index in the array where the information is stored.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int arrInt = new int[10];
arrInt[0] = 200;
arrInt[3] = 43; 
arrInt[10] = 30;  //IndexOutOfBounds error no index 10

int x = arrInt[3];  //would assign 43 to x
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  ArrayList
&lt;/h2&gt;

&lt;p&gt;What happens if we need an array but we don't know how many indices. We may need 1 or 2 or we may need 1000. We may need to add or remove an index based on our info and how it changes. Well we could set an array to the maximum number of indices we know we will need; which would take a large chunk of memory, some of which we may never even use. A solution to this is that we could use an ArrayList. ArrayList is part of the java.util package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.ArrayList
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Similar to a normal array it can still only hold one data type. Items in an ArrayList are actually objects so we need to use the wrapper class for each data type; for instance instead of int we need to use Integer. Where it differs is it can grow and shrink as we need. Say we needed an array of names. We can add names to the list using the .add() method. If we don't need a name on the list we can also remove the name using .remove().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ArrayList&amp;lt;String&amp;gt; students = new ArrayList&amp;lt;String&amp;gt;;
student.add("Jimmy");
student.add("Sarah");
student.add("Rick");

student.remove(1);  //this would remove the student at index 1 
                   which would be Sarah resizing our index to 2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;There are other methods we can use on an ArrayList as well. The .set() method allows us to set the information in the ArrayList at a specific index. The .clear() method completely empties an ArrayList. The .size() will return the size of an ArrayList similar to the method you use on an array. You can also use the .add() to insert an item at a specific index.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ArrayList&amp;lt;String&amp;gt; students = new ArrayList&amp;lt;String&amp;gt;;
student.add("Jimmy");
student.add("Sarah");
student.add("Rick");

student.set(1, "Ruby");   //this would change Sarah to Ruby
student.add(1, "Sarah");  // this inserts Sarah into index 1 
                          above Ruby

student.size();          //this would return 4 

student.clear();         //this empties the ArrayList
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;While this is brief this should help give you the basics on Arrays and ArrayList and how to use them in Java.&lt;/p&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>Java Variables</title>
      <dc:creator>John Hill</dc:creator>
      <pubDate>Fri, 03 Jul 2020 03:51:09 +0000</pubDate>
      <link>https://dev.to/jmhill91/java-variables-13a0</link>
      <guid>https://dev.to/jmhill91/java-variables-13a0</guid>
      <description>&lt;p&gt;In my last blog I explained that I even though I have been coding due to academic integrity I haven't been able to upload my code to Github. So to now get into the good stuff that I have been learning and working on. Summer B session has officially started back for me at ASU. The coding language I will be using this semester is Java. So while I am reviewing the basics and getting started I figured I go ahead and start with something simple as my first blog about code in a while. This will give you the basics of declaring and assigning variables in Java. &lt;/p&gt;

&lt;p&gt;In java declaring variables all follow a basic format:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;type&lt;/em&gt; &lt;em&gt;name&lt;/em&gt;; &lt;/p&gt;

&lt;p&gt;If you have never used Java than it is important to know that there are both primitive and object types. The primitive data types in Java are &lt;strong&gt;byte, short, char, int, long, float, and double&lt;/strong&gt;. In Java the object types are &lt;strong&gt;Byte, Short, Character, Integer, Long, Float, Double, and String&lt;/strong&gt;. If you notice all primitive data types start with a lower case letter and object types all start with a capital letter. So as I said know this declaring variables becomes pretty simple a few examples are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int myInt;
double myDouble;
String myString;
Integer myInts;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Primitive vs. Object Data Types Basics
&lt;/h3&gt;

&lt;p&gt;Primitive data types are predefined in Java. When a variable is  created and another copy of the variable is created and changed the changes made in the copied variable will not reflect in the original variable. Where as Object data types are created by the user in Java. These Object Data Types could be class, array, string, ect. So when you create another variable and make it equal another Object Data Type they both reference the same object in memory so any changes made to either variable make changes to the object in memory and will be reflected in both.&lt;/p&gt;

&lt;h4&gt;
  
  
  Assigning Variables
&lt;/h4&gt;

&lt;p&gt;In java you can assign a variable on the same line you declare it or you can assign it in a separate line after declaring the variable. The important thing to remember is that you if you try to assign a int to a char for instance if it is single digits it will assign it as a character and not the number if it is double digits for instance it would not work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int z; 
z = 10; 
String myString = new String("Hello World");
char myChar;
myChar = 10,   &amp;lt;---- this would not work because char is a 
                     single character ----&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>java</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Github Conundrum/ Solving a problem in coding</title>
      <dc:creator>John Hill</dc:creator>
      <pubDate>Fri, 26 Jun 2020 21:58:25 +0000</pubDate>
      <link>https://dev.to/jmhill91/github-conundrum-solving-a-problem-in-coding-4ldd</link>
      <guid>https://dev.to/jmhill91/github-conundrum-solving-a-problem-in-coding-4ldd</guid>
      <description>&lt;p&gt;So I have run into a conundrum; even though I am coding I can't get it on my GitHub so how do I prove my growth. After graduating Flatiron School @ Access Labs in New York I moved to a market where if you didn't have 3 to 4 years experience or a bachelor degree getting a job was near impossible. So I decide to pursue the degree.&lt;/p&gt;

&lt;p&gt;The degree has already introduced me to 2 new languages in Python and Java. Due to academic integrity I can't post my code but I can start blogging on what I have learned or what I am working on when I start back up classes here in a week. &lt;/p&gt;

&lt;p&gt;This week though I am going to talk about solving my coding problems then move on to languages next. So given a problem, whether I know the coding language or not, how do I approach it to either fix the code or write out the new code.&lt;/p&gt;

&lt;p&gt;The first step for me is figuring out the problem to find a starting point. If there is code already in place I read over the code to make sure it makes since to me. &lt;/p&gt;

&lt;p&gt;From there I will look at syntax, in Ruby make sure every method has a def and end; In Python, for instance, make sure everything is tab and spaced correctly. Also make sure that every ()/{}/[] has both opening and closing tags. Then check the spelling and punctuation. &lt;/p&gt;

&lt;p&gt;After getting an understanding of the  code in place, I will work on solving the problem. If it is something as simple as making calls to methods in the correct order or editing a piece of code to make it function correctly then that would be the first step. From there if it requires a new method I go to work on building the new method. Also test you code as you go, it helps simplify were a bug might be as you go. &lt;/p&gt;

&lt;p&gt;Then probably the most common thing when it comes to writing code is the point where you eventually get stuck. From there go to google and look at sites such as stack-overflow to figure out how to fix your problem. The easiest way for me to learn is look at multiple solutions and then write my own from the ones you find on those type of websites. If it doesn't work then go back and figure out where I went wrong in the method and continue to build on it.&lt;/p&gt;

&lt;p&gt;While writing new code and new methods it is important you also  make sure you keep with the style of the current code. If the current code is camelCase then you don't write the new method in snake_case and vise-versa. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
