An inner class declared as static is treated as if it were a normal top-level class.
Write a program to copy the contents of one array into another in the reverse order?
do something like this
char[] myArr = {'a','b'};
StringBuilder sb = new StringBuilder();
sb.reverse();
char[] charArr = sb.toString().toCharArray();
or something like this
char[] charArr = new char[myarr.length];
for (int i=myarr.length-1,j=0;i>=0;i++,j++){
charArr[j] = myarr[i];
}
Why encapsulation does not implement information hiding in object orientation?
Encapsulation also implements data hiding in an object oriented programming design. By encapsulating various methods & data objects into a single class they can also be hidden from all the other classes. You can declare the variables and methods as private and that way you can hide the data from the other classes in the application.
How do you convert an ArrayList to a HashMap?
Unfortunately, there seems to be no built in way of adding all elements of a list to a map. This means that we need to iterate through each element of the ArrayList and add it to the HashMap individually.
/**
* Generic method to add all elements from source into dest.
*/
public static final
// Iterate through each element in source and put it in dest.
for (int i = 0; i < source.size(); ++i) {
// We will use the index of each element of source as the key in dest.
dest.put(i, source.get(i));
}
}
Sample use:
// Create a new ArrayList and add some stuff to it.
ArrayList
list.add(1); list.add(2); list.add(3);
list.add(4); list.add(5); list.add(6);
list.add(7); list.add(8); list.add(9);
// Print out our list
System.out.println(list);
// Create a new map and call our function
HashMap
addAll(list, map);
// Print out to verify identical contents
System.out.println(map);
#include
using std::cout;
using std::endl;
int main()
{
int myArrayNumberOfElements(5);
double myArray[myArrayNumberOfElements] = {1.1, 4.5, 5.7, 7.9, 10};
double sum(0);
for (int i(0); i < myArrayNumberOfElements; i++)
{
sum +=myArray[i];
}
cout << endl << "Sum of all elements: " << sum << endl;
system("PAUSE");
return 0;
}
What is the optional in a variable declaration statement?
Optional is the assignment of the value of course.
int number; //Variable Declaration
int number=2; //Assignment Declaration
What machine instruction is used to assign a value to a variable in c plus plus?
MOVE, STORE, LOAD, or something similar, CPU-dependent.
Can unhandled exceptions be tolerated?
Yes, but they dont always result in acceptable or good behavior.
Exception handling allows developers to detect errors easily without writing special code to test return values. Even better, it lets us keep exception-handling code cleanly separated from the exception-generating code. It also lets us use the same exception-handling code to deal with a range of possible exceptions.
So, it is always a good idea to handle exceptions rather than leave them unhandled
What is type promotion of java?
Type promotion is an automatic type conversion from a "lesser" base type to a "greater" one or from any type to String via the toString() method.
A promotion from on base type to another may occur in an arithmetic expression:
Example:double x = 3.14 + 10; /* 10 is promoted to a double */ double y = 12; /* 12 is promoted to a double then assigned */As mentioned earlier, type promotion occurs from a "lesser" type to a "greater" one where a type is "less" than another if it offers smaller precision. In our previous example, an int offers less precision than a double thus an int value can be promoted to a double as necessary. For the same reason a double cannot be promoted to an int. If an double is used where an int is expected, Java will generate an error:
Example:int z = 2.4; Compile-time error: possible loss of precisionExample program of how to convert infix notation to postfix notation and prefix notation?
What happens if a constructor is not defined in class?
Nothing happens. The compiler successfully compiles the class. When a class does not have a specific constructor, the compiler places a default no argument construtor in the class and allows you to compile and execute the class.
public class Test {
}
and
public class Test {
public Test(){
}
}
are one and the same.
What is meaning for BufferedReader br equals new BufferedReader new InputStreamReade System in?
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
This line will create a new BufferedReader object, which reads from System.in (standard input). The InputStreamReader part is used to convert System.in (which is an InputStream) to a Reader object (which can be used by BufferedReader).
After creating br, you can read input from the user:
String input = br.readLine();
The line above will allow the user to type in anything they want, press the
Sounds suspiciously like a homework question. :P
Does C language has a interpreter?
There might be C language interpreters, but they have no or minimal importance in actual programming.
What are disadvantages of file system?
File system data management (or flat-file databases) served as the only method of file storage and retrieval before the advent of database management systems (such as relational databases). While retaining some use, flat-file databases suffer from poor accessibility, data redundancy, lack of standard file access and the inability to organize data.
Wap to display string in the ascending order in java?
public class CreateDatabase{ public static void main(){ int a=10; int b=20; int result =a+b; System.out.println(result); } }
How do you switch off Java updates for Vista?
First, open up the Control Panel: Start -> Control Panel If you're using the default view for Control Panel, click on "Programs." Now click on "Java" (If you use the classic view option, this will show up right away and you can double click it.) When the Java Control Panel pops up, click on the Update tab, and uncheck the "Check for Updates Automatically" box. There may be a warning message that pops up; click on the Never Check button to turn off updates. Now click on the OK button and close the Control Panel window and you're all set.
What is the methods with the parameters of an AWT?
AWT (Abstract Window Toolkit) is a top-level Java package. Listing out the hundreds or thousands of methods would be a waste of effort.
See the related link below for the Java documentation on the AWT package.
Difference between reference and object in java?
On the lower level of Java, a "reference" can be thought of like a pointer in C. It is essentially an integer which refers to (points to) a location in memory where the object data exists.
// "button" is a reference to a JButton with a "1" on it (the object).
JButton button = new JButton("1");
C program to find the mean median mode?
try this---> http://c-pgms.blogspot.com/2008/08/program-to-find-meanmedianand-mode_22.html
How do you represent or in java?
A boolean or comparison in Java is made with the operator.
boolean a = true;
boolean b = false;
if( a b) {
...
}
A bitwise or comparison in Java is made with the | operator.
int n = 1;
int m = 2;
if( n | m == 3 ) {
...
}
What happens if the controlling expression in a do while loop is initially false?
The do-while loop is designed specifically for such situations, where you want the loop to execute once irrespective of the loop expression.
The loop would execute once and then terminate because, the loop controlling expression is false.
If you note the syntax properly
do {
...
...
...
} while(condition)
The condition is executed only after one iteration of the loop and hence the code would execute once irrespective of the loop expression result.
The Java keyword is used to declare a class as a subclass of another class?
class MyClass extends AnotherClass {
}
This is packaging for food. A packaging that provides protection, resistance from temperature, and special physical, chemical needs. It must handle and represent all the nutrition facts, label and all other related information about food.
How do you add tangent in calculator in java?
You are able to calculate the tangent of a number using the Math class (java.lang.Math). The tan(double a) method is the one you are looking for. For example: double a = 2.5; double tangent = java.lang.Math.tan(a);