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

Write a program to encrypt a string and decrypt it using your own method of encryption and decryption.?

We'll use a simple method of encryption: xor encryption

// same function used to both encrypt and decrypt

void crypt(char *str) {

const int key = 0x86;

// crypt each individual character of str

int i;

const int length = strlen(str);

for(i = 0; i < strlen(str); ++i) {

str[i] = str[i] ^ key;

}

}

IS Throwing an exception always causes program termination?

No Not necessarily..

You can catch an exception and then continue to execute your program as if nothing happened.

If in your catch block you have code like System.exit then your program would terminate.

What is unicast remote object in java?

The UnicastRemoteObject class defines a non-replicated remote object whose references are valid only while the server process is alive. The UnicastRemoteObject class provides support for point-to-point active object references (invocations, parameters, and results) using TCP streams.

What is the defference between bisection method and newton method?

there are three variable are to find

but in newton

only one variable is taken at a time of a single iteration

A Java method that takes an integer array as a formal parameter and returns the sum of integers contained within the array?

I don't know if I fully understand but here goes

int a[]={2,4,8,0,2};

int y = 0;

int x = 0;

while(y<a.length()){

x += a[y];

y++;

}

then you just reference x.

How could Java classes direct program messages to the system console but error messages say to a file?

Sytem.out amd System.err is used to get the output, and refer to standard output strem and which is by default console ... u can send the output to any other stream or log file either by importing java.io.file and show the output to the console and run time error to any file using exception handling .... or u can give the command while running the program which will redirect this to log file as ... java ClassName 2error.log this will send error message to error.log file and output to console. ... u can send both the output and error to log file as... java ClassName output.log 2 error.log ... here ClassName is the name of the calss file which u wanted to execute

If you enter same function name into two interfaces than how you implement these two into one class?

If you have two (or more) interfaces with the same method definition like this:

public interface one(){

public int doSomething();

}

public int interface two(){

public doSomething();

}

You can implement both in the same class:

public class myClass implements one, two{

public int doSomething(){

// the code to do something goes here

return 0;

}

}

And you only have to write the implimentation once. This code is valid for all the interfaces implemented with a doSomething() method.

What are the methods of hash table?

See the related link below for the Java API documentation for the Hashtable class and its methods.

What r conditional loops and unconditional loops in c?

A conditional loop will only continue to loop while the given condition is true:

while( i < 10 ) {

...

}

An unconditional loop either has no condition (a GOTO loop), or the condition is guaranteed to always evaluate to true:

while( true ) {

...

}

Write an equivalence of switch statement and if statement?

switch(ch)

{

case '+':

....cout <<"arithmetic operator";

....break; //<===break is a must

/// <====================other cases

.

.

default: // <=======else

}

Does a collection require an array?

No. While there are quite a few which use arrays to store their data (ArrayList, HashMap, Vector, etc.) the typical counter example is a LinkedList. Java's implementation of the LinkedList class uses the standard Entry-Entry.next method of connecting elements in the list.

You can even consider a collection as something that is similar to an array but with enhanced features. Collections have a lot of features that arrays do not have.

What is meaning of word persistence in java?

Persistence is the term used to refer to the situation where the objects data is stored even after the object is destroyed or the application is closed.

Persistence is implemented using Serialization where the data of the object is serialized into flat files and stored into the system. These files can be de-serialized to form the objects by using de-serialization.

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.