Showing posts with label Java Tutorial. Show all posts
Showing posts with label Java Tutorial. Show all posts

Saturday, June 08, 2013

Guaranteed asked Java Interview Questions

Leave a Comment Follow us on twitter

Java Interview Questions


These are guaranteed Java Interview Questions that are mostly asked by the interviewer when the focus of the topic is java. In the today’s world when java is in demand and the competition is tough, one should prepare for the java interview questions before going for an interview. So, let’s see the java interview questions.
1. Why multiple inheritance is not possible in java?

>> Multiple inheritance is not permitted in java because it will result into ambiguities and inconsistencies.

2. What is the difference between abstract class and abstract method?

>> Abstract class is a class that is declared abstract while, abstract method is a method without any implementation code.

3. What is the difference between runtime error and exception?

>> Each exception is a run time error, but all the runtime errors are not exceptions.

4. What is Method Overloading?

>> Method Overloading means having more than one method with same name but different number of arguments.
Eg.
class Sample
{
void method1()
{
System.out.println("This is method 1");
}
void method 2(int a)
{
System.out.println("This is method "+a);
}
}
class Main
{
public static void main(String args[])
{
Sample object=new Sample();
object.method1();
object.method2(2);
}
}

5. What is Dynamic Method Dispatch?

>> First of all Dynamic method dispatch is the best example of run time polymorphism. Dynamic method dispatch is used to solve the problem of call of overridden method at run time rather than at compile time.

6. Runnable interface comes under which package of java?

>> It comes under java.lang package which is the most basic package used in java.

7. What does JDBC stands for and why do we use it?

>> JDBC stands for Java Database Connectivity and it is used for making the connectivity between java programming language and database.

8. Why we don't use delete operator for memory deallocation?

>> Generally as in C++ we use delete operator to free dynamically allocated memory. Java takes a different approach, it deallocates memory automatically. This technique is also called as Garbage collection.

9. Why we use static in java?

>> Classes are called with the use of their objects. Static is used so that class can be called without using an object of that class.

10. What is Interface?

>> An interface is the collection of methods which does not have any implementation code or we can say that interface is the collection of abstract methods.

Hope that you will these find java questions in your interviews.
READ MORE...

Thursday, June 06, 2013

Basics of Java Programming: How to write a simple Java Program

Leave a Comment Follow us on twitter
To do java programming and to become a better programmer, one should able to write the java code with less complexity and lower running time. In this java tutorial instead of focusing over Complexity and Running time of a program, we are going to learn how to write a simple java program.

class Javaprogram
{
public static void main(String args[])
{
System.out.println("This is your first java program");
System.out.print("Here you are going to learn java");
}
}

Above written eight lines of code is the simple java program one can write, but for the beginners it is very difficult to understand such creepy code. Let's understand the code. As Java is an Object Oriented Programming language so there is the use of classes, procedures, methods etc. Same applies here; in java program we start with class <Classname>. After that in the next line we use public static void main(String args[]).  Now the question arises what does that mean?

Why we use public static void main(String args[]) in java program


The answer is that public is used to make the code accessible by any object of any class from anywhere. The class is called by the object of that class, static is used to specify that it can be called without having any object, void is return type which means that nothing is returning as void means nothing/null, main is the main() function of the program. It is compulsory to use main() so that it should always called first by default. The use of String args[] is to take the command line arguments from user. The use of args[] is to specify the number of arguments to be stored in array and the return type of that array is String.

Then we use the System.out.println and System.out.print, here out means output which is belongs to System class; and println() and print() are the methods of that System class. The difference between println and print is that println show the output in next line while print shows the output in the same line.

I hope that now you will understand the above written java code and able to write java program of your own.

READ MORE...

Saturday, June 01, 2013

Java Tutorial : Operator and Expressions in Java

Leave a Comment Follow us on twitter
In this java tutorial we are going to see how Operators and Expressions are used in java programming. In the computer programming, Operator and Expressions play a vital role and are almost same for all the programming languages. Let's discuss the Operators first. So, basically java operators are grouped into four categories and they are : 

-Arithmetic Operator
-Bitwise Operator
-Relational Operator
-Logical Operator

Without these operators, a coder cannot do the mathematical computation. Let's see each one of them individually.

* Arithmetic Operator : +, -, *, /, %, ++, +=, --, -=, *=, /=, %= are arithmetic operators used in java programming.

Eg.:
class Sample
{
public static void main(String args[])
{
int a=2,b;
b=a*2;
System.out.println("Value of b after using Arithmetic operator is :"+b);
}
}

* Bitwise Operator : ~, &, |, ^, >>, >>>, <<, &=, |=, ^=, >>=, >>>=, <<= are the bitwise operators currently using in Java Programming.

Eg.:
Suppose we have a binary value
01000001  :  65
Apply <<2 (i.e. Left Shift)
00000100  :  4

* Relational Operator : ==, !=, >, <, >=, <= are the relational operators. These are used to determine the relations between the operands.

Eg.:
int a=5, b=1;
boolean d=a>b;
If the result of a>b which is True is stored in variable d.

* Logical Operator : &, |, ^, ||, &&, !, &=, |=, ^=, ==, !=, ?: are the logical operators (boolean logical operators). In this we generally use assignment and ? operator.

-Boolean means the value will be either true or false.

Eg.:
int a,b;
if(a>b)?a=1:b=1;

In this example if the value of a is greater than b then, value assigned to a equals to 1. In the else case b=1.


Now let's see Expressions in Java Programming. Expression in Java Programming is same as the expression in Computer Programming. Expression is the combination of operands and operators. Every computer programming languages have its own rules for Expression, but they are all like to be similar.

Eg.:
-a+5 is an expression.
-a+b+c is an expression.
-a+b+5 is an expression.

I hope that these java tutorial will help you to learn java. Java have a wider scope in Computer Programming and quite general in use in today's world.
READ MORE...

Friday, May 31, 2013

What is Object Oriented Programming (OOP) : An Introduction

Leave a Comment Follow us on twitter
Many of us has heard the word OOP i.e. Object Oriented Programming, but not aware with the concepts of Object Oriented Programming. Today many coders still don't know what basically is Object Oriented Programming? Let's understand the Object Oriented Programing.

It is not a programming language as some people still thinks. Object Oriented Programming is a Programming Language Model which focuses on Objects. Objects are the instance of a Class or Object is a run-time entity. It focuses on data rather than procedures. The basic feature that Object Oriented Programming provides is Classes. Here are some of the important features of Object Oriented Programming :

* Inheritance : In this the object of one class can acquire the properties of object of another class. E.g. Data member of one class can use the value of data member of another class (which we call Inheritance).

* Polymorphism : Polymorphism means ability to take more than one form.

* Data abstraction and Encapsulation : Data Abstraction means to highlight the essential feature without including background details whereas, Data Encapsulation means merging of the data and functions into single component.

* OOP allows the use of classes and method in the program. It also enlights the feature of reuability. Reusability is an important feature from the Object Oriented Programming (OOP) point of view.

Object Oriented Programming (OOP) languages are C++, Java, Python, .NET, Visual Basic etc. These languages have a wider scope in the field of Computer Science and Information Technology. Having command over one of any listed language will lead to have a better career in the chosen field. Hope that you are now able to understand the concepts and features of OOP's.

The two basic programming languages C++ and Java are Object Oriented and they are so popular that they are used to make a varieties of OS, Webpages, Software Applications etc. In the further tutorial we will focuses over these two programming language, try to understand their concepts, features, needs and surely we will do the coding part also.
READ MORE...