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

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.

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.

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.

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.

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"

How do you get rid of Java-ByteVerify?

== == == == == == This is not a virus, but rather a method to exploit a security vulnerability in the Microsoft Virtual Machine. First, update to the latest version of Java Runtime Environment (JRE) - 6 Update 3 (as of June 2008. # Click on Start> Control Panel and double click on Add/Remove Programs. Locate Java 2 Runtime Environment, SE v1.4.2and click on Change/Remove to uninstall it. # visit the SUN Java's website. http://java.sun.com/javase/downloads/index.jsp

# Scroll down to Java Runtime Environment (JRE) 6 Update 3. Click on Download. # Select Accept License Agreement. The page will refresh. # Click on Windows Offline Installation, Multi-language and save it to a convenient location. # Run this installation to update your Java. 2) Run a windows update

3) Do a complete scan with a fully updated Anti virus Program.

Can you use objects in class level declaration?

Objects are classes... It's the most abstract type of data.

Garbage collection in net and j2ee?

How Does the Garbage Collector Work?

You just can't be sure. You might hear that the garbage collector uses a mark and sweep algorithm, and for any given Java implementation that might be true, but the Java specification doesn't guarantee any particular implementation. You might hear that the garbage collector uses reference counting; once again maybe yes maybe no. The important concept to understand for the exam is when does an object become eligible for garbage collection? To answer this question fully, we have to jump ahead a little bit and talk about threads. (Don't worry, We will take a detailed look at Threads in future.) In a nutshell, every Java program has from one to many threads. Each thread has its own little execution stack. Normally, the programmer causes at least one thread to run in a Java program, the one with the main() method at the bottom of the stack. However, there are many really cool reasons to launch additional threads from your initial thread. In addition to having its own little execution stack, each thread has its own lifecycle. For now, all we need to know is that threads can be alive or dead. With this background information, we can now say with stunning clarity and resolve that an object is eligible for garbage collection when no live thread can access it.

Based on that definition, the garbage collector does some magical, unknown operations, and when it discovers an object that can't be reached by any live thread, it will consider that object as eligible for deletion, and it might even delete it at some point. When we talk about reaching an object, we're really talking about having a reachable reference variable that refers to the object in question. If our Java program has a reference variable that refers to an object, and that reference variable is available to a live thread, then that object is considered reachable. We'll talk more about how objects can become unreachable in the following section.

Can a Java application run out of memory? Yes. The garbage collection system attempts to remove objects from memory when they are not used. However, if you maintain too many live objects (objects referenced from other live objects), the system can run out of memory. Garbage collection cannot ensure that there is enough memory, only that the memory that is available will be managed as efficiently as possible.

What is the difference between first class and business class on united airlines?

first class first class bigshots will go..Business class business freak junk heads will go..hehehehheheh

Is string is a primitive type or not?

,

Strings are not a primitive data type and strings are objects of class String.

They have been built this way primarily because a large number of methods can be implemented for use if string is a class. That way coding regarding strings is much easier.

If you really want to implement it as a primitive data type, go ahead and create an array of characters. but then you wont be able to utilize all the string related methods in JDK

Regards,

Prime

Three kinds of relationships in object oriented modeling?

  • 'is_a' classification relations
  • 'part_of' assembly relationships
  • 'associations' between classe