Why do you need other programming language other than java?
different languages has different purposes some are low level and some are high level e.g assembly language that is low level(not as a whole) works with machine but java didn't that's why we need other programming languages
What are the situations where overloading function can be an ambiguity?
We know that compiler will decide which function to be invoked among the overloaded functions. When the compiler could not choose a function between two or more overloaded functions, the situation is called as an ambiguity in function overloading.
When the program contains ambiguity, the compiler will not compile the program.
The main cause of ambiguity in the program
· Type conversion
· Functions with default arguments
· Functions with pass by reference
Type conversion
#include
using namespace std;
#include
void fun(int i)
{ cout << i;}
void fun(float f)
{ cout << f;}
int main()
{
fun(10);
fun(10.2);
return 0;
}
In this example type conversion creates ambiguity. fun(10) will refer the first function.
We think the value 10.2 is floating point value. So fun(10.2) will refer the second function. But fun(10.2) will refer which function? It could not refer any function. Because 10.2 will be treated as double data type by the compiler. (In c++ all the floating point values are converted by the compiler as double data type.) This is type conversion of float to double. So now compiler could not search the function fun with double data type.
So the compiler will give error message call of overloaded 'fun(double)' is ambiguous.
This example clearly rises the ambiguity in the program because of the type conversion.
Functions with default arguments
#include
using namespace std;
#include
void fun(int i)
{ cout << i;}
void fun(int i, int j=8)
{ cout << i << j;}
int main()
{
fun(10);
fun(10.2f);
return 0;
}
This program will give error message that overloaded 'fun(int)' is ambiguous. Because the fun(int i, int j =8) is a function with default arguments. It can be called in two ways. They are
(i) function with one argument.
fun(2) now the value of i is 2 and j is 8 (8 is the default value).
(ii) function with two arguments fun(5,6). So i is 5 and j is 6.
fun(int i) is a function with one argument. It should be invoked with one argument. So
when we call a function with 1 argument the compiler could not select among the two functions fun(int i) and fun(int i, int j=8).
This example clearly illustrates the ambiguity in the program because of function with default arguments.
Function with reference parameter
#include
using namespace std;
#include
void fun(int i)
{ cout << i;}
void fun(int &i)
{cout <
int main()
{
fun(10);
return 0;
}
This program will show the error message call of overloaded 'fun(int)' is ambiguous.
First fun(int) takes one integer argument and second function fun(int &) takes a reference parameter. In this case, compilers do not know which function is intended by the user when it is called. Because there is no syntactical difference in calling the function between the function with single argument and function with single reference parameter.
So compiler could not decide which function should be invoked when it is called. So this leads ambiguity in the program.
What are the cordinates of java?
Java, one of the main islands of Indonesia, is centered near 7°30′10″ S, 111°15′47″ E and stretches from about 106° E to 114° E , along the northeast edge of the Indian Ocean in southeast Asia. The Indonesian capital of Jakarta is on Java.
What is Polymorphism and inheritance explain with example?
Polymorphism, is an object-oriented programming concept, which relates to the ability to create a variable, function or an object that has more than one form. This allows the object to invoke the correct instance of the variable, function or other object based upon the object type. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.
Here are some links to examples:
C++: http://www.cplusplus.com/forum/beginner/10884/
c#: http://msdn.microsoft.com/en-us/library/ms173152.aspx
Python: http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming
Java: http://www.tutorialspoint.com/java/java_polymorphism.htm
What is serializable class in JAVA?
The serializable interface is used to perform the serialization action. Serialization is the process by which the contents of an object are written to any form of storage - say a flat file. This data stored in the flat file can be de-serialized at any time to create the object.
Ex: public class Test implements Serializable {
…
//lots of code
}
What is the difference between throw and throws in Java?
Throw is used to actually throw the exception, whereas throws is declarative for the method. They are not interchangeable.
public void myMethod(int param) throws MyException
{
if (param < 10)
{
throw new MyException("Too low!);
}
//Blah, Blah, Blah...
} The Throw clause can be used in any part of code where you feel a specific exception needs to be thrown to the calling method.
If a method is throwing an exception, it should either be surrounded by a try catch block to catch it or that method should have the throws clause in its signature. Without the throws clause in the signature the Java compiler does not know what to do with the exception. The throws clause tells the compiler that this particular exception would be handled by the calling method.
How many packages available in java?
A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time. Programmers also typically use packages to organize classes belonging to the same category or providing similar functionality.
· A package provides a unique namespace for the types it contains.
· Classes in the same package can access each other's members.
package is a container in which similar classes are grouped together.
package avoid the redundance of classes. it also provide security to hide the code only by importing the packege which contains the required class.
Difference between base class and derived class?
The derived class derives, or inherits, from the base class. The derived class is like a "child", and the base class, the "parent". The child class has the attributes of the parent class - its variables (those defined at the class level) and methods. Changes done to the parent class (the base class) will affect the child class (the derived class).
A Java application can accept any number of arguments from the command line. This allows the user to specify configuration information when the application is launched.The user enters command-line arguments when invoking the application and specifies them after the name of the class to be run.
What is Keyword Research and Analysis?
Keyword research is important in order to be able to narrow you niche so that there is less competition for your page when it is crawled by the Search Engines. It is just one of many factors that may contribute to higher search engine rankings more traffic.
Google has a free keyword research tool to help you find the best keywords and phrases for your topics.
The best keywords have:
a) high search volume - lots of people searching for that phrase
b) low competition - not too many pages on the web that feature that phrase
What is difference between abstract class and interface in core java give brief answer with example?
Differences:
An interface can be considered as a pure abstract class that contains no method implementations and contains only declarations.
Reverse of a given string using recursion?
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char str[10],temp;
int i,len;
printf("Enter String : ");
scanf("%s",str);
len=strlen(str)-1;
for(i=0;i<strlen(str)/2;i++)
{
temp=str[i];
str[i]=str[len];
str[len--]=temp;
}
printf("%s",str);
getch();
}
Please do give your views on this.
With Regards,
Sumit Ranjan.
Analyst at RMSI Company.
What is a buzz number in java?
A number that ends with 7 and is also divisible by 7 is called buzz number.
How is Java different than any other OOP language lke C plus plus?
There are many differences between Java and other programs, as there are also similarities: - managed code: java does not produce native code, but some byte code that will make it runnable in something called "virtual machine". The best thing about that: compile on windows and deploy that application on UNIX. - full object oriented -- even more than C++ where global variables are possible. Here, in java, everything must take place in an object - works on many operating systems. - a lot of technologies grouped in J2EE, that covers many the aspects of enterprise programming - servlets, jsp, ejb, jdbc to access the database, etc. The list is huge, I don't want to get in too much detail about that.
I guess it features some of the most mature technologies on the market.
Answer to: which programming language is more robust C sharp or Java?While I generally prefer "C" as a more robust language, I also consider anything that is released by Microsoft to be unreliable and likely to fail. Java is the product of Sun Microsystems, and has a very good reputation. While I'm not a Java programmer, I have heard nothing but good reports about Java. Answer to: why is Java more secure than other languagesJava is considered more secure than other languages for several reasons:1)Java is a purely Platform independent means the application that will work in any kind of Operating System.But .Net is platform independt software.
2).Net support to develop application in different languages and to develop application Rapidly. This feature is not exist in Java
Answer to why is Java more popular than CA long time ago, many people believed Java was slower than C because Java had to run through a virtual machine. Today however, Time and speed aren't really affected by the programming language or the used technology as much as affected by memory cards capacity and processors speed (Clock rate). Hench programmers and developers started looking for the most powerful yet easy to 'learn and work with' programming language. And there came Java with the multi-platform support, Object oriented methodology and other great capabilities and features.On the other hand, General Purpose applications are still developed using C++ because it doesn't need any intermediate software to run.
and i think that java it's been improved everyday by the newest releases of the implementation of the virtual machine.
What are application-level requirements for the Currency Conversion project?
Must model each currency.
Must do I/O and currency calculations without crashing.
How do you write a program to find whether a number is a perfect square in java?
Example:
int x, y;
x = 5;
y = x * x; // square of x
System.out.println("The square of " + x + " = " + y);
Put all this in your main() method. Most Java IDEs will generate the main() method automatically.
Can you have more than 1 constructor in a class?
Yes. At least in Java, that's possible, as long as the constructors have a different number, or different types of, parameters.
Can a Volatile variable be static also?
Probably; I don't see anything in the standard that says you can't. However, the use of the volatile keyword is usually in embedded code, or multi-threading in which you don't want the compiler to do optimizations on the variable itself.
Yes, sure.
An array is a collection of similar data types. An integer array is nothing but a collection of integer data types.
Ex: int a[100], int arr[100][100]
There are several types. 1D array, 2D array, Multi-Dimensional array.
But array is a contiguous allocation. And array size will always be positive. It can be given in the declaration stage or we can specify it dynamically by using malloc function.
Ex: int *a;
a=(int*)malloc(sizeof(int)*HOW_MANY_NUMBERS_YOU_WANT);
How the new operator works in java?
1. It is the only way to create object. 2. New is a keyword. 3. New operator allocates memory for an object. 4. It is a bit faster and clever way of creating objects or instances.
What is meant by the complexity of an algorithm?
Complexity of an algorithm is the study of how long a program will take to run, depending on the size of its input & long of loops made inside the code
Specifically, the complexity of an algorithm is a measure of how long it takes to complete (give an answer) relative to increasing sizes of input data. Thus, complexity is not concerned with how long it took the algorithm to run using X amount of data. Rather, it is concerned with the relationship in runtime when using X amount of data, 2X amounts of data, 10X amounts of data, etc. While complexity usually refers to execution time, it can also be applied to other resource usage (for example, memory allocation). In all cases, complexity is concerned with the relationship between the rate of increase in resource consumption and the rate of increase of the size of the data set being worked on.
Complexity is closely related to the concepts of scalingand efficiency, but is NOT an exact equivalence to either.
Why it is necessary to avoid infinite loop in program design?
It is not necessary to avoid infinite loops. You are perhaps confusing infinite loops with endless loops which are to be avoided at all costs. An endless loop is an infinite loop that has no reachable exit condition; the loop will iterate until we forcibly terminate the program.
We use the the term infinite loop in the sense that it is impossible to measure or calculate when the exit point will be hit. the following are all examples of infinite loops in their simplest form:
for (;;) {
// ...
}
while (true) { // ... }
do while (true) {
// ...
}
endless:
// ...
goto endless;
The conditional expressions in each of these loops can never be false thus we cannot easily determine when these loops will exit. We typically use infinite loops when there are many exit conditions to consider and it is either impractical or inefficient to evaluate all of those conditions via the controlling expression alone. We take it as read the exit conditions are contained within the body of the loop.
If the body of the loop has no reachable exit condition then it becomes an endless loop. It is the programmer's responsibility to ensure that all infinite loops can exit at some point.
There Are Two main types of data. Qualitative data are expressed As numbers, obtained by counting or measuring. Another type of data is called an inference.An inference is a logical interpretation based on prior knowledge or experience.
What are return statements in java?
you can understand what is the purpose of return in java after this simple example
Basically return use in java to return some values from a method
note: this sample will work on all java versions, i test it on JDK 1.4
enjoy the code.
file name : Class1.java
-----
package mypackage1; //package name
public class Class1 //class name + file name the
{
public String add(int a,int b) //a method in the class; its type is String and it take a and b variables; a and b are int
{
int answer = a+b; //this is some code in the class; maybe some operations; no need to know whats happening in this method
System.out.println("I'm in Class1"); //this is some code in the class; maybe some operations; no need to know whats happening in this method
return " I'm the returned value "+ answer; ////this is what you need to take from the method
}
public static void main(String [] arg)
{
Class1 c1 = new Class1(); //creating c1 object from Class1 Class
System.out.println(c1.add(10,6)); //printing the returned values from the method;
}
}
-----------------
output:
I'am in Class1
I'am the returned value 16