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

If String str US then what is the value of str.substring(2 4)?

In C++, the return value will be an empty string because 2 is equal to the string length (the second parameter, 4, is simply ignored). If the first parameter were greater than the string length, an out_of_range exception will be thrown instead.

What is a spinning class?

Spinning is an aerobic exercise that takes place on a stationary bicycle.

During the class you vary your pace, pedaling as fast as you can, other times cranking up the tension and pedaling slowly from a standing position. This helps you to focus and work on your mind as well as your body.

What are sealed classes in java?

Final classes are sealed classes in java I guess.

Ipv4 is connectionless or connection oriented?

It's neither. IP is a transport layer protocol. Connection/Connectionless imply the network layer.

Look up the OSI model.

Actually you are correct, but it doesn't just go that far. The definition of connectionless is the ability to send and receive packets without already establishing connectivity between two or more specific entities. IPv4 is connectionless, meaning if I send information via IPv4 I can just send the packets without having to do much more than click "return".

Hope this helps.

What is delegation in oops concept?

Delegation allows the behavior of an object to be defined in terms of the behavior of another object.

ie, Delegation is alternative to class inheritance. Delegation is a way of making object composition as powerful as inheritance. In delegation, two objects are involved in handling a request: a receiving object delegates operations to its delegate. this is analogous to the child classes sending requests to the parent classes.

Example in a Java/C# like language class A {

void foo() {

this.bar() // "this" is also known under the names "current", "me" and "self" in other languages

}

void bar() {

print("a.bar")

}

}

class B {

private A a; // delegationlink

public B(A a)

{

this.a = a;

}

void foo() {

a.foo() // call foo() on the a-instance

}

void bar() {

print("b.bar")

}

}

a = new A()

b = new B(a) // establish delegation between two objects

Calling b.foo()

will result in a.bar being printed, since class B "delegates" the method foo() to a given object of class A.

What resources are used when a thread is created?

When a thread is created the threads does not require any new resources to execute the thread shares the resources like memory of the process to which they belong to. The benefit of code sharing is that it allows an application to have several different threads of activity all within the same address space. Whereas if a new process creation is very heavyweight because it always requires new address space to be created and even if they share the memory then the inter process communication is expensive when compared to the communication between the threads

WAP to interchange the value of two variable without third variable?

Ellipses (...) used to emulate indentation... swap (int *i1, int *i2) { /* only works for integers, i1 != i2 */

... *i1 = *i1 ^ *i2;

... *i2 = *i1 ^ *i2;

... *i1 = *i1 ^ *i2;

}

What are the valid signatures of the main method of a class?

The main method can be declared as either of the below: public static void main(String[] args)

or public static void main(String args[])

What does the import java.io. file class do?

It gives you access to all of the IO file classes, including all of the stream classes and java.io.File.

How do you search for an element in unsorted array?

Let's use integers as an example.

int elementToFind; // the element we want to search for

int[] elementArray; // the array we want to search through

boolean found = false; //boolean flag to indicate if we found the element or not

for(int i = 0; i < elementArray.length; ++i) {

if(elementArray[i] == elementToFind) {

// we found the element at index i

// do whatever you want to do with this information

found = true;

}

//if found is still false so it means this element is not found

if(!found) {

//the element is not found in the array

}

}

What is an abstract equation?

An abstract equation is an equation where it is impossible, with the information given, to find the numeric values of the variables. For example 2X=4Y can be reduced to X=2Y or Y=X/2 or 2=X/Y but you cannot find the numeric values of X or Y.

How do you compile and run with the same file name provided file name and class name are different?

You are supposed to use the same name for the filename and the class name. I am not entirely sure what happens otherwise; at the very least, I would expect that you would get unnecessary complications.

Is it true In a sequential search each element is compared to the searchValue and the search stops when the value is found or the end of the array is encountered?

As I know the search method depends on your(programmer's) logic. In sequential search it will be better to stop the search as soon as search value encounters or if search value is not in the array then it should stop at the end.

How do you convert a string into a character array?

A string is, by definition, a character array. No conversion is required.

Can you override method in the same class?

You cannot override a method inside the same class. If you do that, it is called Overloading. Experienced java programmers can clearly identify the difference between overloaded methods and the overridden ones. We just had a detailed look at overridden methods and it is time to take a look at the overloaded ones.

Overloaded methods let you reuse the same method name in a class, but with different arguments (and optionally, a different return type). Overloading a method often means you're being a little nicer to those who call your methods, because your code takes on the burden of coping with different argument types rather than forcing the caller to do conversions prior to invoking your method. The rules are simple:

• Overloaded methods MUST change the argument list.

• Overloaded methods CAN change the return type.

• Overloaded methods CAN change the access modifier.

• Overloaded methods CAN declare new or broader checked exceptions.

• A method can be overloaded in the same class or in a subclass. In other words, if class A defines a doStuff(int i) method, the subclass B could define a doStuff(String s) method without overriding the superclass version that takes an int. So two methods with the same name but in different classes can still be considered overloaded, if the subclass inherits one version of the method and then declares another overloaded version in its class definition.

How do you print the pattern ABCdcba ABC cba?

There are many different ways to print out a random sequence of letters on the screen. I believe that the shortest possible line of code that does this is:

System.out.println("abcdcba abc cba");

For a program, here is the shortest program that runs on a Java 1.6 compiler:

public class A{public static void main(String... a){System.out.println("abcdcba abc cba"

Meaning of sequential access method and example of it?

Sequential access basically means accessing things one after the other in order. For example reading all the numbers from 1 to 10 by starting at 1, then 2, then 3 etc.

How Write a c program to find and replace a string in the given text?

  1. #include
  2. # include
  3. char c1,c2,a[80];
  4. void main()
  5. {
  6. clrscr();
  7. find_rep();
  8. getch();
  9. }
  10. void find_rep(void)
  11. /* Function to find & replace any text */
  12. {
  13. char c1,c2;
  14. char a[80];
  15. int i,j,k;
  16. printf("Enter a line of text below:-");
  17. printf("Press Enter after line..");
  18. printf("You Have Entred:- ");
  19. gets(a);
  20. printf("Enter the replaceable & replacing letter respectively:- ");
  21. scanf("%c %c %c",&c1,' ',&c2); //i have given space & 2nd %c
  22. for (j=0;j<80;j++)
  23. {
  24. if (a[j]==c1)
  25. a[j]=c2;
  26. }
  27. puts(a);
  28. printf("Here all %c are replaced by %c.", c1,c2);
  29. return;
  30. }

Which is better - AVL or Red Black Trees?

It depends on what the tree is being used for. If the tree is being used to store data that is not going to be modified very much, than AVL trees are probably better. In most other cases, I'd say Red-Black trees are better.