Often it is required to convert a string to an integer but before conversion it is recommended to check if the string being converted is in integer format or not. This might be useful when converting a user input value into an integer since user entered value will always be a string. If the string is not integer then the conversion process will fail resulting in code break. This is because it is possible to convert “12” into 12 but trying to convert ‘twelve’ into a integer will result in an error. This post shall list down different methods by which we can check aRead More →

What is a nested method If a method is defined inside another method, the inner method is said to be nested inside the outer method or it is called Nested method. All languages do not support nesting a method inside another method but python allows you to do so. Benefit Suppose there are some lines of code inside a function(or method) which are repeating multiple times. Instead of repeating them, you can put them inside a separate method and call that method where those lines are required. This prevents repeating lines of code as they are encapsulated in a single method which is called whereRead More →

What is a class Concept of class can be better explained and understood by an example. Suppose an apartment of hundreds of flats need to be made. All the flats will be based on a design which is created by an architect. Now in future if more such flats need to constructed, then it can be easily done with the help of this design. This design can also be termed as a template or skeleton. Similar is the concept of a class. A class in an Object Oriented Programming language is a template, skeleton, blue print or design based on which objects are created. ARead More →

What is multiple inheritance When a child class extends more than one class or it has more than one parent class, then the type of inheritance is called multiple inheritance. Many programming languages do not support this type of inheritance but python supports it. Following illustration will clarify the concept of multiple inheritance. where a class can have more than one parent classes. Before moving on with this post, it is recommended to understand the concept of inheritance in python, if you are not already familiar with it. Python multiple inheritance syntax In order for a class to extend more than one classes, all its parentRead More →

What is inheritance Inheritance is one of the prominent features of Object Oriented Programming(OOPs). In fact, a language which does not support inheritance should not be called an Object Oriented Programming language. Inheritance involves more than one class where a class is a Parent and other classes are its children. This parent-child relationship can be at a single level where there is only one parent class and single or multiple child classes at the same level or at multiple levels where a parent class has child classes which also have their own children, these grand children may have their children and so on or aRead More →

What is operator overloading? Overloading an operator means adding it some behavior for your own customized requirements apart from its default operation. Example, + operator is used for adding two numbers, merging lists or concatenating strings but what if you want to add two objects of a class using +.  Consider the below class for understanding the concept better. class Course: def __init__(self, name, hours): self.name=name self.hours=hours Above code defines a class Course which has two fields name and hours. Now what if we create its objects and try to add them as shown. courseOne = Course(“python basics”, 10) courseTwo = Course(“python advanced”, 20) print(“TotalRead More →

Scenario Many times you want to perform some task repeatedly after a definite time interval or call a particular function after every fixed time elapse. Example, checking for the status of completion of a process and showing the result when the process completes or displaying some message on the browser after every few seconds etc. Javascript way In javascript a task can be repeated using setTimeout method. This method takes 2 arguments, first one is the task which needs to be done. This task is provided in the form of a function. Second argument is the time after which the task will be repeated. TimeRead More →

Determining the number of words in a file is an important aspect of programming. It is required while solving programming problems and it is also utilized in real world applications. This post shall detail out different methods to count the number of words in a file. All of the methods involve the logic to read a file, thus you should know how to read a text file in java. This post will definitely help you out on that. Method 1: Using BufferedReader Read a file line by line using java.io.BuffereredReader. Break this line into words by splitting over it using split method of java.lang.String. ThisRead More →

What is sorting? Sorting means to arrange elements of a collection in an order which can be either ascending or descending. Collection can be an array, a list, keys or values of a map etc. Usually when sorting techniques are discussed, the collection is sorted in ascending order of its elements and the collection picked up is an array. There are many approaches available to sort an array. This post will focus on Bubble sort. What is Bubble sort? It is a sorting algorithm in which each array element is compared with the element next to it. If the element being compared is greater thanRead More →