answersLogoWhite

0

📱

Java Programming

The Java programming language was released in 1995 as a core component of the Java platform of Sun Microsystems. It is a general-purpose, class-based, object-oriented language that is widely used in application software and web applications.

5,203 Questions

How do you get the number of argument from command line?

It is very difficult task.but I will manage it by deep thinking on on the issue.

Why Overloading looks for argument not the return type?

A method's return value can be assigned to a variable:

x = myMethod(a, b);

or combined in a more complicated expressions:

result = a + b + myMethod1(c, d);

HOWEVER, it is also possible that the return value is discarded; that is, that the method is invoked, but nothing is done with the return value:

myMethod(a, b);

In this case, if there are different versions of "myMethod()" that only differ in their return value, the compiler won't know which version to use.

Can a source file contain more than one class declaration?

Yes, a source file can contain more than one class declaration. In many programming languages, such as Java and C#, it is common to define multiple classes within a single file, though typically only one can be declared as public and must match the filename. However, in languages like Python, there are no such restrictions, allowing for multiple classes to be declared freely within a single file. This practice can help organize related classes together, but it's essential to maintain clarity and readability.

Why do you need to create an object reference variable to call methods cant you directly use the objects that is created?

Creating an object and invoking a method of that object are 2 distinct steps. From good programming practice, it is better off to have 2 separate statements at least to do this.

For example:

(new object()).ToString(); // creates an instance and invoke ToString()

vs.

object objRefence = new object();

objRefence.ToString();

The variable objReference is needed to invoke the method ToString(), because the object refereced of the one being created from the new operator needed to be cached somewhere.

There is no major differences between the 2 above. However, if there is another method to be invoked, the second way (use variable reference) is the only way, the first one cannot. (You can replace ToString() with GetHashCode(), and prints it on the console twice, the first one may produce 2 different values, while the second one will be the same value. Think of GetHashCode() returns the object id in a way)

What is the meaning of anonymous classes for events in java?

Anonymous classes, basically, have no name. It combines the class declaration and the creation of an instance of the class in one step.

If an event handler is not shared by multiple components there is no need to declare a class to handle the event. The handler can be implemented with the use of an anonymous inner class. i.e. :

button1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

JOptionPane.showMessageDialog(null, "You clicked button1.");

}

});

What method exists for writing text to a document?

Two methods exist for writing text to a document, and both are methods of the document object.

  1. document.write(expr) will print the value of exprto the page.
  2. document.writeln(expr) will do the same thing, plus add a newline character at the end.

How do you initialize more than one variable in a for loop?

example with two variables (j and d):

for (i=0; i<10; ++i)

{

int j=1;

double d=8.0;

... more statements ...

}

What is the program for palindrome numbers from 500 to 100?

#include<iostream>

// forward declarations...

unsigned reverse (unsigned, const unsigned base = 10);

bool is_palindrome (const unsigned);

// the program...

int main (void) {

const unsigned max {500};

const unsigned min {100};

std::cout << "Palindromes from " << max << " to " << min << std::endl;

for (unsigned num {max}; num>=min; --num) {

if (is_palindrome (num)) {

std::cout << num << std::endl;

}

}

}

// Returns the reverse of a number using the given base (default: base 10)

// Note: trailing zeroes do not become leading zeroes so reverse (100) returns 1 not 001.

// However, the reverse of 0 is obviously 0.

unsigned reverse (unsigned num, const unsigned base /* = 10 */) {

unsigned rev {}; // zero-initialised

while (num) {

rev *= base;

rev += num % base;

num /= base;

}

return rev;

}

// If the reverse of a number is the same number, that number is a palindrome.

// All single-digit numbers are palindromes, including 0.

bool is_palindrome (const unsigned num) {

return num == reverse (num) ;

}

What is the absolute machine code?

The very lowest possible level at which you can program a computer is in its own native machine code, consisting of strings of 1's and 0's and stored as binary numbers. The main problems with using machine code directly are that it is very easy to make a mistake, and very hard to find it once you realize the mistake has been made.

Why is it important to select the proper field size for a field whose data type is number?

Because you want the field to be large enough to store the data. Also, you may not want to have it too large if you know values are going to be in a small range. If you allocate a large amount of space, that will be used by each record, even when actual values are small, so it is more efficient to use the right sizes. So, in short, you choose the appropriate size to ensure you don't have too little or too much size allocated for your intended data.

What is System Rights Applet?

The System Rights Applet is a component typically found in software applications or operating systems that allows users to manage and configure permissions and access rights for various system resources. It provides a user-friendly interface for administrators to define who can access certain files, applications, or system settings. By utilizing this applet, organizations can enforce security policies and ensure that only authorized users have the necessary permissions to perform specific tasks.

JDK version is same as JRE version?

No, not necessarily. JDK stands for Java Development Kit and JRE stands for Java Runtime Environment. They can be of the same or different versions each. It is better if we have two compatible or same versions of JDK and JRE installed for ease of use.

Does the G1's browser support Java and Flash?

No. I have read that it will support Java. I believe that it does not support flash ATM.

What is the meaning of dot in dot net?

How the Microsoft .Net ?Name has come? Is there any reason dot before Net? for example Java having some history behind name so like wise is there any reason putname like .net
Hi,
I want to know the meaning of dot in .NET. But NET means NETWORK ENABLED TECHNOLOGIES. I came to know there was meaning for dot. Iam very excited to know the meaning of dot as soon as possible.

P.MANOHAR

Define connection oriented and connectionless transmission with examples?

TCP has an acknowledgement technique of checking if data packet is received either at the client or at the server end, this is what makes it a connection oriented network service.

while

UDP does not guarantee reliability of ordering or acknowledgement the way TCP does. Datagrams may appear out of order, missing or appear duplicated. This is what makes it a connectionless oriented network service.

Can the primitive type and reference type be used together in the same array or program?

Of course they maybe used together. (do not understand what the word program meant in the question context)

However, do not put them together in an array. In fact, any collection, including an array, should hold only 1 kind of objects. (the word kind means a base class and its derived subclasses, the same interface, or the same primitive types).

Putting more than 1 kind of objects in an array is making troubles for yourself, putting more than one class of objects in an array is an acceptable practice.

Another thing to look out for, if a primitive type is always go with a reference type, or most of time, being used, or being passed to another method, you may have a new class to be designed. You should put them together into a new class.

If you have a method need to return a primitive and a reference type, you may have another class design to do as well, or the method is doing too many things (one is the principle!). 1 pair of int and Person may not be a problem.

But when you have more than 10 pairs... Do you have 2 arrays, one to hold the integers, one to hold Person? Or you have 1 array to hold both (the odd element is always the int, and the even is the Person - big mistake). Now just image that, oh by the way, you will need a String (message text) go with the int and the Person....