Why can't we use a keyword as a variable name?
It is because, the keywords are defined in the java language for a specific purpose. If we start declaring variables with the same name, the compiler would not know if you are trying to use a variable are trying to tell it to perform an action and hence keywords cannot be used as a variable name.
Volatile variables are variables that may change value while they are being operated upon. For instance, a hardware clock is constantly updated by the operating system, thus its value is constantly changing. If you refer to the value, you must declare it volatile because the value is outwith the control of the program.
How is java both a programming language and a platform?
By using Navite Interface we write this type of code
Constructors in java cannot be invoked explicitly. They are invoked automatically when an object is created. In java if u dont write any code for constructor, by default compiler inserts a zero argument constructor. If required, it can be overrided.
Write a program sort a list of names in alphabetical order in java programming language?
// Let's assume we're sorting the characters in String toSort
// convert the String to an array of characters
char[] chars = toSort.toCharArray();
// let Java do the sorting for you
Arrays.sort(chars);
// recreate the original String with the newly sorted array of characters
toSort = new String(chars);
How do you write a java program to print numbers that have number nine up to 100?
public class Divisible {
int num;
int sum;
public void calculate() {
sum=0;
System.out.println("Numbers divisible by 9:");
for(num=50;num<100;num++) {
if(num%9==0) {
System.out.println(num);
sum=sum+num;
}
}
System.out.println("Sum: "+sum);
}
public static void main(String a[]) {
Divisible obj=new Divisible();
obj.calculate();
}
}
for( int i = 54; i <= 100; i += 9 ) {
System.out.println(i);
}
}
Write a program to compare two strings?
Registers used: ax,ds,si,di,cl
flags affected: zf,cf
program:
assume cs:code,ds:data
code segment
mov ax,data
mov ds,ax
mov si,offset str1
mov di,offset str2
mov cl,count
cld
rep cmpsb
hlt
code ends
data segment
str1 db 04h,05h,07h,08h
count equ 04h
org 0010h
str2 db 04h,06h,07h,09h
data ends
end
result:
input: str1 (ds:0000h) = 04h,05h,07h,08h
str2 (ds:0010h) = 04h,06h,07h,09h
I like to think it's because of the connection to "Java man" (Pithecanthropus erectus): it's primitive and an evolutionary dead end.
However, the official story is that the programmers drank a lot of coffee while creating it.
What is the difference between the printf and the println statement in java?
The println method outputs a newline character after the arguments you pass to it. The code for println basically looks like:
public void println(String x) {
print(x);
newLine();
}
How would you describe the fetch execute cycle?
Fetch Execute Cycle
A more complete form of the Instruction Fetch Execute Cycle can be broken
down into the following steps:
1. Fetch Cycle
2. Decode Cycle
3. Execute Cycle
4. Interrupt Cycle
1. Fetch Cycle
The fetch cycle begins with retrieving the address stored in the Program
Counter (PC). The address stored in the PC is some valid address in the
memory holding the instruction to be executed. (In case this address does
not exist we would end up causing an interrupt or exception).The Central
Processing Unit completes this step by fetching the instruction stored at
this address from the memory and transferring this instruction to a special
register - Instruction Register (IR) to hold the instruction to be executed.
The program counter is incremented to point to the next address from
which the new instruction is to be fetched.
2. Decode Cycle
The decode cycle is used for interpreting the instruction that was fetched in the Fetch Cycle. The operands are retrieved from the addresses if the need be.
3. Execute Cycle
This cycle as the name suggests, simply executes the instruction that was fetched and decoded
What is mean constructor in java?
A parameterized constructor in java is just a constructor which take some kind of parameter (variable) when is invoked. For example.
class MyClass {
//this is a normal constructor
public MyClass(){
//do something
}
//this is a parameterized constructor
public MyClass(int var){
//do something
}
//this is another parameterized constructor
public MyClass(String var, Integer var2){
//do something
}
}
What are accessors and mutator method in java?
An accessor is a method that accesses the contents of an object but does not modify that object. In the simplest case, an accessor just returns the value of one of the fields. In general, an accessor performs some computation using the fields as long as that computation does not modify any of the fields. Mutators
A mutator is a method that can modify an object. In the simplest case, a mutator just assigns a new value to one of the fields. In general, a mutator performs some computation and modifies any number of fields. Sometimes, accessors are called 'getter' methods and mutators are called 'setter' methods.
Discuss features of Java Language?
# interpreted and compiled
# simple # robust and secure # platform independent and portable # multithreaded and interactive# object oriented # dynamic and extensible
What is inheritance how does it help us create new classes?
Inheritance is the java feature by which the functionality of a parent class is inherited by the child class.
Inheritance does not help create new classes instead it avoids creation of duplicate classes. We can re-use classes using Inheritance.
What programming language does YouTube use?
If your are thinking of youtube it uses a variety of languages. It defiantly uses flash and JavaScript for its front end and some sort of SQL for its data base. It uses several other languages too but those listed above are the only ones I am sure of.
The term keywords in Search Engine Optimization (SEO) refers to the most important words or group of words in your website content. Keywords play an essential role in the SEO process because search crawlers use them to index your website. Thus, it is essential you understand how to leverage your website keywords for your SEO process to be a success.
The "this" keyword is simply a reference to the current object. If, for example, you wanted to add the object you're currently working in to a collection you would want to do something like:
// Collection c;
c.add(this); ---------------------------------------------------
actually,there are 3 uses of 'this' keyword: 1. to refer to the address of the object under consideration. 2. to avoid name space collision. 3. to call a constructor within another constructor.
Which programming language developed JAVA?
the softwares like .net and java, both are in peak now. Each of these software is very useful for develop the software. the softwares like .net and java, both are in peak now. Each of these software is very useful for develop the software.
Write a Java program to find occurrences of given word in a text?
/*this block of code fineds any given string in tree different file
displays the string and prints the number of occurences in these file....thats all:)*/
package useToken;
import java.io.*;
class readFile extends StreamTokenizer {
readFile(InputStream in ){
super(in);
}
public static void main (String argv[]){
try {
int ret;
String string;
BufferedReader in =
new BufferedReader (newInputStreamReader(System.in));
System.out.print("Enter some text: ");
string = in.readLine();
String[] file = {"file1.txt","file2.txt","file3.txt"};
for(int i=0;i<3;i++){
FileInputStream fin = new FileInputStream(file[i]);
readFile rt = new readFile(fin);
int counter =0;
while((ret = rt.nextToken())!= 0 && rt.sval != null){
if(rt.sval.equals(string)){
System.out.println("Found Text :" + rt.sval );
counter++;
}
}
System.out.println("The String Found :" + counter + " " + "times");
System.out.println(file[i] + " " + "Complete");
}
} catch (Exception e ){
System.err.println("Exception :" + e);
}
}
}
Write a program to find the frequency of words in a sentence in java programing?
//program to find occurence of a word in a sentence
import java.io.*;
public class cnt2
{
public static void main(String args[])throws IOException
{
int times=0,count=0,x=0,no=0;
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
String s,w;
System.out.println("Enter the sentence:");
s=br.readLine();
System.out.println("Enter the word:");
w=br.readLine();
try{
for(int i=0;i { if(w.charAt(0)==s.charAt(i)) { for(int j=0;j { if(s.charAt(i)==w.charAt(j)) { count=count+1;} if(count==w.length()) {no=no+1;count=0;}; } } } catch(Exception e){} if(no==0) { System.out.println("word is not present"); } else { System.out.println("word is present "+no+" times"); } } }
Write a program to check whether a given number is in array or not?
/**
* Searches for the number n in ns.
*
* Note: Will always return false if the Number type of n is different from ns.
* For example, if n is an Integer and ns is an array of Long objects, then
* contains will always return false. This can be circumvented with some
* generics hacking, but this results in overly-ugly code.
*
* @return true iff n is an element of ns
*/
private static final boolean contains(final Number n, final Number[] ns) {
for(int i = 0; i < ns.length; ++i) {
if(ns[i] == n) {
return true;
}
}
return false;
}
Where do you find instances in World of Warcraft?
Instances in WoW are all over the place. Theres one in the Barrens near Thunderbluff, theres one in Westfall, one in Dun Morogh, theres one actually inside a Capital city: Stormwind City. So.... Just look around cause the instances are all over the place.
Why in copy constructor in c you use pass by reference?
Because if it's not by reference, it's by value. To do that you make a copy, and to do that you call the copy constructor. But to do that, we need to make a new value, so we call the copy constructor, and so on...
(You would have infinite recursion because "to make a copy, you need to make a copy".)
The difference between Real data type and integer data type?
An integer data type is any type of number without a fractional part.
Signed vs unsigned of any data type refers to whether or not that data type can store negative numbers (numbers with a negative sign). The typical way to store the sign information for a number is to reserve one bit of information to do so.
For a signed 32-bit integer (a common integer size), this means that there are 31 bits available to hold information about the value of the number and 1 bit reserved for signifying negatives. This means that the range of data for a 32-bit signed integer is [-2147483648, 2147483647].
If you use an unsigned 32-bit integer, you can use that extra bit to store more positive number values. The range of data for a 32-bit unsigned integer is [0, 4294967295].
in short law FOR n bits
signed rang[-2n-1 -------- 2n-1 -1]
unsigned rang [0----------2n-1]
C doesn't have interfaces like Java does. In fact, it doesn't even have classes. The closes thing it has to interfaces might be a pointer to a function, which could point to one of several different functions without the caller having to know which one exactly. C does not have interfaces or classes. However it's quite easy to simulate interfaces and classes in C. Before I get into doing that, let me explain what interfaces are and how it's done in C++, which supports multiple inheritance which is much more powerful then interface inheritance.
Interface inheritance is basically the same thing as multiple inheritance. In interface inheritance, the interfaces are classes that cannot have method implementations and variables. They may only have function prototypes. You are only allowed to inherit from one full blown class as a child in the interface inheritance model.
However, in multiple inheritance (which C++ supports), you're allowed to inherit from as many full classes as you want. This allows you to make those full blown classes as slim as a bunch of pure virtual functions (interface) or as full classes with method implementations and variables. For example, to implement something similar to a comparable interface in C++:
class Comparable
{
public:
virtual int compareTo(void* x) = 0;
};
class Foobar: public Comparable
{
public:
virtual int compareTo(void* x) { /*compare implementation here */ }
//rest of class
};
That would be pretty much the same thing as interface inheritance in Java. Any function that takes a Comparable pointer or reference will also be able to take Foobar. In C, you'd have to use function pointers to achieve the same effect. Basically in your structure, you'd have to have a pseudo v-table... a bunch of function pointers:
struct Comparable
{
int (*compareTo)(void* x) = 0;
};
struct Foobar
{
int (*compareTo)(void* x);
//rest of structure
int i;
int j;
int k;
};
void InitFoobar(struct Foobar* this)
{
this->compareTo = /*compare to function*/;
//rest of the initialization
this->i = 0;
this->j = 1;
this->k = 2;
}
If you want to pass Foobar into a function that takes a Comparable pointer, just cast the Foobar pointer to a Comparable pointer. The C standard guarantees structures Comparable and Foobar will be laid out exactly the same as long as the variables are declared in the same order. So the first 4 bytes, the function pointer, will be at the exact same offsets in both Comparable and Foobar. However, after the first 4 bytes, Foobar will have extra 12 bytes of stuff where Comparable will not. This memory arrangement lets you treat Foobar exactly like a Comparable. This is also how single inheritance is normally implemented in most languages.
What does a class specify about an object?
Object is an instance of a class.
Example: In general, animal is a class where as, tiger is an object.