Java All Long - Short Questions Solved Interview level....
This Long short Questions are important in Final Exam. So I solve in easy Language .
In this some questions are always ask's in Many Corporate Companies and IT industries.
In this some questions are always ask's in Many Corporate Companies and IT industries.
Justok! by Amit..... |
Java vs C++
So the main Difference is java Programming is pure based on OOPS whereas C++ is based on Function oriented and also supports OOPS.But java is fast and secure and also Platform Independent and c++ needs to compiler based software for Program execution.
Serial No. | Java | C++ |
---|---|---|
1. | Java is platform Independent. | C++ is platform dependent. |
2. | Java uses Compiler and Interpreter both. | C++ uses only Compiler. |
3. | Java doesn't Supports Operator Overloading. | C++ Supports Operator Overloading. |
4. | Java doesn't Supports multiple Inheritance. | C++ Supports multiple Inheritance. |
5. | Java does not Supports Structure. | C++ Supports Structure heterogeneous Data Type. |
6. | Java has no any header files.it uses import keyword to include Classes. | C++ Supports header files and it's also Supports STDL standard Template Header Files. |
Two Dimensional Array in Java with an Example....
The 2-D Array is nothing in Java but it is similar to Linear Array or 1-D array.So it is Array of Arrays.In java we use 2-D array for Data storage in the format of Rows and Columns and we can easily Access the record using both the Row and Column Index .It is also Called Multi-Dimensional Array.
Declaration of 2-D array in java....
In C language we simply declare 2-D array by For Example :
int array[4][5];
int is the data type and array is the name of 2-D array and 4 is the size of Row and 5 is the Size of Column.
But in java we use new Keyword to declare 2-D array.
For Example :
int [][] Employees = new int[4][5];
Things to be remember..
1.) Here we use Integer data type for declaration of 2-D Array.it means this array's only accepts Integer Values.Support if we use Float values in this array then it's throws IOMismatch Exception.
2.) Employees is the name of 2-D Array.
Initialization of 2-D array at compile time
Let's take a same Example.
int [][] Employees = {{10,20,30},{11,12,13},{34,45,78},{23.46.89}};
Here we not mention any size of rows and columns but Java Compiler is Intelligent.Compiler Automatic Calculates the Both Sizes.
So it's Enough for Java Array .....
Declaration of Variables in Java
So Basically , A variable is a container which holds the value while the Java Program is executed.A variable is declare with a Data type.Variable is the name of memory Location.In C Language we already discuss Variable is the Quantity which can change in the Program Execution.
There are 3 types of Variables in Java with Declaration.
1.) Local Variable....Those Variables which are declare inside the body of the method and Loops called Local Variable.
For Example :
for(int i=0;i<=10;i++)
{
int a=5;
a++;
}
Here int a=5; is the Local Variable.
2.) Instance Variable......Those Variables which are declare outside of the body of the method called Global or Instance Variable.
For Example :
int i=1;
while(i<5)
{
i--;
}
Here int i is the Instance Variable.We can also make sum of two numbers in Java using Instance Variable.
3.) Static Variable......Those Variables which are declare with static keyword is called Static variable.It can't be Local.Static means memory allocation happens only once when the class is loaded in the Memory.
For Example :
public static int a = 5;
it is static variable and it's memory location never changed once Class is Loaded in the Memory.
Why Java is both Interpreter and Compiler Language
If we run code on Windows Command Prompt then we need Java compiler included in JDK So that's why Java Sometimes called Compiled Language and when we run Java code on JVM in OS Linux then it's called Interpreter Language.But in the Both Compiler is much Faster then Interpreter.
Compiler: The Java compiler (javac) compiles Java code into bytecode. Bytecode is what the interpreter reads. The bytecode is platform-independent. This means it isn’t targeted at any particular operating system; it targets the interpreter.
Interpreter: Java’s interpreter is more correctly called the Java Virtual Machine (JVM). It reads the bytecode and translates it into something the hosting operating system can understand and execute. For example, “make a window” is done different ways on different operating systems (Windows, Linux, etc.).
Constructor In Java Programming
Constructor is a block of code that initializes the newly created object.A constructor resembles an instance method in java but it's not a method as it doesn't have a return type.In short constructor and method are different.People often refer constructor as special type of method in Java.
Constructor has same name as the class and looks like in a Java code.
Serial No. | Java Features |
---|---|
1. | Java is platform Independent. |
2. | Java is simple and easy to learn. |
3. | Java is user Familiar. |
4. | Java Supports Pure OOPS concepts. |
5. | Java also Supports Functional Programming. |
6. | Java is strong Security Model called Robust Security Model. |
7. | Java is Fast and Secure. |
8. | Java is High Performance Language. |
9. | Java also have a features Multi-threaded Concepts. |
10. | Java is a widely used in Android Applications. |
Purpose of Exception Handling........
The main Purpose is to prevent abnormal termination of the program and to customize the exception message.Exception is a type of run time Error . Exception handling is a mechanism by which we handle the exceptions as per our need at run time.we use try-catch blocks for executions as per our need at run time.
An Exception is any event that disrupts the normal flow of a program’s execution as it executes instructions. Like its name, it refers to exceptional conditions that could happen during execution. Because these conditions are exceptional, you have to handle them in order to continue with normal program flow.
There are two types of Exception.....
1.) Checked Exception
2.) Un-Checked Exception
1.) Checked Exception is Compile time exception which can fixed by Programmer and visible to Programmer.
For Example..... SQL Exception .
2.) Un-Checked Exception is Run time exception which can handle by Programmer using try-catch block or also throws Keyword and not visible to Programmer.
For Example..... Arithmetic Exception .
#StayHome
Solve By Amit
Technical Content Writer And Owner Of JustOk! Website
0 Comments
Write your comments or feedback here.........