Posts

Visual studio code:Is it worth your time?

I am not a fan of Microsoft but these days I became a fan of IDE called  “Visual studio code ”.Before jumping into the discussions I want to talk about the other IDE’s. Netbeans .Netbeans is great,but it serve a special purpose,i.e,creating Java based applications,you get JS,Go,python support but it is limited to certain extent.Then comes the next candidate. Eclipse .I was using eclipse when started doing android developement.At that time there was no android studio.I was the only choice left for me.Eclipse is really fast and smooth.It also has git support like Netbeans.But similiar to netbeans it can’t detect new programming languages and hence we can’t get autocomplete feature.For Java and C++,it’s great Sublime text : Not an IDE but text editor still counts.Sublime text gives tough competition to VS code but as it is just a text editor there are basic features missing such as in build terminal,debugging,git support,split screen view.Which is why I left it also. Webstorm :...

Lists in java

Lists in java: What is a list? A list is collection of data.For a real time example consider a list of groceries for a month.You can add,remove,clear,get items from a list.List is actually an interface. There are several lists collections available in java: Array list:Most important and useful type of list LinkedList:Similiar to arraylist with limited functionality Vector:Similiar to arraylist but it is synchronised class. Stack:LIFO(Last in first out) collection Common methods in a list: add(Object e),add(int index,Object e):adds an element(duh :<).For adding element at specific position pass parameter index. remove(int index):remove an element at position clear():clears out the list.Make list empty.

Four building blocks of Object oriented programming language

Four building blocks of Object oriented programming language Java is an object oriented programming language just like C++,small talk and python. An OOP language follows four basic rules: *Inheritance *Encapsulation *Polymorphism *Abstraction *Inheritance: The ability of a language to reuse previously written code and add further functionalities to the previously written code. How we use it in Java: BY EXTENDING CLASSES. Each child class inherits the functions and member variables from the parent class without even writing the whole code. *Encapsulation:  The ability of a language to  hide the important and private data and encapsulate into an single unit called "CLASS". How we use it in Java: By creating classes the data wrapped inside it and can only be accessed using the object(unless it is static data). *Polymorphism:  The ability of a language to  create a method with same name but multiple arguments each method do different work on different ...

Threads in java

Image
Threads in java What are threads :For understanding threads we must firstly know,what is a process? A process is a background activity running besides doing some works at a piece of time.A machine operating system runs a lot of processes to do a task such as opening a program,booting up,loading resources etc.So next question is what is a thread? A thread is a light weight process,i.e. threads do small piece of work in a particular duration.It has a start start,running state,waiting and terminated state.There is a default thread running in a java program,if you have noticed:its the main thread. Why do we need threads? Suppose in a situation where we are creating a project where a program does two or more piece of work at the same time,for example processing a mouse click on a button and opening the other frame of project at the same time.HOW CAN WE DO THAT??The power comes with multithreading. How threads works? The threads are started using start() method,that gives call ...

Basics of JDBC connectivity

JDBC connectivity: Or simplified as Java database connectivity.What is the fun when the program does not have a database to store to.So,here comes sql(a console based language specially for the data storage) to the rescue. Why is JDBC connectivity needed: Suppose you are working on large project called Library management and there are huge data to be stored and retrieved during the program execution.Such large data cannot be managed by simple file based databases.So,there is a need for a proper tool for this purpose.JDBC serves for this purpose.   How to do JDBC connectivity: First you will need jar file for JDBC driver. Link: JDBC driver for Mysql . If you are working on the eclipse,the right click on the project->project properties->java build path->(Bottom Left)add button->Path of the .jar file. Or you can create lib folder in your project and paste the jar file into it.That shoul work. JDBC connectivity is done in for steps: Loading the class with class...

Method overloading,overriding and need of it,Concept of object

Image
Method overloading : Let me get this straight,method overloading simply means same method with different parameters either of different data-type or different parameter size.Return type must be same. Here's the example: Valid overloading of methods: void foo():nothing in the parameters list void foo(int num):one  parameter of type int void foo(int a,int b):two parameters of type int void foo(float a,float b): two parameters of type float void foo(int num,float tot): two parameters of type float and int In-Valid overloading of methods: If the parameters of the at-least one method is exactly the same invalid overloading. Need of overloading methods?? Method overloading is needed because there are situations where a single method have to do several kind of work.Suppose there is a method name calc_area that calculates area of different figures such as: Circle:single parameters with float value  calc_area(float r). Triangle:Two parameters(base and ht,) with flo...

Exceptions and exceptional handling

Exceptions: What are exceptions you may ask,exceptions are flaws in the programs that are to be taken care of.They disturb the normal flow of the program and creates serious problems if not handled properly.They can be run-time or compile time or you may say unchecked or checked exceptions.But what are errors then,exceptions that cannot be recovered  are called errors.For example:Programmer has declared an array of objects of string class of size n,but has inserted greater than n value,its an array-index-out-of-bound exception,or if called the method of a class that neither exist on the package.There are lots of predefined exceptions in java including them.  There are basically two types of exceptions as I said,checked and unchecked exceptions. Checked exceptions are notified while compiling the program,i.e. the compiler checks that it would cause further problem,that's why they are called checked exceptions.Examples are:IOExeption,sqlException. Unchecked...

Inheritance,its requirement,use and implementation

Image
Inheritance Inheritance example:a tree Inheritance is the most interesting feature of java and other Object oriented programming language.It is the only reason why i hate "C". Firstly,lets know what inheritance is??As the word suggest means taking the features....but of what??A class or an interface.But what are the features???The variables and the method the class or interface contains. Inheritance takes the principle of re usability.Using the previously written code for a class without rewriting it again. Just extend the class,that's it.The class which is taking the feature of another class is called child class and the class from which features are taken is called parent or base class. It per the rules of humanity that child cannot be born parents,thus child class constructor is executed after the parent class constructor by default(discussed later). Remember single class can extend single class through inheritance. Requirement No one likes to rewrit...

Abstract class,Interfaces and its implementations

Image
Abstract class We need abstract class for the sense of simplicity.Learn it this way,suppose there is a college administration with over 100 of persons working in different sections namely,Head of department,teachers of diff. subjects,accounts department staff,mess staff,cleaners etc. Each have their own role in the college.But,here's the situation,what if the different department(classes) want the similar thing,for example,retrieving student info or getting the salary.We have to make method with similar motive,for each and every class we make,WHAT A WASTE!!! Abstract class comes to the rescue.  Abstract class is nothing but a normal class with some restrictions. Well,these restrictions are: At least one of the method/s must be abstract. You cannot make an object of an abstract class,i.e.,no new keyword before the class name.But the sub-classes of an abstract class is allowed. An abstract method MUST NOT HAVE A BODY.For example:void...

The mystery keyword static,final

The keyword static Most of the new java developers are often confused or find difficulty to understand what  keyword static really is. Java API is full of static methods and variables. I will explain it clearly, There are three main reasons why "static" is used: To does not bother about creating an object and accessing methods or data,directly calling the variable or method. To  make the instance variables belonging to whole class rather than binding to a particular object,i.e,if a Class A has static variable a,and A has two instance a1 and a2 with instance variable value then the values are same. To allow sharing of data to all the objects accessing static variable. For c ount the number of objects cr eated in the p rogram as static variables are share d among objects. Where static keyword are used: For making methods static For making class variables static also called static variables For making nested class static. 1.Making methods static:Type stati...