When shall you use Multiple Inheritance?
Multiple inheritance is used when a new class to be formed has to inherit characteristics from two or more classes. eg: class scientist class labourer | | | | V V -------------------------------- | class employee | -------------------------------- Multilevel inheritance is used if a derived class inherits characteristics from a base class which is a derived class (intermmediate base class). If the inheritance level is more than two then it is a multilevel inheritance. eg: class Grandfather | | V class Father | | V class son
Why does not use pointer in java?
You do not use pointers in Java because the language designers decided to abstract memory management to a higher level in Java than in C. The reason for this is that it is easy to make mistakes using pointers and other lower level memory management techniques. These mistakes can lead to bugs. hard to read code, memory leaks that waste system resources, and security issues. Instead for the most part Java takes care of memory management for the user who can instead specify behavior though the object oriented techniques that are safer and easier to understand. The downside is that the programmers lose some control and flexibility in using memory. Also, programs using Java take a small performance hit in some cases because of the extra work Java has to do to manage memory itself.
They are, however in Java they are called references.
If you want your project to run in windows only,then surely go for .net,.net is especially made for windows,since it provides a very good UI,also it is very easy for referencing external assemblies very efficiently for your project,which java programmers find it very difficult,there is the support of pointers in .net thru which you do a lot of things,and finally there are lot of languages to choose in .net
But if ur project needs to run in Linux as well,then surely go for java,bcoz java is far better than c++,also java is more secure than .net
It depends on your needs to decide weather to go for .net or java,but surely there is no point in finding advantage of platform independence of java with .net.Dotnet was built for windows only.
Both the technoligies have their own advantages.
.Net
1) If the application is Windows platform specific then use .Net
2) .Net is Language independent, so if the team has multiple skill expertise C#, VB.NET , C++ , developers can still work on the same project with different skill set.
3) MS technologies provides RAD (rapid application development) to deviler project faster, customers always prefer faster delivery.
4) Debugging is very effort-less therefore, can fix the bugs quicker.
5) deployment is very easy and simple
6) Ajax implementation is simple & easy
.Java on the other hand
1) Platform independent
2) Open source
3) Dependant on the 3rd party tools to develop applications
Distinguish between the Classes and Objects?
A Class is a template from which Objects are created, in much the same way as a plan of a building is a template from which a building is created... just as the building plan is a piece of paper and not a building, so a Class is not an Object.
The code for a Class describes the way in which an Object should behave when particular methods are invoked.
Swing is a package in Java which contains tools for building GUI application. Swing is a part of Java's foundation classes.
How much space does Java take to download?
On a Windows platform the online Java Runtime Environment (JRE) installer is approximately 0.86 MB and the installed size on disk is about 98MB.
The downloadable full Windows offline JRE installer is larger ~30.2 MB and for MacOS ~50 MB.
Why do abstract class can not be inherited?
An abstract class is designed to provide function and organization to subclasses without ever existing as an object itself. In other words, it is a glorified template, an abstraction for subclasses, and would be illogical to instantiate.
As an example, imagine that a zoo wanted to make separate classes representing each of its animals, but wanted them to all have some common features like a variable for life expectancy or a method to project feeding costs. To force every class to implement this functionality, the programmer may create an abstract class called Animal that each subclass would extend. However, would it ever make sense to create an Animal? No, because an Animal does not exist anywhere in the zoo - an Alligator however might.
Why you don't use void in constructor function although it doesn't return any value?
Return a value in the constructor is senseless, because a constructor is used to initialize a object instance and not to perform a task or a operation. When we call a constructor we used a sentence like this:
MyClass var = new MyClass();
Then when we execute the above line the constructor return ('create') a new object of the type 'MyClass'. If this call could return an other type, for example an Integer, the constructor is considered a normal method, and if there are not more constructors a empty default constructor for MyClass is defined by the java compiler.
public class MyClass{
// The java compiler will insert a real constructor here
public Integer MyClass(){ //This isn't a constructor, only a simple method
return new Integer(1);
}
}
What is the constructors in class?
A class is simply the definition of a data type. A constructor is a special method of a class that is automatically invoked whenever an object of that type is instantiated, and is used to initialise the object's data members.
What is a argument constructor?
The value what we pass in the constructor is know as argument.you can look into the example given below to make it more clear.
class Test
{
Test(int a,int b)
{
int c=a+b;
System,out.println("the value of "+c);
}
}
public class testMain{
Public static void main(String args[])
{
Test t=new Test(10,20);
//here 10 and 20 are the arguments and a,b are parameters....
}
}
i hope this will help u
Kumar Ashish
What is the difference between static and non static class members in java?
Static data members are different from automatic ones in the way that their lifetime is equals to the lifetime of your program. Even if you have declared static members inside of function (class) other than main();
What is the advantages of high level languages to low level languages?
High Level Language:
High level language are easier to use and less technical skills are required to do a program. It is very useful where textual data is given priority. Troubleshooting doesn't takes a longer time. We get to know the errors very easily.
Low Level Language:
Low level language are not easily read at a glance and very high technical skill are required to do a program. Troubleshooting takes a longer time. They can produce stunning graphics.
Java is a program that is used for many things, As in picture wise. Java is a photo uploader. You can download the program. Or you can use Java when you upload Photos on Myspace.com
Another Answer:
Java is powerful and portable. it is a programming language. It's used on Web pages, in cell phones and on mainframes all around the world. A program written in Java on a computer/PC can easily find its way into many different computing platformsmaking Java a popular language for application development.
What is the difference between Statement and PreparedStatement?
* Prepared Statement is Pre-compiled class , but Statement is not. * So in PreparedStatement the execution will be faster. Actually when u submit a simple statement to the databse, at first the DBMS parses it and sends it back with the result, so again when u send the same statement again the DBMS server parses it and sends back the result so here a lot of time is wasted and because the statement is again parsed though it has been sent twice or thrice it consumes a lot of time and response will be slow.Prepared Statement is used when u want to execute a statement object many times. when u submit a PreparedStatement the DBMS server parses it and creates a execution plan. This e-plan can be used when u again send the same statement to the database.That is the DBMS server zest executes the compiled statement rather that executing it from first, hence we get an precompiled statement.And also the advanatge of using this PreparedStatement is it is used to send dynamic sql statements, which u can give values later than giving the values at the time of creation.
Difference between abstract and final class?
How can you convert an infix notation to postfix notation?
#include <iostream>
#include <stack>
using namespace std;
int prec (char ch){
// Gives precedence to different operators
switch (ch) {
case '^':
return 5;
case '/':
return 4;
case '*':
return 4;
case '+':
return 2;
case '-':
return 1;
default :
return 0;
}
}
bool isOperand(char ch){
// Finds out is a character is an operand or not
if ((ch>='0' && ch<='9') (ch>='a' && ch<='z'))
return true;
else
return false;
}
string postFix (string infix){
string pfix = "";
stack<char> opstack;
for (int i=0; i<infix.length(); i++){
// Scan character by character
if (isOperand(infix[i]))
{
pfix += infix[i];
}
else if (infix[i] ')')
{
// Retrace to last ( closure
while (opstack.top() != '(')
{
pfix += opstack.top();
opstack.pop();
}
// Remove the '(' found by while loop
opstack.pop();
}
In languages like Java and C,programs are organized into function. The main function is called by the startep code, and it, in turn calls other functions. The information passed explicitly to a function are the parameters.
Most modern languages use "data hiding" to increase reliability. A function can only change a parameter if it has access to the address of the parameter. That is, if you create a function addone and pass the parameter glop to the function, the function gets a copy og glop, changes the value of that copy, and when the function complete, the original glop trmains unchanged,
It rakes CPU cycles to do data hiding, and so not every language does it. Fortran has remained popular with scientists and engineers for 60 years because it can be lightning fast since, among other things, it doesn't do
data hiding. It still uses parameters, though, in statemebts like WRITE (3, 1H1) which says to print on device 3 the single character "1". (On an IBM 1130 running FORTRAN IV, that set a form feed command to the line printer).
How do you display a string on the console with java?
For example:
System.out.println("Hello.");
For example:
System.out.println("Hello.");
For example:
System.out.println("Hello.");
For example:
System.out.println("Hello.");
How do you repair an unhandled exception?
You can stop an unhandled exception by handling it. When your program crashes it will tell you exactly where it crashed and what exception it ran into. Dealing with the exception is the hard part. Generally, you want to take one of two approaches. The first is to make sure that the exception cannot happen. You may, for example, have to validate data to make sure that your users aren't allowed to give input which would result in a division-by-zero exception. The second is to allow the exception to be thrown, but use a try-catch block to catch it and print out a useful message instead of crashing. The method you choose will depend on what your program is supposed to do, who is using it, what exceptions are being thrown, where they're being thrown, etc. There's no silver bullet solution for handling an exception.
What is the difference between static and nonstatic member with example in java?
It depends on whether the member is a static variable or a static method of the class.
A non-static member variable is an instance variable. That is, each instance of the class has its own independent set of instance variables.
A static member variable is not associated with any one instance of the class, and exists even when there are no instances of the class. As with all static variables, it exists for the entire duration of the program.
A non-static member method is an instance method, thus the method automatically inherits a this pointer.
A static member method does not inherit a this pointer, but it does have private access to to the class. Thus specific instances can be passed to a static method if necessary.
Static members can be thought of as being common to all instances of a class, rather than a specific instance, even though no instances are actually required in order to make use of them.
Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer?
public class Add { public staticvoid main(String[] args) { int value=12; intcount=0; int sum=0; while(count<=4) { sum+=value%10; value=value/10; count++; } System.out.print("The sum of the individual integers is= "+ sum); } }
Write the program that display the factorial of a number?
/* gcc -ansi -Wall -Wextra -pedantic -s -static 0.c -o 0 */
#include <stdio.h>
int main ( )
{
int n , factorial = 1 ;
printf ( "enter the value of n\n") ;
scanf ( "%i" , & n ) ;
while ( n != 0 )
{
factorial *= n ;
n -- ;
}
printf ( "The factorial of n is\n%i\n" , factorial ) ;
return 0;
}
Write a program to detect duplicate elements in array?
The simplest way of doing this is not very efficient, but provides a quick development time. You want to take all of the elements of the array, add them to a Set, then retrieve them as an array again. Note that this will probably not preserve the order of elements in the array.
{
Object[] originalArray; // let's pretend this contains the data that
// you want to delete duplicates from
Set newSet = new HashSet();
for (Object o : originalArray) {
newSet.add(o);
}
// originalArray is now equal to the array without duplicates
originalArray = newSet.toArray();
}
Now the efficient, and more correct, solution.
This one will create a new array of the correct size without duplicates.
{
Object[] originalArray; // again, pretend this contains our original data
// new temporary array to hold non-duplicate data
Object[] newArray = new Object[originalArray.length];
// current index in the new array (also the number of non-dup elements)
int currentIndex = 0;
// loop through the original array...
for (int i = 0; i < originalArray.length; ++i) {
// contains => true iff newArray contains originalArray[i]
boolean contains = false;
// search through newArray to see if it contains an element equal
// to the element in originalArray[i]
for(int j = 0; j <= currentIndex; ++j) {
// if the same element is found, don't add it to the new array
if(originalArray[i].equals(newArray[j])) {
contains = true;
break;
}
}
// if we didn't find a duplicate, add the new element to the new array
if(!contains) {
// note: you may want to use a copy constructor, or a .clone()
// here if the situation warrants more than a shallow copy
newArray[currentIndex] = originalArray[i];
++currentIndex;
}
}
// OPTIONAL
// resize newArray (using _newArray) so that we don't have any null references
Object[] _newArray = new Object[currentIndex];
System.arraycopy(newArray, 0, _newArray, 0, currentIndex);
}
public static void main(String[] args) { int val = 100; int val1 = 50; System.out.println("Number of digits in " + val + " is: " + new String(val + "").length()); System.out.println("Number of digits in " + val1 + " is: " + new String(val1 + "").length()); }
Can a private method be overridden?
No. A method that is declared as private in a class is not inherited by any other class and hence if another class that extends this class declares a method with the same name and signature, it does not mean that this method is overridden. It is an entirely separate entity.