The Best Self Learning and Documents Platform

Simple way to learn and analyse amazing documents for your project.

Friday, 30 June 2017

Welcome to C#

Welcome to C#


C# is a powerful language that is generally called a Component Oriented Language. Now we have heard of Object Oriented Languages, but what is a Component Oriented Language? Though the difference is unclear and thin, the reason why this new concept has become associated with C# is that a new technique was to be introduced that would develop software combining some pre-existing features (OOP) and welcoming some new components. Some of the components are:

  • Properties
  • Methods
  • Events
  • Attributes (Metadata-Data about Data)
  • Assemblies/Packages

Another major characteristic is the introduction of Separation Of Concerns (SOC) and the Service Oriented Architecture (SOA). SOC is Separation Of Concerns via partial classes in C#.

Versions in C#

The following  are the versions so far. The data is from C# Indepth. Please visit or follow the book to learn more about the various versions.

C# version 1

C# version 2: As said previously, in this version, Generics, Nullable types(), anonynous types and Iterators(blocks) were introduced.

C# version 3: As said previously, implicit typing, object and collection initializers, anonymous types, automatic properties, lambda expressions, extension methods, query expressions were introduced.

C# version 4: As said previously, dynamic typing, optional parameters, named arguments and generic variance were introduced.

C# version 5: As said previously, asynchronous functions, caller info attributes, a tweak to foreach (one of the examples is Parallel.Foreach (with Lambda expression)) and iteration variable capture were introduced. Caller info attributes is a very new concept and an interesting one too. These attributes track information about the calling methods/properties and many more.


A small incident to share, I always wondered why C Sharp?? Is it a kind of successor to C++ or what? I always wondered and I feel many beginner developers would be wondering. Thanks to Wiki the data warehouse for every bit of concept in the world for letting me understand why? Without any delay, straight from the WIKI,

The name "C sharp" was inspired by musical notation where a sharp indicates that the written note should be made a semitone higher in pitch. The sharp symbol also resembles a ligature of four "+" symbols that thus implies that it is an increment of C++.

Now let's get along and start learning from the basics.

Camel and Pascal Case Notations

Every time a developer gets into these concepts, but sometimes beginners like me would wonder what these actually are. Camel case is used for naming fields whereas Pascal case is used for naming properties and function names. In Pascal case, the starting letters in the multiword name are capitalized whereas in Camel case except the very first letter is all capitals as in the following:
  • Pascal Case: GetSumFromNumbers.
  • Camel Case: getFirstNumber.



Working with Variables, Operators and Expressions

Before getting into the variables, let's get into what an identifier is. Identifiers are the names that are used to identify elements in the program. In C#, there are the following conventions to be followed:

  • Only letters are allowed (it may be uppercase or lowercase), digits and underscore(_) characters are allowed. 
  • An identifier should always start with a letter.


For example, _getSum, GetSum, Get_sum are valid identifiers. Just to remember or keep in mind everytime that C# is case sensitive so getSum and GetSum are different and provide different meanings. Keywords, there are many keywords that are predefined in C#, for more info on the keywords, use the following link: C# keywords Now let's get back to our topic of discussion, variables. A variable is a location with memory or storage location that stores/holds a value. A variable in a program holds a unique name, its like madatory to provide it a unique name. A variable holds temporary information. A variable is used to get the value that it holds after assigning. In the following I specify the naming conventions to be followed when declaring variables specified by the Microsoft .NET team:

  • Underscores are advised not to be used.
  • Variables names that differ only in capitalization should be avoided. Like, abcTest or AbcTest used in the same file and at the same time. This would also mean identifiers with the same name and different case should be avoided.
  • It is advised to start the name with a lowercase. This would be consistent throughout since it would lead to easy maintenance.
  • Camel case notations should be used, for example, abcTest, myVariable, as such.
  • Declaring Variables is easy and simple. Usually the keyword var is used when the type is to be implicitly decided. If any datatype is already used during the declaration of the vriable, then it is explicitly typed.


As in the preceding piece of snippet, you can see the statement ends with a semicolon ";" that simply marks the end so the compiler knows that the statement ends there. The Equals operator is used to assign the value to the declared variable. C# also uses the same the operators that we as developers have been using in other programming languages (+(plus), -(subtraction), *(asterix/multiplication), /(divide) and also the modulo operator(%)). These are, as we know, called the arithmetic operators. We cannot apply the arithmetic operations on datatypes except int (integer type) in a similar way.


However using explicit conversion, a string can be converted into integers. For increment the values, the increment and decrements operators are also strongly followed in C#. 


Understand your first C# program

As we all know, every program follows a common rule that is Input, Process and Output. Let's have a go at it. 


When we run the preceding program, we get the following output. I am showing the output step wise, so that you get to understand the importance of the Console.WriteLine and Console.ReadLine.


As we see in the image, the console window opens when the project runs and asks for the first name. As we see in the program, first comes Console.WriteLine(), then when the user enters the name Console.ReadLine(), it plays its role and stores it in the variable memory firstName



As we see in the image, the console window opens when the project runs and asks for the last name. As we see in the program, first comes Console.WriteLine(), then when the user enters the name Console.ReadLine(), plays its role and stores it in the variable memory lastName.



Now when a final Enter is pressed by the user trying to understand what the program is doing. Yes, it gives the desired output. It concats the variables where the names/values entered by the user are temporarily stored in memory. {0} {1}, this actually contains the values entered by the user when asked and as said previously concats the input and displays the full name as the output. This could also have been done by using the "+" operator like:


There are many libraries that can be used in your program. These libraries need to be specified at the top of your program, in other words where the Namespaces are and they are used using a usingkeyword. :D Yes, so many use! When on the console window, something needs to be displayed, Console.WriteLine() is used and when we need to take the Input from the user and store it in memory, Console.ReadLine() is used. This is a simple and basic difference. The {0} used in our program, acts as a simple placeholder where the dynamic values are used by specifying the argument at the end. The many the arguments, the many the placeholders to be used. 

Conclusion

Thanks guys for having patience and reading through this. This is what I could cover in the first part and will continue some more interesting topics in the second part. Let's learn, let's explore and let's share.


Thursday, 29 June 2017

Method Overloading in Java with examples


Method Overloading in Java with examples

Method Overloading is a feature that allows a class to have two or more methods having same name, if their argument lists are different. In the last tutorial, we discussed constructor overloading that allows a class to have more than one constructors having different argument lists.

Argument lists could differ in –
1. Number of parameters.
2. Data type of parameters.
3. Sequence of Data type of parameters.

Method overloading is also known as Static Polymorphism.
Points to Note:
1. Static Polymorphism is also known as compile time binding or early binding.
2. Static binding happens at compile time. Method overloading is an example of static binding where binding of method call to its definition happens at Compile time.

Method Overloading examples:
As discussed above, method overloading can be done by having different argument list. Let’s see examples of each and every case.

Example 1: Overloading – Different Number of parameters in argument list
When methods name is same but number of arguments are different.
               


In the above example – method disp() has been overloaded based on the number of arguments – We have two definition of method disp(), one with one argument and another with two arguments.

Example 2: Overloading – Difference in data type of arguments
In this example, method disp() is overloaded based on the data type of arguments – Like example 1 here also, we have two definition of method disp(), one with char argument and another with int argument.
               

Example3: Overloading – Sequence of data type of arguments
Here method disp() is overloaded based on sequence of data type of arguments – Both the methods have different sequence of data type in argument list. First method is having argument list as (char, int) and second is having (int, char). Since the sequence is different, the method can be overloaded without any issues.
               

Let’s see few Valid/invalid cases of method overloading
Case 1: 


Result: Compile time error. Argument lists are exactly same. Both methods are having same number, data types and same sequence of data types in arguments.

Case 2:

Result: Perfectly fine. Valid case for overloading. Here data types of arguments are different.
Case 3:
               

Result: Perfectly fine. Valid case for overloading. Here number of arguments are different.

Case 4:



Result: Perfectly fine. Valid case for overloading. Sequence of the data types are different, first method is having (int, float) and second is having (float, int).

Case 5:


Result: Compile time error. Argument lists are exactly same. Even though return type of methods are different, it is not a valid case. Since return type of method doesn’t matter while overloading a method.

Guess the answers before checking it at the end of programs:
Question 1 – return type, method name and argument list same.

               

Answer:
It will throw a compilation error: More than one method with same name and argument list cannot be defined in a same class.


Question 2 – return type is different. Method name & argument list same.


               

Answer:
It will throw a compilation error: More than one method with same name and argument list cannot be given in a class even though their return type is different. Method return type doesn’t matter in case of overloading.


Wednesday, 8 February 2017

Symmetric-key algorithm


Symmetric-key algorithms are algorithms for cryptography that use the same cryptographic keys for both encryption of plaintext and decryption of cipher text. The keys may be identical or there may be a simple transformation to go between the two keys . The keys, in practice, represent a shared secret between two or more parties that can be used to maintain a private information link. This requirement that both parties have access to the secret key is one of the main drawbacks of symmetric key encryption, in comparison to public-key encryption (also known as asymmetric key encryption).

Types of symmetric-key algorithms
Symmetric-key encryption can use either stream ciphers or block ciphers.
·         Stream ciphers encrypt the digits (typically bytes) of a message one at a time.
·         Block ciphers take a number of bits and encrypt them as a single unit, padding the plaintext so that it is a multiple of the block size. Blocks of 64 bits were commonly used. The Advanced Encryption Standard (AES) algorithm approved by NIST in December 2001, and the GCM block cipher mode of operation use 128-bit blocks.

Implementations
Examples of popular symmetric algorithms include Twofish, Serpent, AES (Rijndael), Blowfish, CAST5, Kuznyechik, RC4, 3DES, Skipjack, Safer+/++ (Bluetooth), and IDEA.

Cryptographic primitives based on symmetric ciphers
Symmetric ciphers are commonly used to achieve other cryptographic primitives than just encryption.
Encrypting a message does not guarantee that this message is not changed while encrypted. Hence often a message authentication code is added to a cipher text to ensure that changes to the cipher text will be noted by the receiver. Message authentication codes can be constructed from symmetric ciphers (e.g. CBC-MAC).
However, symmetric ciphers cannot be used for non-repudiation purposes except by involving additional parties. See the ISO/IEC 13888-2 standard.
Another application is to build hash functions from block ciphers. See one-way compression function for descriptions of several such methods.




Construction of symmetric ciphers
Main article: Feistel cipher
Many modern block ciphers are based on a construction proposed by Horst Feistel. Feistel's construction makes it possible to build invertible functions from other functions that are themselves not invertible.

Key generation
When used with asymmetric ciphers for key transfer, pseudorandom key generators are nearly always used to generate the symmetric cipher session keys. However, lack of randomness in those generators or in their initialization vectors is disastrous and has led to cryptanalytic breaks in the past. Therefore, it is essential that an implementation uses a source of high entropy for its initialization.


Reciprocal cipher
A reciprocal cipher is a cipher where, just as one enters the plaintext into the cryptography system to get the cipher text, one could enter the cipher text into the same place in the system to get the plaintext. A reciprocal cipher is also sometimes referred as self-reciprocal cipher. Examples of reciprocal ciphers include:
·         Beaufort cipher
·         Enigma machine
·         ROT13
·         XOR cipher
·         Vatsyayana cipher


Sunday, 4 December 2016

Commercial Bank first to launch NFC-enabled premium credit cards for both Visa & Mastercard



The Commercial Bank of Ceylon has become the first bank in Sri Lanka to offer Near Field Communication (NFC) enabled credit cards of both Visa and Mastercard, two of the leading brands in the sphere.

Formally launched in Colombo on Wednesday, 23rd November, Commercial Bank’s Visa Infinite, World Mastercard and Visa Signature branded NFC credit cards are targeted at premium customers, the Bank said.

Near Field communication is a set of communication protocols that enable the chip mounted on the credit card to establish contactless communication with a portable device such as a smartphone or NFC enabled point-of-sale unit, by bringing the two within about 4 centimeters of each other.

NFC enabled credit cards are more secure than those with magnetic strips, and their contactless communication capability means that holders of NFC-enabled cards need not relinquish their cards to third parties when making a payment via a terminal or device with the same technology.

Speaking at the launch of NFC-enabled credit cards from Visa and Mastercard, Commercial Bank’s Managing Director/CEO Mr Jegan Durairatnam said: “Commercial Bank is proud to be the first bank in Sri Lanka to launch NFC enabled credit cards from both Visa and Mastercard brands. These cards are designed to offer the most premium facilities to customers who enjoy the finer things in life.” Mr Durairatnam also remarked that the Bank was particularly proud to bring two competing giants in the cards business on to the same platform at a launch event. 

The first two NFC-enabled credit cards issued by Commercial Bank were presented to Mr Indra Silva and Mrs Nisreen Jafferjee at the launch event.

Holders of Commercial Bank’s NFC-enabled credit cards will be eligible for numerous exclusive benefits local and internationally, including upgrades at premium hotels, access to premium airport lounges, premium travel experiences, offers at gourmet restaurants, special shopping offers and concierge services, the Bank said.

NFC technology evolved from radio-frequency identification or RFID, the technology used by shipping companies, in large warehouses, and in superstores to keep track of goods. It uses electromagnetic induction in order to transmit information over a short space so that by simply scanning a container, a staff member can know what it contains.

The NFC standard has three modes of operation: the peer-to-peer mode that lets two smartphones swap data, a read/write mode in which one active device picks up info from a passive one, and card emulation, in which an NFC device such as a smartphone can be used like a contactless credit card.

The only Sri Lankan bank to be ranked among the Top 1000 banks of the world for six years consecutively, Commercial Bank operates a network of 251 branches and 650 ATMs in Sri Lanka. The Bank has won multiple awards as Sri Lanka’s Best Bank, Best Trade Bank, Strongest Bank, Most Respected Bank from a number of local and international institutions and publications over several years and has also been adjudged one of Sri Lanka’s 10 best corporate citizens by the Ceylon Chamber of Commerce for several years.

Commercial Bank’s overseas operations encompass Bangladesh, where the Bank operates 18 outlets, Myanmar, where it has a Representative Office in Yangon, the Maldives, where the Bank opened a fully-fledged Tier I Bank in September 2016 and Italy, where the Bank launched its own money transfer service in November 2016.

Saturday, 3 December 2016

what your web browser is telling websites about you

Interested in knowing what information a website has access to about you as soon as you visit a page? Here are a couple of websites that will show you what information you are leaking as you browse the internet.



Your web browser holds a lot of information about you, and this information is available to websites who want it. Want a peek at the sort of information that a website has access to? Read on!

If you are interested in the sort of information that your browser can offer, there are two websites that you can visit.

The first site is called " Click."

Not only does this site show you the information that your browser is leaking about you and your computer, it also watches what you do. I won't spoil things for you, but I encourage you to turn up the volume (there is a little mild profanity so perhaps headphones is a good idea), and explore the page.

How many of the achievements can you unlock while on Click? Let me know!

The other site you can visit is Webkay.

This site is less playful than Click, but it presents the data that it gathers about you in a much clearer manner, going as far as explaining what is being collected, and also offering some advice to help you prevent some of the data leaks from happening in the first place.

If you're not used to maintaining your privacy while browsing the web, you might be surprised just how much information websites have access to. If you're already switched on in terms of privacy, bask in the glory of being able to tour around the web without leaving too many footprints.

Friday, 2 December 2016

PHP 7.1 has been released!



PHP 7.1 has been released!

New Features:

- Nullable types

- Void return type

- Iterable psuedo-type

- Class constant visiblity modifiers

- Square bracket syntax for list() and the ability to specify keys in list()

- Catching multiple exceptions types


Any more details

Featured Documents

Programming

View more

Tips and Tricks

View more

Mobile

View more

Tutorials

View more

General

View more

Getting Started

View more