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 many threads run at the start of JVM?

at the starting of the JVM it handels approx 7000 threads .........

Can you instantiate an abstract class?

No. You must create a subclass of the abstract class in order to be able to instantiate it.

Types of purchase method?

What is the type of purchase method? And I want to know about what different between purchase method and pooling method?

installment plans: People began to buy expensive goods using installment plan credit during the 1920s.

What is mean by class access?

Class access is the ability for any given class to access the functions of another class. Private access limits access to data and code just to the class that contains the private access modifier. The so-called "default" access grants private access, as well as access to any class in the same package. Protected access grants the same as "default" access, and also allows subclasses to access the code and data. Public access allows any class in any package to access the code and data.

What is static key word?

It is one of the constant key word and it is used only in run time

How do you implement multiple inheritance through interface in java?

The multiple inheritance is supported by using more implements key word

example

class a implements b, implements c, implements d

{

....

}

so here the class a supports multiple inheritance by implementing class b,c,d.

Java does not support true multiple inheritance - true M.I. requires that a class be able to inherit directly from multiple classes. That is, in M.I., Class A can be a direct child of Class B and C.

To get much of the functionality and advantages of the M.I. model, Java uses Interfaces. Thus, a Java Class A will be the child of Class B, but can implement several interfaces X, Y, and Z. This attempts to mimic the behavior that in a M.I. language would be given by Class A being a direct child of B, X, Y, and Z.

The major difference between a M.I. language and a single-inheritance language with interfaces (like Java), is that interfaces can only define the method signatures and constants; they CANNOT provide implementations of those methods in the interface specification. Thus, any class which implements a given interface must provide an actual implementation of the methods that the interface describes. The big downside to this is that it can lead to a large amount of "code copying" - that is, if both Class A and Class B implement an interface X, there is a good chance that most of the methods from X will have the same code implementation in both Class A and B. Sometimes this is unavoidable; however, it is also considered good programming style to use abstract Classes to implement commonly used interfaces, then put that abstract class fairly high in the object hierarchy, allowing large numbers of classes to inherit from that abstract Class (which, in turn, means they have access to the implementation of those interfaces without having to copy the code). The advantage of interfaces is that they can keep things conceptually clean, and also make it simple for classes to decide how they want to implement the method contract the interface describes.

Practically speaking, if you would like Class A to inherit from Class B and also to inherit from Class C, then, in Java, you would simulate this via interfaces this way:

public class B {

// the superclass

methods_go_here_with_their_implementations;

}

public interface C {

// the Java equivalent of Class C in a M.I. Language

the_method_signatures_of_C_go_here;

}

public class A extends B implements C {

implementations_of_methods_in_C_go_here;

}

What is a logic error in a programs code?

It is a generic term for screwing the program code up. It means that somewhere in the coding it is not doing what it is supposed to do. Say you wanted to add the amount of apples and then print the amount for inventory. The code says that it is adding the apples then sending a zero amount for the amount to the inventory.So the inventory shows a zero balance all the time. This is a logic error. Good luck.

Sample Sql query with explanation for selecting the alternate row from the table?

SELECT *

FROM ( SELECT FirstName LastName

FROM people

) @tempTable1

WHERE MOD(@temptable1.rn 2) 1

--even number query

SELECT *

FROM ( SELECT rownum rn firstname lastname

FROM people

) @temptable1

WHERE MOD(@temptable1.rn 3) 0

but it is not working properly...can anubody tell me what is rownum here...

How do you delete and recreate a service?

If u r asking how to delete and recreate a Microsoft service, then the following would help u.

Note: take a backup of the registry before attempting these steps.

from services.msc doubleclick on the service you want to delete and find the service name

from the cmd console, type

///sc delete <servicename>

deleted service

check with services.msc you will find it disabled.

now type,

/// reg copy hklm\system\ControlSet001\services\<servicename> hklm\system\CurrentControlSet\services

operation completed successfully

restart the machine.

or

you can export the registry,delete the key using SC command and restart the PC and merge the backup.

Disclaimer: Try this at your own risk

How do you delete all table in a database?

Unless you want to drop (delete) the entire database, you will must delete tables individually.

To delete tables individually, execute the query "SHOW TABLES" in your database which will return a list of all table names. Iterate through that resultset and execute "DROP TABLE {$table_name}"

What does 'public static final int' mean?

public: It can be called (method) or accessed (field) from any class in any package.

static: It is declared on the class rather than the object. If a method, you do not need an object to call it, it can be called directly on the class. If a field, there is only one variable for the class, not one per object.

final: If a method, the method cannot be overridden. If a field, the value cannot be changed (a constant).

int: If a method, the return type. If a field, the field type (it can only hold values of type 'int'). int is the primitive integer type.

Is duplicated data is accepted in linked list?

Yes definitely, a linked list can accept duplicate data. As the data of each node does not have any concern with data of other node. The node differs from each other in their addresses. Until user does not make the linked list to accept unique data, the linked list can accept duplicates.

if unsorted (e.g. representig a queue): yes

if sorted (e.g. representing a set): should be decided design-time

If a method calls another method and that method throw an exception then caller method must be throw that exception or not?

If method A calls method B and method B throws an exception, then method A must handle that exception. It does not have to throw the exception if it is in a try-catch block, but it must do something to deal with it.

Note that this only applies to checked exceptions. If method B throws an unchecked exception, then A is allowed to ignore it.

How do you remove recursion using stacks?

Using stacks won't remove recursion, they can only re-implement those recursions. In some cases we don't actually need a stack to implement a recursive algorithm, in which case an iterative implementation will typically perform better with little to no cost in additional memory. But if we require a stack in order to implement recursions iteratively, then we pay the cost in terms of additional memory consumption (the "built-in" call stack is fixed-size and exists whether we use it or not). In addition, there may be a performance cost if we cannot determine how much additional memory we need.

As an example, consider the recursive quicksort algorithm:

template<typename T>using iter = std::vector<T>::iterator; template<typename T>void quicksort (iter begin, iter end) {

if (begin<end) {

size_t pivot = partition (begin, end);

quicksort (begin, pivot - 1);

quicksort (pivot + 1, end);

} // end if

}

Note that the partition algorithm is not shown for the sake of brevity. However, it is best implemented as a separate function as its local variables play no part in the recursion.

Being a divide-and-conquer algorithm, this algorithm requires a stack for back-tracking. Here is the iterative equivalent using a stack:

template<typename T>using iter = std::vector<T>::iterator;

template<typename T>void quicksort (iter begin, iter end) {

if (begin<end) {

std::stack<std::pair<iter, iter>> s {};

s.push ({begin, end});

while (s.empty() == false) {

begin = s.top().first();

end = s.top().second();

s.pop();

size_t pivot = partition (begin, end);

if (pivot + 1<end) s.push ({pivot + 1, end});

if (begin<pivot - 1) s.push ({begin, pivot - 1});

} // end while

} // end if

}

Note that the order we push the pairs on at the end of the while loop is the reverse order we wish them to be processed. The order doesn't actually matter, but it ensures both algorithms operate in a consistent manner, with depth-first traversal from left to right.

This implementation is naive because each push allocates new memory for each pair object we push onto the stack, releasing the same memory with each pop. Allocating and releasing system memory on a per-element basis like this is highly inefficient, so it's highly unlikely that this version will perform any better than the recursive algorithm.

However, the quicksort algorithm guarantees that there can never be more elements on the stack than there are elements in the initial range, so we can improve performance significantly by reserving sufficient memory in advance:

template<typename T>using iter = std::vector<T>::iterator;

template<typename T>void quicksort (iter begin, iter end) {

if (begin<end) {

std::vector<std::pair<iter, iter>> v {};

v.reserve (end - begin);

v.emplace_back (begin, end);

while (v.empty() == false) {

begin = v.back().first();

end = v.back().second();

v.pop_back();

size_t pivot = partition (begin, end);

if (begin < pivot - 1) v.emplace_back (begin, pivot - 1);

if (pivot + 1 < end) v.emplace_back (pivot + 1, end);

} // end while

} // end if

}

Note that in this implementation we use a vector rather than a stack, however all pops and pushes (implemented as emplace_back operations) occur at the back of the vector where the unused elements are, and that's precisely how an efficient stack should be implemented. As a result, this version will perform significantly better than the previous version and should perform at least as well as the recursive implementation if not better. The only significant cost is the cost of reserving memory in the vector.

What is the use of passing an argument by value?

Passing an argument by value means that the method that receives the argument can not change the value of the argument. Passing an argument by reference means that the method that receives the argument can change the value of the incoming argument, and the argument may be changed in the orignal calling method.

What is embedding java script?

To embed JavaScript code is to include it in the HTML page. For example, this will embed the code to display an alert:

<script type="text/javascript">

alert("Embedded alert!");

</script>

What is pallendrome in java?

palindrome in every language means same. it means on reversing a number or string, if we get the same number or string as the case may be ,then the number or string is called palindrome. eg: 1221,111,252 or LIRIL,MADAM etc .