Posts

How to create a simple addition function in java and use command line arguments to accept the 2 numbers to add

Image
    How to create a simple addition function in java and use command line arguments to accept the 2 numbers to add To create even a simple function in java, there is foundational code (often called boilerplate) to get you started that you need first and then you can create your simple function.  The boilerplate code you need in this case is the setup of a class.  After that, you can add your function to the class, and you can use your function as we do. Once you master this step, you can advance to more complex steps, for example adding another function, or even adding another function that lives inside another class. This is another baby step that is worthy of practicing, by following, and then by aiming to complete more and more without referencing, and then completely by memory, and to practice often. So let's do it, and discuss it, just a bit ... Here's the code:    1 public class SimpleFunction {   2     3     public static int...

How to print the letter J with dashes in Java

Image
  How to print the letter J with dashes in java Taking the step to print out anything (in this case the letter J) using dashes (or any other single symbol for that manner) is a great baby step in many programming languages. I've seen wonderful examples of fairly sophisticated art (i.e. simpsons art) created using a single symbol.  The road there includes some of the simplest trial and error.  You can quickly move from creating the letter J to creating another letter, or perhaps your name initials, and then even to complete words. This is another baby step that is worthy of practicing, by following, and then by aiming to complete more and more without referencing, and then completely by memory, and to practice often. So let's do it, and discuss it, just a bit ... Here's the code:    1 public class PrintJ {   2     public static void main (String argv[]) {   3         System.out.println("----------");   4     ...

How to print out hello world in java

Image
How to print out hello world in java Taking the step to print "hello world" is one of the first steps recommended in most programming languages. It's also one of the most common steps to take when experimenting with something new in a given language. It's even a quick opportunity when you want to test out something complex in an isolated manner. So let's do it, and discuss it, just a bit ... Here's the code:    1 public class HelloWorld {   2     public static void main (String argv[]) {   3         System.out.println("hello world");   4     }   5 } Here's what we used when building this code: * java 8 * vim editor (note: we have much love for intellij and other editors too!) * code was placed in a file named HelloWorld.java Here's what we did to run the code: * javac HelloWorld.java * java HelloWorld Here's what you'll see when you run it: hello world Here's a bit of description about the code and concepts used: the ...

Baby Java: Exploring, Building, Enhancing, & Fixing Java Apps in Pieces and Baby Steps

Image
Baby Java: Exploring, Building, Enhancing, & Fixing Java Apps in Pieces and Baby Steps In most things, we need to crawl before we walk, walk before we jog, and jog before we run ... In this blog we'll leverage the same approach with the beautiful programming language Java. Enjoy! My daughter & I at one of our nation's oldest aquariums on Belle Isle. So let's get started with a very small piece of code, pretty much hello world. This assumes that you have java installed as well as the java development kit installed. You can typically get standard, reliable versions from oracle. This code would need to live in a file named BabySteps.java so that the public class BabySteps will work well with it.    1 public class BabySteps {   2     public static void main (String args[]) {   3         System.out.println("Crawling before walking, walking before jogging, jogging before running!");   4     }   5 } Be careful to ens...