Posts

Power On!

Welcome to this series of blogs. Let's do a review of our favorite languages! Looking for the next piece on Applications ^ Data? See here! These blogs are designed to trigger questions and discussions. It's not about being right or wrong. The purpose is to discover, know and develop. Feel free to leave comments, ask and answer questions, voice opinions and enjoy! Guideline : Please be respectful and welcoming of everyone's views and questions. You are now a part of our team :) Click here  to attempt the  assessment of this series Notes: - You can login using your gmail id . If you have provided us the gmail id already, it will succeed. - Otherwise, please write a mail from your gmail id to sudeep@rapalearning.com with subject Bootcamp access - Each lesson has an assessment. Each assessment can be submitted once. Here's is a sequence we suggest: Building block of polymorphism : Start here for a fun exercise to program an artillery firing sequence... in C...

JavaScript functions

Functions are famously called first-class citizens of the JavaScript world. Functions can smoothly be treated as a variable,  For example, if we execute this in a browser: function myFunction(a, b) {   return a * b; } var x = myFunction; console.log(x(3,4)); It will log 12. The declaration of myFunction makes it a 'value', which is assigned to a variable 'x'. Notice that there are no parenthesis in that assignment. Next, we have a log that invokes myFunction by applying the parenthesis () operator on the variable. The log statement logs the return value of myFunction, which is the product of 3 and 4. Let's say we forget the parenthesis: console.log(x); This will log the function itself! Try it out in your browser by enabling the console display via the 'developer tools' option. Of course, this will just call the function normally: var x = myFunction(3,4); It's just the application of the () operator to call a...

JavaScript data-types

JavaScript is a versatile language that's used in programming everything from web pages to servers and desktop applications. We will use this interactive tutorial  as a reference in our journey. JavaScript is different from the other languages we've seen here (C++, C#, Java), in that it doesn't have a compiler. The code is interpreted while running it. This brings us to a distinction in data-types as well. JavaScript doesn't fix the type of its variables. For example, this is a valid sequence for the interpreter: var x;           // x is undefined to start with x = 15;          // After this assignment, x is a Number x = "Phil";      // Here x becomes a String Many other fun things can happen with JavaScript data, as you can see here . What could be the use of such flexibility? Tell us what you feel below. Hint: Think of real-life arrays - like array of vehicles, array of chat messages...

Java Characters

Characters are represented by codes. ASCII is a standard for alphabets and a few symbols. For example, the code 65 is used for the letter 'A' char c1 = 65; System.out.println(c1); Will print the character A. Modern Java compilers and Operating Systems are aware of Unicode characters. Unicode is a standard system of encoding characters in all known scripts. Here's code to print the recent 'Rupee' symbol: char c1 = 0x20b9; System.out.println(c1); Will print the symbol  ₹ If you don't have a local Java compiler, you can use this online compiler . Explore Unicode. Share some characters and the corresponding codes of your mother-tongue. Click here to power back

Java Strings

If you are unfamiliar with Java or interested in a refresher, use this link . In this blog we look at some quirky dealings with Java Strings. We'll be using concepts of Java variables , data-types and operators and especially Strings . The following code constructs two strings  s1  and  s2 . When they are compared, their contents are identical. String s1 = "12345"; String s2 = "123"; s2 += "45"; if(s1 == s2) {     System.out.println(s1 + " equals " + s2); } else {     System.out.println(s1 + " does NOT equal " + s2); } Strangely, this code reports that the strings are not equal: 12345 does NOT equal 12345   Why is that? How do we fix this? Notice the change in bold below. String s1 = "12345"; String s2 = "123"; s2 += "45"; if(s1.equals(s2)) {     System.out.println(s1 + " equals " + s2); } else {     System.out.println(s1 + " does...

C# Collection and Iteration

C# has powerful structures for dealing with collections and other data structures. In this blog, we'll be using string formatting  and lists . Click on the links if you haven't done them in C# before. var names = new List<string>   { "nobita", "bheem", "oggy", "oggy cockroach", "ninja" }; foreach (var name in names) {     if(name.StartsWith("oggy")) {         Console.WriteLine($"Need to remove {name}!");         names.Remove(name);     } } This code tries to remove names starting with "oggy" from a list. Try it in the interactive editor offered by the above tutorial (click 'Enter focus mode' at the bottom of this site ) Does it work? No! Which is the line that's causing the crash? How would you resolve it? Click here to power back

C# loop optimization

See here for an interactive tutorial on control flows in C#. At the end of the tutorial, you see this piece of code, to sum all numbers between 1 and 20, which are divisible by 3 int sum = 0; for (int number = 1; number < 21; number++) {   if (number % 3 == 0)   {     sum = sum + number;   } }   Check the cyclomatic complexity  of this code. Is there a way you can simplify it by removing the nesting? Type your thoughts below. Going ahead, we'll look at using loops to iterate over a collection