A Methods Meaning

Hello, how are you doing? well i am fine indeed.On my last post we talked about class in programming, today we’ll talk about Methods because methods are one of the most important chunk of code inside a class(check out my last post about Classes). First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

Methods… hmmm… methods, I wonder what it is, and what does it have to do with classes and objects. To get the answer let’s take a look at methods definion? well here it is
: a methods is a particular form of procedure  for accomplishing or approaching something, especially a systematic or established one.


You might wonder, what the heck does that suppose to mean? well… first… you’re tricked, this is not the real definition of methods in programming, this is a methods definition in general (haha!). I feel bad doing this, so I’ll just give you the definition of methods in programming, and here it is : A method in OOP is a programmed procedure that is defined as a part of a class and will be included in any object in that class.

How to call or execute a method? that is easy, well it took me some time to understand it but you will to eventually, here is how to call a method : 

Let’s take a look at an example of a methods :

/** the snippet returns the minimum between two numbers */ public static int minFunction(int n1, int n2) {
      int min;
      if (n1 > n2) min = n2;
      else min = n1; 
      return min; 
}

 There are actually two ways in which a method is called i.e. method returns a value or returning nothing (no return value). The process of method calling is simple. When a program invokes a method, the program control gets transferred to the called method. This called method then returns control to the caller in two conditions, when: 

  • return statement is executed.
  • reaches the method ending closing brace.

Easy right? you’ll get yourself better at it within time and within a lot of practicing. 

How about now? feeling better understanding this? well I hope you do, if you’re feeling better… let’s get to one of the most important method capabilities that is provided is methods overriding. The same name (e.g., area) can be used for multiple different kinds of classes. This allows the sending objects to invoke behaviors and to delegate the implementation of those behaviors to the receiving object. Methods inside Java programming will set the behaviour of the class object. For example, an object can send an area message to another object and the appropriate formula’s that is created will be invoked whether the receiving object is a rectangle, circle, triangle, or something else etc…
 
 Conclusions

  • A methods is a particular form of procedure  for accomplishing or approaching something, especially a systematic or established one. (In General).

  • A method in OOP is a programmed procedure that is defined as a part of a class and will be included in any object in that class.
  • This called method then returns control to the caller in two conditions, when: 
    • return statement is executed.
    • reaches the method ending closing brace. 

 

What is a Class in Coding?

Hello, how are you doing? well i am fine indeed.On my last post we talked about Reference data types, today we’ll talk about Classes in coding, what is it definition, example etc… because classes is one of the important things in OOP(see my last post about Reference Data Types). First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

What is a class? is it the place that you go to every morning when school day? well it is but that’s when you’re talking about it’s general meaning. Here we’ll talk about classes in coding, first… let’s get a grip of the meaning of the class itself,
a class in coding is a blue print from which individual objects are created. Just think of one bycicle, there must be thousands of the same kind of bycicle that exist in this world, but think… all of those bycicle will have the same blue print that is used to make it, and will have the same component for its creation. In object-oriented-programming terms, we should say that your bicycle is an instance of the class of objects known as bicycles. A class is the blueprint from which individual objects are created.

A sample of a class is given below:

public class Lion{
String maleorfemale;
int ageC
String color;

void roaring(){
}

void hungry(){
}

void sleeping(){
}
}

A class could contain any of the following variable, types :

  • Local variables: Variables that is defined inside the class methods, constructors or blocks are called local variables. The variable that is created will be declared and initialized within the method inside the class and the variable will be destroyed when the method has completed.
  • Instance variables: Instance variables are variables within a class but outside any other method. These variables will and are initialized when the class is instantiated. Instance of the variables can be accessed from inside any method, constructor or blocks that exist from that particular class.
  • Class variables: Class variables are variables declared with in a class, outside any method, with the static keyword.

A class can have any number of methods to access the value of various kinds of methods. In the above example, roaring(), hungry() and sleeping() are methods

Conclusions :

  • A class in coding is a blue print from which individual objects are created. 
  • A class could contain any of the following variable types : 
    • Local variables
    • Instance variables
    • Class variables

Reference Data Types

Hello, how are you doing? well i am fine indeed.On my last post we talked about Primitive data types, it’s still within the OOP and so the one that we’ll be talking right now, today we’ll talk about Reference Data Types(see my last post about Primitive Data Types). First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

First thing first, let’s get a definition of what Reference data types means itself, here is my definition : A Reference data types is a data types that are based out of class rather than based of  a primitive types that is built into the java language. The class that’s mentioned can be a class that Java API class library provides or it can be a class that you made yourself.


Well either way, when you create an object from a class that you or the java api class librabry made, Java will allocates the total memory that the object requires to store the object. And then, if you put or assign the object to a variable, the variable that is assigned is a reference to the object, not the object itself. This reference is the address of the memory location where the object is stored.
If you want to declare a variable that will use a reference type, you need to simply list the class name as the data type. For example, the following statement defines a variable that can reference objects created from a class named Bike:

Bike b;
after that you need to import to tell Java where to find the class. If you want to create an instance of an object from a class, you need to use the new keyword along with the class name, example :

Bike b = new Bike();

One of the key concepts that you always need to remember in working with reference types is the fact that a variable of a particular type doesn’t actually contain an object of that type. Instead, it contains a reference to an object of the correct type. An important side effect is that two variables can refer to the same object.

Consider these statements:

Ball b1 = new Ball();
Ball b2 = b1;
 

Here, both b1 and b2 refer to the same instance of the Ball class.

conclusions 

  • Reference data types is a data types that are based out of class rather than based of  a primitive types that is built into the java language.
  • If you want to create an instance of an object from a class, you need to use the new keyword along with the class name.
  • Two variables can refer to the same object.

Primitive Data Types

Hello, how are you doing? well i am fine indeed.On my last post we talked about object inheritance, an inheritance in the viewside of coding. Today, we’ll still talk about OOP because there is so much we need to cover, now we’ll talk about Primitivedata types in Java. First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

Java programming language is statically-typed, which means that all variables must be declared before they can be used, so this will involve stating the variable’s type and name just like you already know :

int = 1;

You see… this will relate to primitive data types, “why?” you might ask, it’s because that int is one the 8 primitive data types that the Java language use, before we’ll get to the 8 of the primitive data types, let’s find the definition of primitive data types itself.
Primitive data types is a data types that directly contains value, now like refference data types, that reffers to an object(we’ll talk about that later).

Now that we know its definitions let’s find out the 8 primitive data types, here is the list with its explanation :

  • byte: The byte data type is an 8-bit signed two’s complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable’s range is limited can serve as a form of documentation.
  • short: The short data type is a 16-bit signed two’s complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same guidelines apply: you can use a short to save memory in large arrays, in situations where the memory savings actually matters.
  • int: By default, the int data type is a 32-bit signed two’s complement integer, which has a minimum value of -231 and a maximum value of 231-1. In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 232-1. Use the Integer class to use int data type as an unsigned integer. See the section The Number Classes for more information. Static methods like compareUnsigned, divideUnsigned etc have been added to the Integer class to support the arithmetic operations for unsigned integers.
  • long: The long data type is a 64-bit two’s complement integer. The signed long has a minimum value of -263 and a maximum value of 263-1. In Java SE 8 and later, you can use the long data type to represent an unsigned 64-bit long, which has a minimum value of 0 and a maximum value of 264-1. Use this data type when you need a range of values wider than those provided by int. The Long class also contains methods like compareUnsigned, divideUnsigned etc to support arithmetic operations for unsigned long.
  • float: The float data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead. Numbers and Strings covers BigDecimal and other useful classes provided by the Java platform.
  • double: The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.
  • boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its “size” isn’t something that’s precisely defined.
  • char: The char data type is a single 16-bit Unicode character. It has a minimum value of 'u0000' (or 0) and a maximum value of 'uffff' (or 65,535 inclusive).
The example and definition of those Primitive data types are obtained from Java documentary
 Conclusions 
  • Java programming language is statically-typed. 
  • All variables must be declared before they can be used
  •  Primitive data types is a data types that directly contains value, now like refference data types, that reffers to an object(we’ll talk about that later).
  • Java documentary 
 

Object Inheritance

Hello, how are you doing? well i am fine indeed.Since we talked about OOP much lately, let’s just get into one more important thing that OOP provides for us programmers or coders, which is an inheritance.We’ll get into it’s deep meaning and we’ll understands it more. First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

 Okay, there is one more important thing in OOP that i want to talk about, which is an object inheritance, before we get to coding object inheritance, let’s just get the general explanation for inheritance.
Inheritance is all part of a person’s estate/assets that is given to an heirs once the person is deceased or dead. An Inheritance basically is a cash endowments that is given to it’s younger heirs from the people that are deceased. If at the time of death a will is not in place, determining the rightful heirs can be a much more complicated matter.

Wait!! we’ve gone to far now! Pheww, I lost my tracks. Let’s get back to coding, now we’ve understand what inheritance in general means, let’s get to OOP inheritance. If an inheritance in general lead to cash endowment or assets, coding inheritance is a bit different, just imagine a bycicle superclass is bycicle then after that comes another placements, types of bycicle, there are mountain bike, tandem bike etc… now the types of the bycicle are the class that inherits from bycicle, both of them had their own properties but will, have the properties that is passed down from superclass Bycicle, if you’re confused just read this, in coding an inheritance is when an object is based from a prototype of another object, using the same implementation (inheriting from object or class) specifying implementation of the object to maintain the behavior to be similar.

There we go! now that’s a coding inheritance, in coding we won’t be confused with an heirs and assets(haha). Now that we know what inheritance in coding is, let’s get some more information about object inheritance, there are 5 types of inheritance that I know, which is :

  • Single inheritance: Where the subclasses of an object will inherit the features of one superclass. A class acquires the properties of another class.
  • Multiple inheritance: Where one class can have more than one superclass and the object will inherit features from all parent classes.
  • Multilevel inheritance: The class A serves as a base class for the derived class B, which in turn serves as a base class for the derived class C. The class B is known as intermediate base class because it provides a link for the inheritance between A and C. The chain that we got from A, B and C is usually well known as an inheritance path
  • Hierarchical inheritance: Where one class of an object will serves as a superclass (base class) for more than one sub class.
  • Hybrid inheritance: A mix of two or more of the above types of inheritance.

Conclusions

  • General : Inheritance is all part of a person’s estate/assets that is given to an heirs once the person is deceased or dead.
  • Coding :  inheritance is when an object is based from a prototype of another object, using the same implementation (inheriting from object or class) specifying implementation of the object to maintain the behavior to be similar.

Byte code, Machine code, Source code

Hello, how are you doing? well i am fine indeed.Last time we talked about OOP or Object Oriented Programming, we see how OOP can benefit us. We talk about it’s definition, it’s example, it’s advantages and stuff.Now we’ll talk about a compiled programming language, since Java is a compiled programming language. First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

Probably you already know that java is an OOP and compiled programming language, but what is the meaning of compiled programming language, what is it benefitial? well basically a compiled programming language is a programming language that compiles instruction that the operators write into bytecode or machine language with the help of an IDE.Another explanation is, A compiled language is a programming language that its implementations are typically based to be compilers (translators that will generate machine code from the source code that operators write), and not interpreters (step-by-step instruction executors of the source code itself, where there are no pre-runtime translation that takes place).


Now you might wonder, what the heck is bytecode, machine code and source code is? good question, and as for that I will answer. What is bytecode? Bytecode, also known as p-code or a portable code, is a form of instruction that is set and designed for efficient execution by a software interpreter, that is its general definition, but… as for the Java bytecode, bytecode is a set of instruction that is created by the Java virtual machine. Each bytecode is composed from one or two bytes that represents the instruction (p-code).

Not to much of a difficult things right? well then… let’s move to machine code. What is a machine code? let’s just divide it into 2 part: first is the machine, the machine represents our computers or any machine that run codes, second… code is a Code!!. Well as for the explanation is, a computer programming language that uses binary or hexadecimal insturction that consist of one and zero(bits) that the computer can responds to directly using it’s central processing unit (cpu). Phewww… easy right? now that you understand what machine code is you could get a deeper meaning in coding.

Last one is our Source code, what is a source code? here is my explanation, source code is a list of text that contains commands or instruction created by operators in a read-able computer language that needs to be compiled to a machine code then will an executable computer program.The source code of a computer program is specially designed to be a facilites for the work of computer programmers, who then… will specify the actions to be performed by a computer mostly by writing source code.

Now that you understand those 3 parts that consist in OOP, I hope you will be better at coding using OOP programming language, since now you understands its meaning and part.

Conclusion

  • A compiled programming language is a programming language that compiles instruction that the operators write into bytecode or machine language with the help of an IDE.
  •  Bytecode, also known as p-code or a portable code, is a form of instruction that is set and designed for efficient execution by a software interpreter.
  • Java bytecode, bytecode is a set of instruction that is created by the Java virtual machine. Each bytecode is composed from one or two bytes that represents the instruction (p-code).
  • a computer programming language that uses binary or hexadecimal insturction that consist of one and zero(bits) that the computer can responds to directly using it’s central processing unit (cpu)
  • source code is a list of text that contains commands or instruction created by operators in a read-able computer language that needs to be compiled to a machine code then will an executable computer program. 

OOP or Object Oriented Programming

Hello, how are you doing? well i am fine indeed.Last time we talked about each of Java and Javascript pros and cons, both of them had their own advantages and disadvantages, but they’re basically the same.Now we’re going to talk about OOP or Object Oriented Programming, what is its definition, example and stuff. First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

What is an Object Oriented Programming? (or we’ll call it OOP just for a shorter instance) OOP is just a programming language that often uses object as its coding bases. If you wanted to be more specific, Object Oriented Programming is a programming language model that is organized around “objects” rather than logic manipulating, OOP takes the view that what we really care is the object that manipulate itself rather than the logic required to manipulate them. It may sounds confusing, so you could just uses the first definition for your beliefs.

What programming language that uses OOP as its base, can you guess? i’ll give a clue, we talk about it in more or less about 3 post, we make a program with it using an IDE. Can you remember now? okay i’ll tell it to you now, it’s Java!! yes, Java is an Object Oriented Programming, just think that we need to make a ball object, a function, method etc… and I’d just tell you in my last post, Java vs Javascript, in there I explained that Java is an Object Oriented Programming language.

What is the basics of Object Oriented Programming or OOP ? well there is actually 10 basics of OOP that I knows, here are the list :

  • Abstraction
  • Class
  • Encapsulation
  • Information hiding
  • Inheritance
  • Interface
  • Messaging
  • Object
  • Polymorphism
  • Procedure

 Let’s talk about 3 of them, which is : Class, Inheritance and Object itself.

First… Class, what is a class?, not that kind of class you go everyday, a Class in Coding, well here is my definition, a Class is a category of objects, a class will contain all of the common properties that belongs to any objects wether it’s different or not.We can also say it in another way, a class is an extensible program-code-template that used to create objects, and could also implements behavior.

Second… an Inheritance, what is an enhiritance?, Just imagine like our world, that every object has something in commong, just for example, a monkey and a human, both of them are a living things, both of them has hands, legs, eyes, ears and mouth, but there is something in someway that seperate a monkey and a human, well it’s called an Inheritance, an Inheritance are the way of some objects will shares similarities like characters but in one if them has some difference, but still inherit something from another object. Well that’s pretty easy right? now let’s move to the last one.

Third… an Object, what does an object means in programming? is it the same definition with the one’s that are in real life? well… an object in a programming language is a particular instance to a “Class” which the object itself can be combination of variables, function and data structures.

What is the advantages that people sees in OOP, One of the most common advantages of object-oriented programming techniques rather than using normal programming techniques is that OOP would allow the programmers to create a somewhat a modules that do not need to be changed over and over again, when a new type of object is added to the program. A programmer can simply create a new object that inherits many of its features or functionality or properties, from existing objects. This makes object-oriented programs easier to modify.

Conclusions :

  •  OOP is a programming language that often uses object as its coding bases or Object Oriented Programming is a programming language model that is organized around “objects” rather than logic manipulating, OOP takes the view that what we really care is the object that manipulate itself rather than the logic required to manipulate them.
  •  Java is an Object Oriented Programming.
  • a Class is a category of objects, a class will contain all of the common properties that belongs to any objects wether it’s different or not
  •  an Inheritance are the way of some objects will shares similarities like characters but in one if them has some difference, but still inherit something from another object.
  • an object in a programming language is a particular instance to a “Class” which the object itself can be combination of variables, function and data structures.
  • The advantages of OOP, A programmer can simply create a new object that inherits many of its features or functionality or properties, from existing objects

Java vs Javascript

Hello, how are you doing? well i am fine indeed.On my last post we just made ourself another version of movingBall program, it’s the same movingBall program but written in different programming language. We made ourself 2 movingBall program, first one in Java and second one in Javascript, well now it’s time for us to take a look at pros and cons from both Java and Javascript. First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

First let’s get the definition of both Java and Javascript, Java is an Object Oriented Programming language while Javascript is an Object Oriented Programming Scripting Language. Both of them are an OOP language but there is a difference, Javascript is a OOP scripting language and what does that means? a scripting language is a programming language that supporst script, program written for a special run-time environment that automate the execution of somekind a task that alternatively can be executed one by one with human operator. An environments that can be automated through scripting is, software applications, web pages within browser, and some numerous numbers of games.


Java is a compiled programming language, it is typically written in an Integrated Development Environment (IDE) and compiled into a bytecode, bytecode is not readable for human language and any Java Virtual Machine could run it. Javascript is a programming language that is Interpreted rather than Compiled, an Interpreted programming language is a programming language that execute the instruction directly, without previously compiling it into a machine-language. Javascript may be easier to create because it doesn’t need to be compiled and deployed like Java, Javascript sometimes can be just created by using a simple text editor like notepad++

Both of java and javascript can be runned inside a browser, in modern browser they obviously take advantages to enhance’s the users experience.Java applet can also be runned in browser, but it have been declining in it’s popularity for various of reasons, first it’s compatibility issues even to security reasons. It is been widely common for a website visitors that it’s javascript is enabled and it is also widely common for a website visitors that it’s Java applet is disabled, especially in mobile browsers.

In javascript you need to send it to the internet first or to your browser first to get the program works, but Java can create a standalone application that doesn’t need any other intermediary to run it, it works on it own. The standalone application is called a Java “applet” (so-called like that because it is a little application) that is a fully contained program. While javascript can only be runned in Javascript with the help of Html and CSS.

Each of them had their own pros and cons, you should pick one programming language that suites you heart, the one that you get comfortable with. Well you could learn both of them but after that choose one that you’ll go deeper with.

Conclusions:

  • Java is an Object Oriented Programming language
  • Javascript is an Object Oriented Programming Scripting Language
  • a scripting language is a programming language that supporst script, program written for a special run-time environment that automate the execution of somekind a task that alternatively can be executed one by one with human operator.
  • Java is a compiled programming language
  • Javascript is a programming language that is Interpreted
  • A compiled programming language is a language that compiles codes into machine-language
  • Both of java and javascript can be runned inside a browser
  • Java can create a standalone application that doesn’t need any other intermediary to run it

MovingBall in Javascript

Hello, how are you doing? well i am fine indeed.In my last post we get our brain and finger exercised on Javascript, we did our exercise in Chrome development console well it’s just for an exercise, but today we’ll do some real Javascript coding, we’ll simply make a Movingball program just like in Java.The way to do this is we need to make a Html file that contains javascript, so let’s do that right now.  first I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

First we need to make an HTML file, you can do this in the notepad++ it can be freely downloaded, now let’s make the structure of the Html, since we don’t really talk about Html much in this blog i’m just going to give you the important Html code structure which looks like this, the canvas is just how big that we want  the background of the painting will be, so don’t worry:


<!DOCTYPE html>
<head> 
<title>MovingBall</title>
</head>

<body>
    <canvas id=”canvas” width =”700″ height=”700″></canvas>
    <script> 

                  /*the section that
                 
we’ll write some Javascript in it*/

    </script>
</body>
</html>

 you just need to write this inside the notepad++ and save as Ball.html (you could name it whatever you want, as long it ends with .html) now after you save that as Ball.html  you will see some changes that is applied to your code, now it has colors right it’s just a helping technique that will help programmer write their code more efficient and more easy.

Now after we finished with the html, let’s work some javascript! the structure prototype and function of this MovingBall is a lot similar with the one that we did with Java, but this one is going to be more easy because it doesn’t have variable typing and class that needs to be created etc… so let’s write it inside the
<script></script>:
first we’re going to make the ball object or ball prototype :
  var Ball = function() {
    this.x = 100;
    this.y = 100;
    this.xSpeed = -5;
    this.ySpeed = 6;
    this.border = 10;
    };

after this we’re going to create a function that will draw a circle whenever it’s called or executed, this is how we write it:
  var circle = function(x, y, radius, fillCircle){
        ctx.beginPath();
        ctx.arc(x, y, radius, 0, Math.PI * 2, false);
        if (fillCircle) {
            ctx.fill();
        } else {
            ctx.stroke();
        }
    };

good now we have created a circle function, now let’s add some more function for our ball, just like draw, move and checkCollisions :
    Ball.prototype.draw = function(){
        circle(this.x, this.y, 20, true);
    };
   
    Ball.prototype.move = function(){
        this.x += this.xSpeed;
        this.y += this.ySpeed;
    };
   
    Ball.prototype.checkCollision = function() {
        if (this.x < 0 + this.border || this.x > 700 – this.border) {
        this.xSpeed = -this.xSpeed;
    }
        if (this.y < 0 + this.border || this.y > 700 – this.border) {
        this.ySpeed = -this.ySpeed;
    }
    }

you see it’s not that different than what we write in our Java coding right? so this will be pretty much easy. Do you have any clue for what we need to write next? we’ll since we’re in javascript environtment inside html inside a browser (yeah right! we’re going to run it in a browser) we need to call a chunk of code that will get the 2d context for the program and this is how we do it:
    var canvas = document.getElementById(“canvas”);
    var ctx = canvas.getContext(“2d”);

 after we create the canvas and context environtment now we’re going to call the ball object or ball prototype and after that we paint or call everybit of code in this program repeatedly over and over, so we write it like this:
 var ball = new Ball(); //we call the ball object or prototype
   
    setInterval(function () {
        ctx.clearRect(0, 0, 700, 700); //we clear the background
        
        ball.draw();
        ball.move();
        ball.checkCollision();
      
        ctx.strokeRect(0, 0, 700, 700); //we create a stroke for the background
        ctx.
        ctx.fillRect(350, 350, 40, 40); //we create a white background
    }, 30);

And you need to remember that you need to write this inside the <script></script> tags or it will never work.
Now, the way you run it is you go to the location of you saved Ball.html, now right click on Ball.html and select open with>(you can choose any browser, but i recommend using firefox or chrome) then… tada!!!! you just make a moving bouncing ball in javascript inside html inside a browser, fun right this may seems much easier for you to understand rather than Java that is a strong typed language, well javascript is easier but each of them had their own advantage and disadvantages just find which one you’re comfortable with.

Javascript Warm Up

Hello, how are you doing? well i am fine indeed.In my last post we talk about Javascript, its history, the guy who made it, what is its used for, “var” and more. We also use Javascript to make our web browsing more unique by implementing animation and rendering, which is very cool and we also could do things like that if we learn Javascript. Now, we’re going to exercise JS or JavaScript, first I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

First we need to find a place to learn our javascript, and luckily Chrome serves us right! Chrome implemented a development console in the browser to do JS stuff, well firefox also did implement development console but lets just use chrome for the sake facility. Now, open your chrome and go to a blank page, if you don’t know how you just type about:blank in the address bar, well this is only optional but it’s easier to just see blank page first when writing our code, now let’s get to writing part!.


Now we got that sorted out let’s write some javascript! now you need to open the development console in the chrome, if you don’t know how this is how you do it, first open the google chrome control menu –> hover you mouse to more tools –> click development tools. That’s the long way to open the development  console, for simplicity sake just use Ctrl+Shift+I, got you! (haha). Now for a warm up, let’s just write the most simplest code that we’ll write today, just type 1 + 1 you don’t need to put an equal( = ) sign, just do that and hit ENTER and… that’s it you just write a succesful piece of code(By the way it should output the number 2). You may try to even billions of number calculating but the computer will always answer as long as you put the syntax right.


Remember when I say javascript is an Untyped programming language, it means that we could use “var” variables for any type of data we want, we could put number inside it, text, commas, special character etc… so if you want to make a position of an object that is keep changing you could use the “var” variable, for example ” var x1 = 200 ” as position 1 and we need to make it move 100 pixels to the right and we make a variable for that too ” var x2 = 200 ” and what we need to do is add those 2 variables together, so we do this “ x1 + x2 ” and it will output 400, it’s just the same when we calculate just the number only, like 200 + 200 but in this case we use the variable to keep track of the numbers that is keep changing.

Well it’s quite easy isn’t it?! it’s just a tini tiny part of code that you can write in javascript, now let’s move to a bit more advanced javascript coding, let’s output your name into the console of javascript world, first you make a variable called “name” and inside that variable you put your name in a string type, it should look like this ” var myName = “you’re name”; ” well it wouldn’t output anything at the moment but it’s just the shell for our next code. After that lets output our name to the world, type this in the console  myName + ” is awesome”; ” (you could put anything inside that string), here what it would output if I do it with my own name :
Rafif is awesome
tada! we made it isn’t it fun, (tell me how you did it with your own name).

Now let’s get to a more complex piece of code, we’ll output our name to the console 10 times automatically without human help, what do I mean without human help? it means that when we execute the code the computer will automatically outpute 10 of the requested output, so lets do that right now!. first you make your name variable just like before, second we’ll make a function that will output the information of our variable for 10 times, here is how we create the function:

var myName = function (howMany) {
for (var i = 0; i < howMany; i++) {
console.log( i + name + ” is awesome”);
}
};

after we create the function it’s time to execute or call the function!:

myName(10);

tada! you just make another piece of working code, by the way this is how my output looks like :

0Rafif is awesome
1Rafif is awesome
2Rafif is awesome
3Rafif is awesome
4Rafif is awesome
5Rafif is awesome
6Rafif is awesome
7Rafif is awesome
8Rafif is awesome
9Rafif is awesome

In javascript you could make such many other things, not only number calculating but you can make an animation or even a game! wooww! cool right? you could do such things like that if you learn it and understand it, and by it I mean javascript, so keep learning!.