Helping Course for JAVA part 1 ~ TnkCoding

in programming •  7 years ago 

     Good evening students and fellow inspired people that want to learn Java. Java is one of the easiest and flexible languages to learn. It is good for beginners. This course however is for people already who have a small understanding and would like to freshen up their knowledge. This is not a "Hello World" kind of tutorial. 

In this part we will cover:

  • Arrays
  • Functions

In the next part we will cover:

  • Recursion
  • Objects

     We will skip the what the variables are and how to initialize them since we take into considering that you understand that. If you don't leave me a comment and if there are more people willing to learn from scratch I will create another tutorial for complete beginners.

     So now we can jump into it. First things first, we will cover arrays since they are the most common thing used. Arrays are amazingly important since it is the simplest form of data structures. Easy to access and easy to use. So, what is an array?

     An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. To see if you understand arrays you must be able to solve the following:​

  • Create an Integer array of N length.​
  • Fill that array with random values.​
  • Create another array and copy the first one.​
  • Reverse the second array.​
  • Shuffle the first array.​
  • Create a two dimensional array and fit in the first row the first array and in the second the second array.​
  • Print the third array.​
  • Put the values of the first array in order and print them.

Before continuing onward try to see what you can do. Then scroll further and view the solutions. The trick to learning is not just to view the solutions but to also understand what happens. Try to read line by line the code and understand what it does and WHY it does it. That "why" is extremely important to understand. That is how I learnt how to code.

Here are the results, don't just look at it, try and understand it:

If you understand this then there is nothing else to freshen up on arrays. Once again if you don't understand even this then you need to do a complete beginners course and tell me in the comments and I will make it.

     Next we will see a bit about functions. A function can also be called a method so do not be confused when you see that name. So what is a method.  A Java method is a collection of statements that are grouped together to perform an operation. Each method can return up to ONE variable. Instead of typing each time the same code, you group it up as a method and just keep calling that one. What these functions return is depended explicitly on what you set them to return.

WARNING: If a method is called from a STATIC method then it requires to also be STATIC 

Simple example of the use of methods.:

  1. What is Integer.toString()?​
  2. Why can I call a method as a parameter for another method?​
  3. How can I have two methods with the same name and type?​

Answers: (once again try to figure it out and then try to understand the answers not just read them)

  1. Integer is a class given to us by Java and we are calling the toString() method of that class.​
  2. Because the first method returns integer so it’s like giving an integer as a parameter.​
  3. The requested parameter types are different.​

Now try to solve these ones and let's see if you really understand methods. What will the print call actually print?

a=0 b=1 c=0 d[0]=2​

The values of a and c don’t change because any changes that happen in a method stay in that method.​
The value of b changed because a value was returned to it.​
The value of d[0] changed twice. It changed every time we use the command d[0]++ because there we were targeting an address in the memory of the program.​
However when we used it as e++ then it ignored it.​

     This should have been enough to freshen up your knowledge, IF you actually made your brains think while reading this. To learn programming you need to be able to think. That is why I didn't write anything else on how to write methods because if you can understand what I wrote the rest can be thought up quite easily. So use your brains. If this was helpful don't be shy, leave your upvote and comment for me to see that you want to see more. It will be really appreciated by me! And if you didn't understand something ask me in the comments. I will try to solve anything uncleared.

     Thank you for your time. I hope to have helped you and that you will want me to make more. Goodbye.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Very useful for new people in programming ! thank you!