Learn C language

Easy to learn C language tutorials

Learn C++ language

Easy to learn C++ language tutorials

Learn Core Java language

Easy to learn Java language tutorials

Learn HTML

Easy to learn HTML tutorials

Learn CSS

Easy to learn CSS tutorials

Learn ASP.NET

Easy to learn ASP.NET tutorials

Showing posts with label Tutorials for java. Show all posts
Showing posts with label Tutorials for java. Show all posts

Tuesday, August 6, 2013

[PART-6] JAVA : Looping

From now onwards use DrJava to write your programs, compile and run it.
It is very handy and easy to use.
Download it from here :
http://www.drjava.org/
You will find compile and run buttons in drjava. Hence it is easy to use.

There may be situations where we have to execute a piece of code several times. For this looping is used. There are 3 kinds of loops in java :


  1. for loop
  2. while loop
  3. do while loop

1.)for loop
i=0;
Here we have assigned the value of integer i variable to 0.
So it will start from 0.

i<=5; (i is less than or equal to 5)
i will start from number 0 and will stop when its value becomes 5.
if it was i<5; (i is less than 5) then it will stop when its value becomes 4

i++ (will increase the value of i with 1, note that 1st time it will not increase the value of i)


2.)while loop
  I have assigned value of i to 1.
now while loop will execute the piece of code until the condition is true. Here the condition is if i is less than or equal to 5 it will print the value of i.
i++ willl increment or increase the value of i by 1 each time the loop is executed.

3.)do while loop
I have done the same thing here.
Initially do while loop will execute whatever is between the { } without checking for any condition.
Then it will check for conidtion i.e. while(i<=5)
Whereas in case of while loop it will initially check the condition and then go ahead only if the condition is true.

See the video for better understanding...




Monday, August 5, 2013

[PART-5] JAVA : Inheritance explained with programs

Read my previous tutorial if you have not read yet.

In my previous tutorial you learned about types of inheritance.
In this tutorial we will develop programs of :
1.) Single inheritance
2.)Multilevel inheritance
3.)Hierarchical inheritance
4.)Multiple inheritance

Let's Start:
 Below are the programs of inheritance. You have to compile and run each program.

1.)Single inheritance :

  • In this program i have declared a class a. In class a, i have declared a int type variable "p" and two functions aget() to get the value of "p" from the user and ashow() to print the value of "p" given by the user. Similarly we have declared another class "b" which contains variable "q" and functions bget() and bshow(). I have use extends keyword to inherit the features of "class a "into "class b". Then i declared the main() method and created object of "class b" as "obj", With the help of this object i can access the data members and member functions of "class a".  as well as "class b". I can access the data members and member functions of "class a" because i have inherited the features of "class a" into "class b".


2.)Multilevel inheritance

  • In this program i have declared three classes "a", "b", and "c". I have declared the data members and member functions same as above in these three classes. But here i have used extends keyword in classes "b" and "c "respectively. Now if i create a object in class 'c" then with the help of this object i can access the data members and member functions of classes a and b respectively.

3.)Hierarchical inheritance

  • In this program i have declared three classes "a", "b" and "c". I have declared data members and member functions of classes "a", "b" and "c" same as i have done above. Now if i create an object of class "b" and class "c" then with that object i can access data members and member functions class "a". I don't need to create object of class "a" to access data members and member functions of class "a".

4.)Multilevel Inheritance
This type of inheritance is not supported in Java to avoid complexity.



Sunday, July 28, 2013

[PART-2] how to compile and run java programs


Read my previous tutorial if java is not installed on your operating system.

In this Tutorial you will learn how to :

  • Configure environment variables so that we can use javac(to compile) and java(to run) commands.
  • write a java program
  • compile a java program
  • run a java program

Pre-requisites :
  • Basic Command Prompt knowledge
  • Basic knowledge of Windows Operating System.
Program used in this video : 







If you have any doubts please mention it in comments...

[PART-1] A Quick Start with java !



  • If you know c or c++ then java is easy to learn.
  • In C language you use scanf and printf function for input and output.
  • In C++ language you use cin>> and cout<< function for input and output.
  • Similarly in Java you need to learn some functions for input and output. Rest Java is same as c or c++ .
  • In C or C++ you include header files, Similarly in java packages are used instead of header files.

The first step is to learn how to install java in your operating system. My OS is Windows 7 x64. Follow the video tutorial if you don't know how to install java.

We will learn how to compile and run java programs in next video tutorial. 

Download latest version of java from here :
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html