# New state - After the creations of Thread instance the thread is in this state but before the start() method invocation. At this point, the thread is considered not alive.
# Runnable (Ready-to-run) state - A thread start its life from Runnable state. A thread first enters runnable state after the invoking of start() method but a thread can return to this state after either running, waiting, sleeping or coming back from blocked state also. On this state a thread is waiting for a turn on processor. # Running state - A thread is in running state that means the thread is currently executing. There are several ways to enter in Runnable state but there is only one way to enter in Running state: the scheduler select a thread from runnable pool.
# Dead state - A thread can be considered dead when its run() method completes. If any thread comes on this state that means it cannot ever run again. # Blocked - A thread can enter in this state because of waiting the resources that are hold by another thread.
OOPS refers to Object Oriented Programming Structure.
Some common terms used in oops are
# Inheritance # Polymorphism # Encapsulation # Data hiding etc..
Yes, since it can only play in some computers and not all computers can read it. Every Java application needs a minimum system configuration requirement which if not met, the machine will not be able to run Java.
Java the language itself is NOT machine dependent.
To run a program written in Java, it depends on an implementation of the Java Virtual Machine specification existing for a given machine/OS platform. Thus, a program written in Java can be run on any OS/machine platform for which a JVM has been created.
For the programming language Java why was that name chosen?
The Java Programming Language was originally named Oak because of an oak tree that stood outside one of the founders' office. It was then renamed to Green, and then renamed to Java because supposedly the creators of the Java Language consumed large amounts of Java coffee.
What is classpath and path in java?
if you are using the IDE then there is no need to set class path, ant you are using Command prompt to run the java program then you need to set the class path where the class (which is going to be used in your program) is actually located,
use the following command:
set calsspath=%classpath%;actual_path_of the class;
we can
call more than two class by using this command by using separator (,)
In Java are variables passing by values or by reference?
//********Shivram singh Rathour Lucknow Gpl************
call by reference or call by value in java?I am programming in Java for quite sometimes now, but I never got stuck with the problem I am facing now.
Suppose I send a list to a function like:
List list = new ArrayList<Integer>() //code 1 in some class say Class1
//assign some numbers to 'list'
Now if I call another class method:
methodCustom(list)
which is defined as
void methodCustom(List list1) //code 2 in another class say Class2
then changing list1 in methodCustom i.e in code 2 of class 2 changes list from code1 of class 1. Weird!! I cant really understand what is happening. So I guess it is sending the reference.. M I correct? if so then what should I do if I only want to send the values? is there anything like deep copying and shallow copying?
kindly give me what is best way to send the array by value.
Along with this how can I get sublist from a list with separate pointers, I dont want my original list to be changed if I change the sublist.
So what is happening here in these cases?
Case1: List sl2 = list.subList(10,20);
Case2: List sl2 = new ArrayList<Integer>(list.subList(10,20));
Case3: List sl2 = new ArrayList(list.subList(10,20));
so can I copy array like:
for using it as call by value:
list=new ArrayList<Integer>(listPrev):
for using call by reference:
list=listPrev;
??
How can you sort an arraylist of strings?
You can sort an ArrayList by using the sort method of the Collecions class (java.util.Collections). Assuming you have an ArrayList called foo: Collections.sort(foo);
What is meant by the term encapsulation as it is used in Object Oriented Analysis?
Encapsulation conceals the functional details of a class from objects that send messages to it.
For example, the Dog class has a bark() method. The code for the bark() method defines exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and volume). Timmy, Lassie's friend, however, does not need to know exactly how she barks. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface - those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in future, thereby allowing those changes to be made more easily, that is, without changes to clients. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected or private, determining whether they are available to all classes, sub-classes or only the defining class. Some languages go further: Java uses the default access modifier to restrict access also to classes in the same package, C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow one to specify which classes may access any member.
When do you declare a member of a class static?
Static members should be used whenever you have a member that is logically considered part of the class, but is not associated with any instance of the class. They are bit like global variables and functions but there's more control over their visibility outside of the class.
Static member methods can be thought of as being global functions that are scoped to the class (rather than to each instance of the class). As such, they do not inherit an implicit this pointer and can therefore be called without instantiating an instance of the class (access specifier permitting). However, any and all instances of the class have unrestricted access to all the static member methods of the class.
Static member variables can be thought of as being global variables that are scoped to the class (rather than to each instance of the class). That is, all instances of the class share the same set of static member variables amongst them, rather than each having their own (as they would with non-static member variables). Static member variables are also accessible to static member functions. As with all other static variables, they are initialised at compile time (which must be done outside of the class declaration), and will remain in scope for the entire lifetime of the program.
All static members are subject to the public, protected or private access specifiers, so while they can act like global variables and functions if declared public, their visibility outside of the class can be limited to private or protected access.
Possible uses for static members are many and varied. By way of an example, suppose you want to maintain a read-only count of all instances of a class. The following framework demonstrates how this can be done with static members:
class Object
{
public:
Object(){++s_instances;}
~Object(){--s_instances;}
static unsigned int GetInstances(){return(s_instances);}
private:
static unsigned int s_instances;
};
// Static member variable initialiser (evaluated at compile time):
unsigned int Object::s_instances=0;
int main()
{
cout<<"Current instances:\t"< Object * p1 = new Object(); cout<<"Current instances:\t"< Object * p2 = new Object(); cout<<"Current instances:\t"< delete( p1 ); cout<<"Current instances:\t"< delete( p2 ); cout<<"Current instances:\t"< } Output: Current instances: 0 Current instances: 1 Current instances: 2 Current instances: 1 Current instances: 0 In the code, if you want to have only one instance of the member variable irrespective of the number of objects created for that class. In these kind of scenarios static members are used
What do you mean by static modifier in java?
The static keyword associated with a method or a variable in java specifies that the entity belongs to the class and not any object instance of the same.
Static Methods
Static keyword when used with a method, specifies that this method belongs to the class and not a particular instance of the class (a.k.a object of the class)
Ex:
public class StaticTest {
public static String getAuthorName() {
return "Anand";
}
}
Here getAuthorName is the static method and it can be accessed without instantiating an object of the class StaticTest. You can access this method as:
String authorName = StaticTest.getAuthorName();
Static Variables
The static modifier tells the system that this particular variable belongs to the class and does not belong to any specific instance of the same. The class will contain only one instance of the static variable irrespective of how many objects of the class you create.
Write a program to print n natural numbers using do-while loop?
//(this is just a function, call this as count(n) in your main loop)
void count(int n){
int i = 1;
do{
printf("%d", i);
i++;
} while(i<=n);
}
Which methods are there in ActionListener interface?
The ActionListener interface has a single method.
void actionPerformed(ActionEvent e) For full Java documentation see Oracle JavaDoc URL in related links below.
What is basic of arrays in java?
the different types of arrays are single dimensional, two dimensional and multidimensional arrays..
they can be declared in java as follows
1)for single dimensional:
int x[]=new int[5];
2)for 2-d array:
int x[][]=new int[5][4];
3)for multidimensional array:
combination of both 1 and 2nd declaration is allowed..
What is need and characteristics of oop?
OOP stands for Object oriented programming.
The main characteristics of OOP are
1. Class
2. Objects
3. Instance
4. Methods
5. Message Passing
6. Inheritance
7. Abstraction
8. Encapsulation
9. Polymorphism &
10. Decoupling
OOP is a concept that allows us to have a program that is
1. "robust and secure".
2. "architecture neutral and portable".
3. "high performance".
Why do file name and public class name always coincide in Java?
First of all, it only has to be the same when the class is public. And there is no explicit reason for that, it's just a convention that came along with old versions of java and people got used to it... They say it's because of the limited capabilities of the compiler to compile dependencies. When packages are stored in a file system (?7.2.1), the host system may choose to enforce the restriction that it is a compile-time error if a type is not found in a file under a name composed of the type name plus an extension (such as .java or .jav) if either of the following is true: * The type is referred to by code in other compilation units of the package in which the type is declared. * The type is declared public (and therefore is potentially accessible from code in other packages). This restriction implies that there must be at most one such type per compilation unit. This restriction makes it easy for a compiler for the Java programming language or an implementation of the Java virtual machine to find a named class within a package; for example, the source code for a public type wet.sprocket.Toad would be found in a file Toad.java in the directory wet/sprocket, and the corresponding object code would be found in the file Toad.class in the same directory. When packages are stored in a database (?7.2.2), the host system must not impose such restrictions. In practice, many programmers choose to put each class or interface type in its own compilation unit, whether or not it is public or is referred to by code in other compilation units. It is not mandatory to say "file name equals to classname". > U can give your own name to your filename [ other than classname ] > at the time of compilation you just give your filename[other than classname] > After compilation you will get .class file with your class name.[classname.class] >.But at the time of loading ur program into JVM u just have to give the class name , This is possible even the main() is public/private. for eg:-consider have created a program in java with file name Ashish n class name is batra,now at the time of compilation u have to write "javac ashish.java" at the command prompt and at the same time the jvm create the .class object in the bin directory with filename =batra(batra.class) .Now at the time of running the program u have to write "java batra" at the command prompt. We say this statment that the file name should be same as the class name to make sure there is no confusion while compiling n running the program .Consider u have created many programs in java and now u want to run any one of them ,then it would be very difficult for u to recall the class name of that particular program .So to make it a simpler we offenly say that the class name should be same as the file name.
In Java what is hybrid inheritance?
Java does not support the ability for one class to extend more than one other class. However, Java does allow for one class to implement any number of interfaces.
Let us consider the below example for hybrid inheritance.
public class A extends C implements D, E {
}
Here A extends C which is direct single inheritance, By implementing D & E we are trying to achieve multiple inheritance to the limit that Java allows us. And if C in turn has extended some other class then we have multi level inheritance as well.
This can be termed as Hybrid inheritance. The presence of more than one form of inheritance.
Program to check the presence of a substring in a given string?
#include<stdio.h>
#include<string.h>
main()
{
char a[24];
int i,count=0,j=0,stlen,k,substlen,sig=0;
gets(a);
for(i=0;i<strlen(a);i++)
{if(a[i]==' ')
break;
else j++;}
stlen=j;
substlen=strlen(a)-j-1;
for(i=0;i<=stlen-substlen;i++)
{count=0;
for(k=i+substlen-1;k>=i;k--)
{if(a[k]!=a[k+stlen-i+1])
break;
else count++;}
if(count==substlen)
{sig=1;
break;
}
}
printf("%d",sig);
}
input-
11100101 1001
110010 111
output-
1
0
note -give the main string and the substring(to be checked) seperated by a space.
Program to find a raised to the power b by using recursion in java?
//with a function:
int exponent(int a, int b){
int returnValue;
if (x==0) return 1;
else return(a*exponent(a,x-1));
}
main(){
printf("%d\n", exponent(1, 1));
}
Why java is called write once and run anywhere?
Write once run anywhere: Java is a programming language which has its own virtual machine. When you write a program using the Java language you can use it on any operating system which has Java installed. This is different to previous programs and programming languages as they were written for individual operating systems and needed to be re-written for a different operating system. For example, a while ago on mobiles, all we had was "nokia games" "sony-ericson games" "motorola games" etc.. but now we have "java games" which can run on any mobile as long as the mobile has java installed... It's clever and very handy!
if you have tried to mod it then the mod will be faulty or you might not of installed it right or you haven't downloaded the right modding tools (e.g. Modloader). If you haven't Tried to mod it then a file is missing and you need to delete it then reinstall it.
What is difference between structural language and object oriented language?
I think there is no any difference between object oriented programming language. Because somebody have written that vb is object based language because there is no inheritance, but javascript has no classes and no inheritance but javascript is also object oriented scripting language and java is also object oriented language vb has no inheritance but classes is.So vb is object based language This is not clear that difference between object oriented and object based. if i am wrong than what should be your answer and if i am wright than no problem But first i am requesting to the developer of any programming language that please define the difference between object oriented and object based languages. Amit Sinha Dist-Gaya State-Bihar
What are the different programming languages?
There are literally thousands of programming languages - some for special purpuses, some of a more general nature. Some popular languages are the Microsoft dotnet languages (C#, Visual Basic .NET, and others); Java; PHP; Python; and lots of others. You can get more information:
* In the Wikipedia article on "programming language"
* The TIOBE website has been keeping track of the most "popular" programming languages, for the last few years.
List the eight basic data types used in java and give examples?
The 8 primitive data types are
byte, short, int, long, float, double, boolean and char
boolean is used to store logical values true/false
char is used to store single digit characters. 'Y', 'X' etc
the remaining data types are used to store a wide variety of numbers.
Difference between method and constructor in java?
A constructor is technically a type of method, but it is a very special type. Whereas other methods can be used to do just about anything, the only purpose of a constructor method is to create an instance of the class that contains it, often with parameters passed to it through another part of the program. This instance is called an "object" and is a central part of not only Java, but other object-oriented languages as well. A constructor method always has the same name as its containing class, and does not have a return type. Think of it this way: a class in Java is like a generic blueprint for a house. Your instance variables are like different attributes of the house - how many bathrooms will your house have, what colour will it be? Once you decide on the exact specifications for your house, you can give those parameters to the construction company, which will actually create that house. That's what a constructor method does - takes input parameters (or, lacking them, sets defaults) and creates an object.