Does Every class has a toString method and an equals method inherited from the Object class?
Yes - in Java, every class has this method, which is inherited from the Object class. Often, the inherited method does nothing particularly useful, but you can override it with your own implementation.
Why java is a strictly type language?
C is not a strongly-typed language, it is weakly-typed. This means that it is possible to work around the type system. That is, types can be explicitly or implicitly converted to other types. A strongly-typed language simply wouldn't allow this. However, C is statically-typed, which means that values are bound to types at compile time, rather than at runtime as they are in dynamically-typed languages.
select customer.customer_num, customer_name from customer, orders where orders.order_date in ('23-OCT-10');
What is the implication of catching all the exceptions with the type Exception?
though catching exceptions is a good practice inside java code, catching all exceptions of the type exception is not the best way to go. Specific exceptions need to be caught instead of the generic Exception being caught. Also, different types of exceptions need to be handled separately.
C code to implement the the first fit best fit worst fit algorithm?
#include<stdio.h>
#include<malloc.h>
/*
filename:firstfit.c
description:this program implements first fit algorithm
Author:Anupam Biswas,NIT Allahabad,India
Date:29.08.2011
*/
#define maxp 10 //maxp:maximum no of processes
#define maxmsz 100 //maxmsz:maximum memory size
struct memory{
int bsz;//bsz:block size
int bs;//bs:block start
int be;//be:block end
int ap;//ap:allocated process
int flag;//for allocated or not
struct memory*link;
}*start,*trav,*prev;
int pq[maxp];//pq:process queue
int f=-1,r=-1;
void enqueue(int ps)
{
/*ps:process size*/
if((r+1)%maxp==f)
{
printf("\nqueue is full, no new process can be loaded");
}
else
{
r=(r+1)%maxp;
pq[r]=ps;
}
}
int dequeue()
{
int ps;
if(f==r)
{
printf("queue empty,no process left\n");
return -1;
}
else
{
f=(f+1)%maxp;
ps=pq[f];
return ps;
}
}
void first_fit(int ps,int pid)
{
/*pid:process id*/
struct memory*block;
block=(struct memory*)malloc(sizeof(struct memory));
trav=start;
/*search the memory block large enough*/
while(trav!=NULL)
{
if(trav->flag==0 && trav->bsz>=ps)
{
break;
}
prev=trav;
trav=trav->link;
}
if(trav==NULL)
{
printf("No large enough block is found\n");
}
else /*if enough memory is found*/
{
dequeue();//remove process from queue
block->bsz=ps;
block->bs=trav->bs;
block->be=trav->bs+ps-1; //anus size defininition
block->ap=pid;
block->flag=1;
block->link=trav;
trav->bsz=trav->bsz-ps;
trav->bs=block->be+1;
if(trav==start)/*if first block is large enough*/
{
start=block;
}
else
{
prev->link=block;
}
}
}
void dealocate_memory(int pid)
{
trav=start;
while(trav!=NULL && trav->ap!=pid)
{
trav=trav->link;
}
if(trav==NULL)
{
printf("This process is not in memory at all\n");
}
else
{
if(trav->link->flag==0)
{
trav->bsz=trav->bsz+trav->link->bsz; //anus link definition
trav->be=trav->link->be;
prev=trav->link;
trav->link=prev->link;
prev->link=NULL;
free(prev);
}
trav->ap=-1;
trav->flag=0;
}
}
void show_mem_status()
{
int c=1,free=0,aloc=0;
trav=start;
printf("Memory Status is::\n");
printf("Block BSZ BS BE Flag process\n");
while(trav!=NULL)
{
printf("%d %d %d %d %d %d\n",c++,trav->bsz,trav->bs,trav->be,trav->flag,trav->ap);
if(trav->flag==0)
{
free=free+trav->bsz;
}
else
{
aloc=aloc+trav->bsz;
}
trav=trav->link;
}
printf("Free memory= %d\n",free);
printf("Allocated memory= %d\n",aloc);
}
int main()
{
int ch,ps;
char cc;
/*the size of the total memory size is defined i.e. largest block or hole*/
/*......................................................................*/
start=(struct memory*)malloc(sizeof(struct memory));
start->bsz=maxmsz;
start->bs=0;
start->be=maxmsz;
start->ap=-1;
start->flag=0;
start->link=NULL;
/*......................................................................*/
while(1)
{
printf("\n\t1. Enter process in queue\n");
printf("\t2. Allocate memory to process from queue\n");
printf("\t3. Show memory staus\n");
printf("\t4. Deallocate memory of processor\n");
printf("\t5. Exit\n");
printf("Enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
do
{
printf("Enter the size of the process: ");
scanf("%d",&ps);
enqueue(ps);
printf("Do you want to enter another process(y/n)?: ");
scanf("%c",&cc);
scanf("%c",&cc);
}
while(cc=='y');
break;
case 2:
do
{
ps=pq[f+1];
if(ps!=-1)
{
first_fit(ps,f+1);
show_mem_status();
}
printf("Do you want to allocate mem to another process(y/n)?: ");
scanf("%c",&cc);
scanf("%c",&cc);
}
while(cc=='y');
break;
case 3:
show_mem_status();
break;
case 4:
do
{
printf("Enter the process Id: ");
scanf("%d",&ps);
dealocate_memory(ps);
show_mem_status();
printf("Do you want to enter another process(y/n)?: ");
scanf("%c",&cc);
scanf("%c",&cc);
}
while(cc=='y');
break;
case 5:
break;
default:
printf("\nEnter valid choice!!\n");
}
if(ch==5)
break;
}
}
Write a program to demonstrate constructor overloading?
Constructor overloading is similar to method overloading. You can overload constructors by changing the parameter list in the class definition.
Here is an example
public class Box{
private int height;
private int width;
private int breadth;
// First constructor with no parameters
Box(){
height = 0;
width = 0;
breadth = 0;
}
// This is the second overloaded constructor
Box(int h,int w,int b){
height = h;
width = w;
breadth = h;
}
public void display(){
System.out.println("Height: "+height+" Width: "+width+" Breadth: "+breadth);
}
public static void main(String args[]){
Box obj = new Box(1,2,3);
obj.display();
}
}
How do you resolve name-space collision?
Import only one of the packages containing the classes with the same name. Use the other class by typing out its full namespace.
How do you do write an annotation?
You take the document you are annotating and add your own notes that further explain the document using critical thinking.
What is contain inside the jar file?
.jar files contain byte-code compiled to run on the Java Virtual Machine.
How do you find the HCF of all the numbers in an array java?
I guess you mean the highest common factor. Use a loop. Start assuming that the hcf is the first number in the array. Call this "result". Find the hcf of "result" and the second element, assign this to "result". Find the hcf of "result" and the third element, and copy this back to result, etc.
When does an object get destroyed in programming?
I agree with @Hilmar. You can never predict when exactly the object will be destroyed. But, you can definitely predict when an object is ready to be destroyed.
Difference between the two can be easily explained using an example (I'm using JAVA here):
Employee emp = new Employee("Dexter");
This statement creates an object of Employee (with name Dexter) which resides in the heap.
As long as you are using the reference "emp" for this object , the object will stay there. Its indestructible. Garbage Collector cannot even touch it.
Now lets say, after a few lines of code, you are executing:
emp = new Employee("RITA");
This creates a new object of Employee (with name RITA), but notice that the reference "emp" no longer points to our old object with the name Dexter. Hence the object of Employee with the name Dexter has no references associated with it.
And this makes it eligible for the Garbage Collection, and whenever the next round of Garbage Collection happens, the mighty GarbageCollector will not leave this chance to eat up the Employee (with the name Dexter).
tough luck
What do you mean by procedure?
A procedure is a specified series of actions or operations which have to be executed in the same manner in order to always obtain the same result under the same circumstances (for example, emergency procedures). Less precisely speaking, this word can indicate a sequence of activities, tasks, steps, decisions, calculations and processes, that when undertaken in the sequence laid down produces the described result, product or outcome. A procedure usually induces a change. It is in the scientific method. So it is in Particular!
How many unique values can you assign in a 3 byte alphanumeric field?
There are 26 alphabetic characters (a-z) and 10 numeric (0-9) which together form 36 alphanumeric characters. If you include capital letters, then you have 62 (36 + 26) alphanumeric characters.
62 * 62 * 62 = 238,328
What method that returns string representation of the contents of the variable?
Since the question is in the Java category: in Java, the method is called toString(). This method will automatically be invoked if you implicitly convert an object to String type, for example:
"The answer is: " + myObject
In this example, the String concatenation (the plus sign) forces the object, myObject, to type String - to do this, the object's toString() method will be called.
#include
#include
using std::cout;
using std::cin;
using std::endl;
using std::string;
int main()
{
string myNumber = "";
cout << endl << "Enter a number: ";
cin >> myNumber;
cout << endl << "You number was saved as string: "" << myNumber << """ << endl;
system("PAUSE");
return 0;
}
What does this mean import com.otherwise.jurtle.?
The "import" statement in Java imports names from some other package into the current context. So, if there was a class called com.otherwise.jurtle.SomeClass, you would have to refer to it by the full name, unless you imported it.
The import can be done specifically for one class:
import com.otherwise.jurtle.SomeClass;
or for everything in a package:
import com.otherwise.jurtle.*;
In Java 5 and up, you can also import all the static functions from a class:
import static com.otherwise.jurtle.SomeClass.*;
The "com.otherwise.jurtle" part is called the package identifier. The general practice is for a company to reverse its domain name for this. So jurtle.otherwise.com becomes com.otherwise.jurtle.