Drawer

Beginners Programming: Java - Project 01

--------------------------------------------------
PROGRAM: Example codes...

PROGRAMMING LANGUAGE: JAVA

-------------------------------------------------
COMPUTER: Home based PC/Personal Computer
OS/Operating System: Linux Mint
--------------------------------------------------
AUTHOR: Mr. Paul Ramnora
LOCATION: London, UK
EMAIL: paulramnoracoder@yahoo.com
GITHUB: https://www.github.com/pramnora
--------------------------------------------------
CREATED: Sun 18 August 2024 01:30 PM GMT
UPDATED: Sun 18 August 2024 01:30 PM GMT
--------------------------------------------------

------------------------------------------------------------------------------
Skillshare Course: 'Java Programming for Beginners: Code in One Hour'
------------------------------------------------------------------------------

The video said I should go and join Replit...; no problem, as I'm already a member of Replit web site, anyway.

- https://replit.com/~
- https://replit.com/@paulramnora

-----

1,1: Java print 1/(my changed code):

>>>
public class HelloWorld {
  public static void main(String[] args) {
    //*** single line comment...

   /* Multi-line
        comment

        block
   */
   // *** commented out line(s) no longer runs, anymore...
   // System.out.println("hello world!");    
       System.out.println("Hello world!"); //...end of line comment/changed 'H'
  }
}

Output:

Hello, world!

Check out the code here(where you may read/run/interact/change it):

- https://replit.com/@paulramnora/ProgramAnatomy-1#HelloWorld.java

-----

1,2: Java print 2/(my changed code):


public class HelloWorld {
  public static void main(String[] args) {

   /* The following line has been commented out...;

        and, therefore, won't run, anymore. */
   // System.out.println("hello world!");

   //*** changed the output text...
    System.out.println("Welcome to the wonderful world of Java programming...!");
  }
}

Output:

Welcome to the wonderful world of Java programming...!

 

Check out the code here(where you may read/run/interact/change it):

- https://replit.com/@paulramnora/Methods-1#HelloWorld.java

-----

1,3: Java print 3/(my changed code):

public class HelloWorld {
  public static void main(String[] args) {

    //*** how to do a vertical line break...
    System.out.println("hello\nworld!");
  }
}

Output:

hello

world!

 

Check out the code here(where you may read/run/interact/change it):

- https://replit.com/@paulramnora/Methods-1#HelloWorld.java

 
-----

public class HelloWorld {

  /*
    This programs demonstrates the use of 2 types of 'for' looping...

    1. A simple and straight forwards for loop counting up from 1 to maxNo

    2. A double for loop which is used to print out the 12 times tables
  */

  public static void main(String[] args) {
    String hw = "Hello, world!";
    printMultipleHelloWorlds(hw,4);
    System.out.println("\n");
    printTimesTables(8);
  }

  //*** A single for loop example...

  public static void printMultipleHelloWorlds(String hw, int howMany){
    for (int eachRepeat = 1; eachRepeat <= howMany; eachRepeat++){
      System.out.println(eachRepeat + "> " + hw);
    }
  }
 
  //*** A double for loop example...

  public static void printTimesTables(int tablesNo) {
    System.out.println(tablesNo + " Times tables:-" + "\n");  
    for (int timesNo =1; timesNo <= 12; timesNo++){
      System.out.println(timesNo + " X " + tablesNo + " = " + (timesNo*tablesNo));
    }
  }
 
}

Check out the code here(where you may read/run/interact/change it):

- https://replit.com/@paulramnora/ProgramAnatomy-1-1#HelloWorld.java

-----

 

CONCLUSION

 

What I've learned so far to date is this...code is NOT learned by, simply, 'reading(a book)/or, watching it(on YouTube)...; but, instead, code is learned by 'doing it'...; by, actually, physically typing all of the codes in...; and, then, running that code to see if it truly works/or, not...? But, if not...then, having to go back in and, repeatedly, correct and correct it...up until the point when you do, eventually, manage to get each and every single code line working properly.

So, basically, the gist of what I'm saying is this...; we learn, believe it or not, by making an endless series of 'mistakes'...; it is a process of, constantly, having to 'adjust'...; we try/we fail...we try our best to find out why we are failing/we go back in and correct...; we try/we fail, all over, again...; and, so this 'try/fail' loop keeps on getting repeated...; that is the exact process of how we learn to code.

Thus, 'learning the art of coding' is not necessarily getting that code to work immediately right away like every single time...; nope that's just living in a world of pure 100% fantasy...lol(or, maybe, only exists in the realm of what are absolute 'genius')!

You would NOT believe just how many mistakes I had to make...before I could eventually get the code up and working, properly; sometimes, the Java compiler complained at me...that if had found, at least, 6 errors...; all because I had left out something really straight towards and simple like...

- a missing semi-colon symbol at the end of the line

- a mis-spelled variable name: TimesNo, should have spelled: timesNo

- I'd gone and placed the called method at the very bottom of the program...meaning ,outside of the main program class block...UGH

- At one point, I wondered why my call to a for loop function was printing out a '0' at the end; which I most certainly didn't ask for...??? And, also, why it would not let me write 'public static void functionName()'...it said 'void' cannot be used here! The problem was I was trying to call the function from inside of another function: 'System.out.println(functionName())'; but, when I changed that call to far more simply say: functionName()...then, Eureka! Everything worked(I could even use 'void', now, as well).

...and, many other seriously stupid things like that...?! Believe me, these sort of errors just goes endlessly on and on and on.