How do you convert jar file into any readable file?
A .jar file is just an archive (Java Archive) file. To see the files inside it you need to use a file compression utility to decompress the archive. you can use JAD to decompress the archive and get the stuff inside it.
Java source files have the .java extension, compiled Java class files have the .class extension.
What is a java constructor and write a program?
Constructors have the same name as the class itself and they do not specify a return type, not even void because they return the instance of the class itself.
Because constructors have the same name as the class then they allow method overloading and also save memory and execution time of program.
Program release memory of constructors function after using this function and it reduce program complexity.
Why do you use the loops in java?
You use loops in Java when you want a set of actions to be repeated until a particular condition is met or for a certain number of times.
The different types of loops in Java are:
What is a predefined interface in java?
An interface is a collection of methods that must be implemented by the implementing class.
An interface defines a contract regarding what a class must do, without saying anything about how the class will do it.
Interface can contain declaration of methods and variables.
implementing class must define all the methods declared in the interface
If a class implements an interface and does not implement all the methods then class itself must be declared as abstract
Variables in interface automatically become static and final variableof the implementing class
Members of interface are implicitly public, so need not be declared as public.
An interface must be implemented in class.
What is an Arraylist used for?
An ArrayList is a data structure. It stores data in an array that can be dynamically resized. This data structure in Microsoft .NET Framework contains Methods that assist the programmer in accessing and storing data within the ArrayList. The following link explains the .NET ArrayList class. http://msdn2.microsoft.com/en-us/library/system.collections.arraylist(vs.80).aspx
What is difference between for loop and while loop?
One first basic rule is that you should use the for loop when the number of iterations is known. For instance:
The while loop is the more general one because its loop condition is more flexible and can be more complicated than that of a for loop. The condition of a for loop is always the same and implicit in the construction. A for loop stops if there are no more elements in the collection to treat. For simple traversals or iterations over index ranges it is a good advice to use the for statement because it handles the iteration variable for you, so it is more secure than while where you have to handle the end of the iteration and the change of the iteration variable by yourself.
The while loop can take every boolean expression as condition and permits therefore more complex end conditions. It is also the better choice if the iteration variable does not change evently by the same step or if there are more than one iteration variable. Even if you can handle more than one iteration variable in a for statement, the collections from which to choose the values must have the same number of elements.
Note: In C 'for' and 'while' can be easily replaced by each other:
while (exp) stmt
for (;exp;) stmt
for (exp1;exp2;exp3) stmt
{ exp1; while (exp2) { stmt exp3}}
How do you know if you have java?
The best way to find out if your Java is up to date is to visit the Java website. You can then check the latest verison number, and compare it to what is already on your computer. You check in your programs and files. You can also choose to update, and if you have the current version it won't do it.
Difference between yield method and sleep in java?
Thread.sleep(long milliseconds): The thread's sleep method sends the current thread into Non-Runnable state for the specified amount of time. But, this doesn't cause the thread to loose ownership of the acquired monitors. So, if the current thread is into a synchronized block/method, then no other thread will be able to enter that block/method.
The Sleep method throws 'InterruptedException' if another thread interrupts it.
There is another variant of the 'sleep()' method where it accepts two arguments - one, long milliseconds, and second, int nanoseconds. Simply put, this method causes the current thread to sleep for the specified number of milliseconds plus the specified number of nanoseconds. The second argument 'int nanoseconds' can acquire a value of the range 0-999999.
wait() method: The wait() method also sends the current thread into Non-Runnable state like the sleep() method. But, the difference between the two is that in case of 'wait()' the locks are released before going into Non-Runnable state, so that any other thread that is waiting on the object can use it (Unlike the Sleep method - This is the big difference) Another apparent difference is that 'wait()' is an instance method, while sleep() is a static method. The method 'wait()' should be called for an object only when the current thread has already acquired lock for that object. This causes the current thread to wait either another thread invokes the 'notify()' method or the 'notifyAll()' method for this object, or a specified amount of time has elapsed and after that the thread starts participating in thread scheduling process to acquire the monitor of the object to proceed further.
There are three variants of this method in the 'Object' class:-
public final void wait(long timeout)
public final void wait(long timeout, int nanoseconds)
public final void wait()
All the three methods throw InterruptedException & IllegalMonitorStateException. The first two may also throw IllegalArgumentException.
The wait() method causes the current thread to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. After the execution of this method invocation, the thread becomes disabled for any scheduling purposes and lies dormant until one of the following things happen:-
* Any other thread invokes 'notify()' method this object and the thread under consideration is arbitrarily chosen as the thread to be awakened. * Any other thread invokes 'notifyAll()' for this object. * Any other thread interrupts the thread under consideration. * The specified amount of time has elapsed (in case first two variants of wait() are used) After any of the four above mentioned events happens, the thread is removed from the wait set for this object and re-enabled for thread scheduling. It'll compete for the rights to synchronize on the object in an usual manner and it'll keep doing this until it acquires control on the object and gains all the synchronization claims on the object, which it had acquired at the time of 'wait()' invocation. This means that after the return from wait() method, the synchronization state of object and of the thread will be exactly the same as it was before the wait() invocation.
What is meant by a class in java programming language?
A class is a template of a type of object. This common paradigm in object-oriented programming (OOP) allows code that can be reused on slightly different, but common data to reduce code complexity. A template for a vehicle in a video game might store its velocity, fuel, damage, and so on. Most classes have no use until they are "instantiated", at which point the template is applied to an area of memory and it becomes an object. Some classes are never instantiated, as they help other classes, and some classes might have some functions that can be called without an instance (known as static methods). Classes allow for similar or related logic to be grouped together, allows memory to be protected from other code units also loaded in memory, and reduces overall programming complexity.
What is the function of anti static mat?
An anti-static mat is usually made of a conductive plastic. Usually, on one corner there is a snap connector. From that snap connector there is a long, (usually GREEN) wire, as well as a coiled wire that goes to a wrist strap. The green wire goes to the round GROUND connector of an AC wall socket. The coiled wire that goes to a wrist strap goes just like that. Wrap the wrist strap around your wrist.
The reason for this setup is, through the green wire to the ground connector, you put both the mat and your body at ground potential. It takes the static electricity from your body,via the wrist strap, and from the mat to ground.
Be VERY CAREFULL!! YOU MUST KNOW WHERE THE GROUND IS ON AN AC OUTLET TO USE THIS AS I HAVE OUTLINED. If you do not know where the ground pin is on an AC outlet, you should not use it.
What is dfference between synchronization and asynchronization in java with example?
synchornisation is the process where more than one thread can be accessed by accesssing the shared object of the class.By syncornisation we can have the communication between threads.if one thread works then another thread automatically stops
To get a better idea on C++ data types, see related links below.
If you're talking about factorial as in "4! = 4 * 3 * 2 * 1 = 24" then you could make a function something like this:
public int fact(int Num) {
int fact;
for (int i = Num; i > 1; i--) {
fact = i * (i - 1)
}
Return fact;
}
Give 6 characterstics of object oriented programming?
Actually these characterstics may differ from books to books. This is in general: #Data abstraction #Data Encapsulation #Inheritance #Polymorphism #Dynamic Linking #Static Binding Some books consider Objects & Classes also as one among these characteristics.
What was the difference between java and net?
Net survives because of java. Net is made up of java.
Internet is a huge network which can be accessed by various users throughout the world. They can use different platforms(or operating systems) which may cause problems like a web page designed for windows may not work with Linux.
Therefore to get rid of this problem java is used to design the internet which is
platform independent.
That is why, net and java are almost same but none is better although net has
got some additional features like flash,etc. with time.
When does Garbage collection occur in java?
No one can force garbage collector to free memory, A java object is subjected to garbage collection when it can not be reached by the program in which it is being used. Programmer can request for garbage collection by System.gc() but JVM doesn't guarantee that is will start immediately
Actually, the specific method for GC and how it will be run is dependent on the JVM implementation being used.
For instance, Sun (now Oracle)'s Hotspot JVM has several different GC designs, one of which (the RealTime engine) can be immediately triggered via a System.gc() call. Each type of GC will have different triggers and thresholds as to when it will be run, which allows the user to pick the GC option that they think will be least disruptive and most effective for their particular application.
You must read the JVM documentation for your particular VM to see what available GC options there are, how each GC method works, and what the various thresholds are.
What is parameter constructor?
C++ permits us to achieve this objects bt passing argument to the constructor function when the object are created . The constructor that can take arguments are called parametrized constructors
Example:-
class abc
{
int m,n;
public:
abc(int x,int y); //paramererise constructor
................
.................
};
abc::abc(int x,int y)
{
m=x;n=y;
}
What is the time complexity for searching an element in an array?
If the array is unsorted, the complexity is O(n) for the worst case. Otherwise O(log n) using binary search.
How do object oriented design and structure design differ?
Object Oriented programming is a superset of structured programming. Structured programming is as follows:
--Program start
var
var
var
function { ... }
function { ... }
function { ... }
main { ... }
--- Program End
You have units of code, which operate on variables, and are called in reference to those variables, to follow a structure acting on those variables.
Object oriented is as follows:
--- Program Start
object {
var
var
function { ... }
function { ... }
function { ... }
}
var
var
function { ... }
main { ... }
--- Program end
Variables can be objects, which have their own data and functions. Think like C and structures, except structures can have functions "in them" which operate specificly on their own data. Thus, instead of referencing a function (a block of code) and telling it to operate on a variableq you reference an object and tell it to perform an operation, most often on itself, specific to itself, using its own data. Instead of creating units of data to pass to functions which operate on them, you create objects and have them perform operations [on themselves].
Functions attached to objects don't need a specific name; rather than task_struct_sort_children(task) and acl_rules_struct_sort_children(task), you can have task and acl_rules with task->sort_children() and acl_rules->sort_children(), which have completely different specific function but the same logical function, and operate on the specific instance of the object.
structured oriented programming and object oriented programming have some features of similarities, but the distinction between the two is that the former relies to the GOTO statements thus the developer has a tendency to confuse while the latter is subgrouped from objects, classes, methods and hierarchies.
What is the meaning of java void keyword?
The void keyword is used to show that a method will not return a value.
// no return type
public void setX(int x) {
this.x = x;
}
// returns an int
public int getX() {
return x;
}
What is the benefit using Encapsulation?
Encapsulation allows programmers to separate interface from implementation, thus creating a better overall design, where each module is individually simpler and doesn't need to know about the other modules. See related links as well.
What is a value that is passed into a method when it is called?
Here is an example program that passes a Scanner object:
import java.util.*;
public class Conversion
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
doSomething(in);
}
public static void doSomething(Scanner in)
{
int q = in.nextInt();
System.out.println("The value you entered is: " + q);
}
}
How exception handling mechanism can be used for debugging a program in java?
Trapping and handling of runtime errors is one of the most crucial taska ahead of any programmer. AS A DEVELOPER, YOU SOMETIMES SEEM TO SPEND MORE TIME CHECKING FOR ERRORS AND HANDLING THEM THEN YOU DO ON THE CORE LOGIC OF THE ACTUAL PROGRAM.
Who makes java platform independent?
JVM makes Java Platform Independent..
It loads byte code(.class file) and Run it.