Example of multilevel inheritance program in java having HAS-A relation?
Just create a class that has two fields of object type. For example, to store data about a person, you might store a name (String object) and a birth date (Date or Calendar object).
What do you mean by a static function?
In Java, a static function is not attached to a particular object, but rather to the whole class.
For example, say we have the following class:
class Song {
String song;
void printSong() {
System.out.println(song);
}
static void printStaticSong() {
System.out.println("This is a static song. It has no tune.");
}
}
The static function Song.printStaticSong() can be accessed without creating an instance of the Song class (using the "new" keyword)
However it cannot access the members of Song (such as song), since it is not an instance of that object.
yes, use for loop;;
an arrow loop is a slit or hole used to shoot arrows through.
Static method can use only static variable why?
A static method is a method that is a class method and is not attached to the object of that class. So if we use a non static variable of the class, it would most probably not have been initialized because no object could have been created for the class. Hence it would throw a null pointer exception.
To avoid such an ambiguity, there is a restriction that static methods can use only static variables. This is to ensure that class methods can access only class variables both of which would get initialized simultaneously.
What is the algorithm using c to delete duplicate elements from an array?
To detect the duplicate, you will have to write a nested loop that compares each element with all the previous elements.
To actually delete the duplicate, once you find it, you have to move over all the elements after the duplicate. If the order of the elements doesn't matter, it is faster to just move the LAST array element, overwriting the duplicate element. Use a variable to keep track how many elements of the array are "usable". For example, if your array had 10 elements, and you delete 1, the array size will still be 10... but (after moving the elements over) only 9 of those elements have useful information.
Bluej program-read a string and check if the given string is a palindrome?
import java.util.Scanner;
public class Palindrome{
public static void main(String[] args){
String front;
String back ="";
char[] failure;
String backwards;
Scanner input=new Scanner(System.in);
System.out.print("Enter a word: ");
front=input.next();
front=front.replaceAll(" ", "");
failure=front.toCharArray();
for (int i=0; i<failure.length; i++){
back=failure[i] + back;
}
if (front.equals(back)){
System.out.print("That word is a palindrome");
}else
System.out.print("That word is not a palindrome");
}}
Give you an example of each type of Exception in Java through programs?
// A method which throws an exception.
// Declare an ArithmeticException to be thrown.
int integerDivision(int a, int b) throws ArithmeticException {
// If we try to divide by zero, throw our exception...
if(b == 0) {
throw new ArithmeticException("Division by 0");
}
// ...otherwise, return our result.
return a/b;
}
// A method which catches an exception.
void doSomeDivision() {
// Let's divide each integer [0,9] by one another...
for(int a = 0; a < 10; ++a) {
for(int b = 0; b < 10; ++b) {
// Try to do the division...
try {
final int q = integerDivision(a,b);
System.out.println(a + " / " + b + " = " + q);
} catch(ArithmeticException ex) {
// ...end up here in case of Exception
System.out.println("Cannot divide " + a + " by " + b);
}
}
}
}
Replace a character by another character in a given string?
To replace a single, specified character with another in a given string, one possibility is ...
char *pszString; /* pointer to string */
int offset; /* offset of desired character */
... initialize pszString and offset
*(pszString+offset) = 'A'; /* or whatever new value you want */
Obviously, this is a simple example, and it does not consider if offset is greater than the size of the array.
If you want to replace every occurence of a character with another, here is another possibility, one that also handles string length ...
char *pszString; /* pointer to string */
char* pszTemp; /* temporary scanning pointer */
char cOldChar; /* character to change */
char cNewChar; /* new character */
... initialize pszString, cOldChar, and cNewChar
for (pszTemp = pszString; *pszTemp != '\0'; pszTemp++) { /* scan */
if (*pszTemp == cOldChar) *pszTemp = cNewChar; /* conditionally replace */
}
Java Solution// Replace all 'e' characters with 'i' characters in String str
str.replaceAll("e", "i");
Java code to implement the the first fit algorithm?
import java.util.*;
class Partition
{
private int partstart;
private int partend;
private int partsize;
private int prosssize;
private int pid;
//private int intfrag;
private boolean empty;
private Partition next;
Partition Head=null;
public void createDynamicPartitions(int totmem)
{
Partition p=new Partition();
p.partsize=totmem;
//p.prosssize=0;
p.pid=-1;
//p.intfrag=0;
p.empty=true;
p.next=null;
p.partstart=0;
p.partend=totmem-1;
Head=p;
memStatus();
}
private Partition selectFirstHole(int prsize)
{
Partition temp=Head,first=null;
while(temp != null)
{
if (temp.empty && temp.partsize >= prsize)
{
break;
}
temp=temp.next;
}
return first;
}
public void loadProcess(int pid,int prsize)
{
Partition hole=selectFirstHole(prsize);
if(hole null)
System.out.println("There is no Process with ID :"+dpid);
else
memStatus();
}
private void memStatus()
{
Partition temp=Head;
System.out.println("Current Memory Status");
// int totfrag=0;
while(temp != null)
{
if(temp.empty)
System.out.println(temp.partstart+"-"+temp.partend+" : is hole of size "+temp.partsize);
else
System.out.println(temp.partstart+"-"+temp.partend+" :Memory with Process ID "+temp.pid+" of size "+temp.partsize);
//totfrag=totfrag+temp.intfrag;
temp=temp.next;
}
//System.out.println("\n Total Internal Fragmentation : "+totfrag);
}
}
public class FirstFit
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Total Memory size :");
int totmem=sc.nextInt();
//System.out.println("Enter number of partitions :");
//int numofpartions=sc.nextInt();
//creating partitions
Partition dp=new Partition();
dp.createDynamicPartitions(totmem);
while(true)
{
System.out.println("Menu");
System.out.println("1.Load Process");
System.out.println("2.Remove Process");
System.out.println("3.Exit");
System.out.println("Enter ur Choice : ");
int ch=sc.nextInt();
switch(ch)
{
case 1:
System.out.println("Enetr Process ID : ");
int pid=sc.nextInt();
System.out.println("Enetr Process size : ");
int prsize=sc.nextInt();
dp.loadProcess(pid,prsize);
break;
case 2:
System.out.println("Enetr Process ID : ");
int dpid=sc.nextInt();
dp.removeProcess(dpid);
break;
case 3:
System.exit(0);
//break;
default:
System.out.println("*** Wrong Choice ***\n Choice must be in b/w 1- 3");
}
}
}
}
What is token List out various type of token support in java?
Tokens are the smallest unit of Program.
There is Five Types of Tokens
1) Reserve Word or Keywords
2) Identifier
3) Literals
4) Operators
5) Separators
Why do we need a Session?
When one page needs to share information with another, the scope of the data broadens beyond processing a single request. This is because, when a response gets committed, all the data that was held in the request that generated that response is destroyed. So, if you want that data in another page, you will be looking at a blank request object with no data in it. When such a need arises, you must send the data from one page to the server and from the server to the next requested page, whether it be the same page or another page altogether. There are several ways to share state information between requests. However, the primary or the easiest way is to use sessions.
How Do Sessions Work?
The container generates a session ID. When you create a session, the server saves the session ID on the client's machine as a cookie. If cookies are turned off then it appends the ID in the URL. On the server, whatever you add to the session object gets placed in server memory-very resource intensive. The server associates that object in memory with the session ID. When the user sends a new request, the session ID is sent too. The server can then match the objects in its memory with that session ID. This is how we maintain client state.
What are 5 equivalent fractions for 1.10?
Equivalent fractions can be formed by multiplying (or dividing) the numerator and denominator by the same value.
1/2 x (2/2) =2/4
1/2 x (3/3) =3/6
other equivalent fractions such as 4/8, 5/10, and 6/12 can be obtained by the same process involving multiplication by 4, 5,and 6 respectively.
Which accepts an integer array of size n and prints every third value of the array?
You can loop through the array, and print out every third element. If the index used for looping is called "i", you can test whether "i" is a multiple of three (i % 3 == 0).
Or, and perhaps more efficiently, you can increase the index 3 at a time, for example:
for (i = 0; i <= theArray.length, i+=3)
{
...
}
Can you have a Java program on numerology?
Yes. You can very well have a java program on numerology. But, the subject of numerology is very complicated and coming up with a program to do that will be quite a feat.
Write a Program to implement error correction using hamming code?
/*
WRITTEN BY : BIBHAKAR JHA
OBJECTIVE: TO IMPLEMENT HAMMING CODE IN C
*/
// PROGRAM CODE :
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void main()
{
char sender[20],buffer[50],reciver[20];
int d,p=0,i=0,j,k,length,power,count;
clrscr();
printf("ENTER THE MESSAGE IN BIT FORM:- ");
gets(sender);
d=strlen(sender);
//power
for(p=0; ;p++)
{
if(pow(2,p)>=d+p)
{
break;
}
}
p--;
/* COPY THE BITS INTO BUFFER */
i=1;
power=0;
j=0;
do
{
if(i==pow(2,power))
{
buffer[i]='0';
power++;
i++;
}
else
{
buffer[i]=sender[j];
j++;
i++;
}
}while(j<=d);
buffer[i]='\0';
//APPLY BIT IN CODE
count=0;
length=d+p;
j=0;
for(j=0;j<=p;j++)
{
k=pow(2,j);
for(i=k+1;i<=length; )
{
if(k==1)
{
if(buffer[i]=='1')
{
count++;
}
i=i+2;
}
else
{
if(buffer[i]=='1')
{
count++;
}
i++;
if(i%k==0)
{
i=i+k;
}
}
}
if(count%2==1)
{
buffer[k]='1';
}
count=0;
}
printf(" ENCODED MESSAGE IS \n ");
i=1;
do
{
printf("%c",buffer[i]);
i++;
}while(buffer[i]!='\0');
getch();
}
Who is the original author of java software?
James Gosling is known as the Father of Java software, however, Sun Microsystems employs many people (authors) to write scripts for them.
Example of inclusive or operator in java?
This is often used to specify several possibilities For example, assuming you have the last digit of a number in a variable "lastDigit":
if (lastDigit 5)
// In this case, the number is divisible by 5
C language is developed by Dennis Ritchie at Bell Laboratories in 1972. To know more about C Programming and learn C Programming from basics to advance visit codeforhunger. com
How do you sort string values by field calculator in ArcMap?
For example, there are few string values of "1-5", ">5", "0-0.9", and "<0" from one field in attribute table. Then I need to sort both "1-5" and ">5" to a new field. How do I make the field calculator for this? Thank you!
Synopsis for project of chat server?
ABSTRACT This report details the work done towards the project "Chat Server". This particular project is a solution developed to communicate between the users across worldwide through Internet. The concept of sending letters and telegraphs has been reduced due to the new era of Internet Mailing. One such facility is being provided by the Chat Server. A message or an information can be sent via many medias, such as it can be telephonic, telegrams, fax etc to the reciepient. Each such information requires a high level of security. To maintain such security and smooth completion of any communication it requires more time and human effort in manual systems.
"Chat Server" automates all the aspects stated above related to a communication in a highly secure environment. This project has been developed to receive instant and urgent messages and to provide total user satisfaction.
The entire process has been automated using JAVAtechnology and SQL SERVER to smoothen the flow of information in a highly secure environment across the network. The solution has been deployed, tested and validated thoroughly. While designing the system, care has been taken in efficiency, maintenance and reusability of the software for the present and future changes in the system.
SYNOPSIS
This is a copy of the synopsis, which was submitted to the institute in the beginning of the project.
ABOUT THE PROJECT : -
This particular project is a solution developed to communicate between the users across worldwide through Internet. The concept of sending letters and telegraphs has been reduced due to the new era of Internet Mailing. One such facility is being provided by the Chat Server.
"Chat Server" automates all the aspects stated above related to a communication in a highly secure environment. This project has been developed to receive instant messages and to provide total user satisfaction.
Existing System: -
It is limited to only two clients. The existing Chat Server System is only meant for transfer of messages from one client to the other. But the messages cannot be formatted and made attractive to look as well as graphical emotional pictures cannot be added to send the picture messages.
This system does not provide the facility of sending and receiving greetings of different occasions. This system does not provide the facility of adding friends and exclusively chatting with the particular added friend.
Proposed System: -
PDS. [Predictivity Dialing System]. Eg. Avaia, Maclenn, SRC & so on. To enhance the performace the system, which helps them to monitor the performance of agents who r online.
The proposed "Chat Server" is a chatting application that provides a good user interface with all the facilities of a chat application. Users have their user-id. User can communicate with any other user, who is online. User gets a list of online users. User can select any user and send a message.
Message can be formatted in terms of font style and size. He can also send some graphical emotional pictures. This application also manages the list of all online users. It also provides the facility of browser window to surf simultaneous.
Client Module:
It provides a frame to login to the chat server. After providing the userid and password the get access to his main frame. He will get a list of online users, area to enter the text, options to format the message. He can also send some image with the message. This application provides option for changing his personal profile. The user can add any other user to his friend list.
Server Module:
The server module is responsible for validating the user information. It allows the authorized user to get facilities provided by this application. It also displays the online users list. It is connected to the database server to perform the function like modifying the user profile, creating a new user account etc.
Advantages of Proposed System: -
The application is feasible for the economic as well as the technical advantages it gives. The main advantages are: -
As the solutions is integrated and developed on the JAVA technology so that it provides multi functionality services. The solution is built purely on the Java Technology using the latest version of Java Swing. So the solution is platform independent and architecture independent and supports different RDBMS packages as Java has in built support for the drivers of different databases. The JAVA based solution is defined as the solution for the enterprise wide application where each and every individual system are integrated on the JAVA platform for the smooth communication among different technologies and solutions.
This particular project is a solution developed to communicate between the users across worldwide through Internet. The concept of sending letters and telegraphs has been reduced due to the new era of Internet Mailing. One such facility is being provided by the Chat Server. A message or an information can be sent via many medias, such as it can be telephonic, telegrams, fax etc to the reciepient. Each such information requires a high level of security. To maintain such security and smooth completion of any communication it requires more time and human effort in manual systems.
This project has been developed to receive instant formatted test and graphical messages and to provide total user satisfaction.
EXISTING CHATSERVER SYSTEM AND ITS LIMITATIONS
Existing System: -
It is limited to only two clients. The existing Chat Server System is only meant for transfer of messages from one client to the other. But the messages cannot be formatted and made attractive to look as well as graphical emotional pictures cannot be added to send the picture messages.
This system does not provide the facility of sending and receiving greetings of different occasions. This system does not provide the facility of adding friends and exclusively chatting with the particular added friend.
PROPOSED SYSTEM
The proposed "Chat Server" is a chatting application that provides a good user interface with all the facilities of a chat application. Users have their user-id. User can communicate with any other user, who is online. User gets a list of online users. User can select any user and send a message.
Message can be formatted in terms of font style and size. He can also send some graphical emotional pictures. This application also manages the list of all online users. It also provides the facility of browser window to surf simultaneous.
Client Module:
It provides a frame to login to the chat server. After providing the userid and password the get access to his main frame. He will get a list of online users, area to enter the text, options to format the message. He can also send some image with the message. This application provides option for changing his personal profile. The user can add any other user to his friend list.
Server Module:
The server module is responsible for validating the user information. It allows the authorized user to get facilities provided by this application. It also displays the online users list. It is connected to the database server to perform the function like modifying the user profile, creating a new user account etc.
HARDWARE REQUIREMENT SPECIFICATION
Hardware Specification: -
Server side:
Description
Minimum
Recommended
System type
IBM compatible PC with 1GHz
IBM compatible PC with 2GHz
RAM
256 MB
512 MB
Cache
256 KB
512 KB
Storage
40 GB
120 GB
(Convenient for Backup)
Disk Drive
Floppy or CD-RW
(Back up purpose)
Floppy or CD-RW or DAT
(Back up purpose)
Display
15'' VGA
17'' SVGA (LCD)
User Interface
Key Board and mouse
Compatible keyboard and mouse
Output media
DMP Printer
Laser Printer (For reports)
Client Side:
Description
Minimum
Recommended
System type
IBM compatible PC with 1GHz
IBM compatible PC with 1GHz
RAM
128 MB
256 MB
Cache
256 KB
512 KB
Storage
20 GB
40 GB
(Convenient for Backup)
Disk Drive
Floppy or CD-RW
(Back up purpose)
Floppy or CD-RW
(Back up purpose)
Display (LCD)
14'' VGA
15'' SVGA
User Interface
Key Board
Compatible keyboard and mouse
Output media
DMP Printer
Laser Printer (For reports)
What is the use of BufferedReader in Java programming?
The BufferedReader class provides buffering to your Reader's. Buffering can speed up IO quite a bit. Rather than read one character at a time from the network or disk, you read a larger block at a time. This is typically much faster, especially for disk access and larger data amounts.
The main difference between BufferedReader and BufferedInputStream is that Reader's work on characters (text), wheres InputStream's works on raw bytes.
To add buffering to your Reader's simply wrap them in a BufferedReader. Here is how that looks:
Reader input = new BufferedReader(
new FileReader("c:\\data\\input-file.txt"));