What is embedding java script?
To embed JavaScript code is to include it in the HTML page. For example, this will embed the code to display an alert:
<script type="text/javascript">
alert("Embedded alert!");
</script>
Scanner scan = new Scanner(System.in); // A scanner object that reads from the
// keyboard( System.in), must import
//Scanner class to use this System.out.print("Input Integer: "); int first = scan.nextInt(); //Reads the next int after the printed stuff that the user
//inputs System.out.print("Input Double: "); double first = scan.nextDouble(); //Reads the next double after the printed stuff that
//the user inputs
How do you calculate size of an unsized array?
In Java, all arrays have a finite size. Even if you did not initialize an array to a particular size (say the array was being passed into a method), some other part of the program did. Because of this, the length of an array can always be accessed via the .length parameter.
Example:
int[] arr = new int[5];
System.out.print(arr.length); //5
public void k(int[] arr)
{
System.out.print(arr.length) //arr will always have a finite size
}
Why ostream operators not overloaded using member functions?
Consider the following line:
cout<<obj;
where obj is the object of Demo class.
In this case we are overloading "<<" operator. But overloading the binary
operator using member function, the left hand operand should be the object of relevant class.
Here in this case left hand side operand is not the object of Demo class. It is object of ostream class.
Hence we cant overload ostream operators using member function. But we can overload these type of operators using friend functions.
Thanks,
Prof. D. H. Ingole
quadruple means anything that has 4 of something in it. quad=4
Its suppose to say k greater than or equal to 3
k greater than or equal to 6
How many types of Data Base in market?
In many cases, each company has its own database (or several databases), so I would estimate that there are about as many databases as there are companies.
If you are referring to the DBMS - the software that manages the databases - you can see a list of the most common ones in the following Wikipedia articles:
* Comparison of relational database management systems
* Comparison of object database management systems
* Comparison of object-relational database management systems
Class limits and class boundaries?
The extreme values of a Class (Class - A range of values which incorporate a set of terms.) are called its Class Limits. This means that the Class doesn't contain values beyond the two extremes of its limits.
.....will be automatically Invoked when an object is created?
The Class object is automatically created by the JVM when an object is created. The Class object provides information about the Class and is primarily used by the IDEs and factory classes.
The method that is automatically called when an object is created is called a constructor. In Java, the constructor is a method that has the same name as the class.
How do you make a UIPickerView that plays sounds?
The UIPickerView doesn't actually play the sounds; you do that with a hidden media control. When you click the control button, you examine the selected element in the list and load the associated sound file into the media control, which then plays the file. There are various ways of doing it, but one of the simplest methods is to use two parallel arrays, one containing the titles (which you load into the list), the other containing the paths to the sound files. Both arrays being of type std::string, of course. Thus element 9 in the titles array maps to element 9 in the sound files array. Alternatively, use std::pair objects (where each element in the pair is a std::string) to associate each title with its sound file.
Why do you need to override the toString method?
By default every class you write inherently extends the base Object class. This has a basic toString() method which merely returns the name of the class followed by a hex representation of the hash value. By overriding this method, you can return a more meaningful value specific to your class, such as member attributes and their values.
Explain different stream classes in Java?
Byte Streams
If a program needs to read/write bytes (8-bit data), it could use one of the subclasses of the InputStream or OutputStream respectively. The example below shows how to use the class FileInputStream to read a file named abc.dat. This code snippet prints each byte's value separated with white spaces. Byte values are represented by integers from 0 to 255, and if the read() method returns -1, this indicates the end of the stream.
import java.io.FileInputStream;
import java.io.IOException;
public class ReadingBytes {
public static void main(String[] args) { FileInputStream myFile = null; try {
myFile = new FileInputStream("c:\\abc.dat"); // open the stream
boolean eof = false;
while (!eof) {
int byteValue = myFile.read(); // read the stream
System.out.println(byteValue);
if (byteValue == -1){
eof = true;
}
//myFile.close(); // do not do it here!!!
}
}catch (IOException e) {
System.out.println("Could not read file: " + e.toString());
} finally{
try{
if (myFile!=null){
myFile.close(); // close the stream
}
} catch (Exception e1){
e1.printStackTrace();
}
}
}
}
Please note that the stream is closed in the clause finally. Do not call the method close() inside of the try/catch block right after the file reading is done. In case of exception during the file read, the program would jump over the close() statement and the stream would never be closed!
The next code fragment writes into the file xyz.dat using the class FileOutputStream:
int somedata[]={56,230,123,43,11,37};
FileOutputStream myFile = null;
try {
myFile = new FileOutputStream("c:\xyz.dat");
for (int i = 0; i
}
} catch (IOException e)
System.out.println("Could not write to a file: " + e.toString()); }
finally
// Close the file the same way as in example above }
Buffered Streams
So far we were reading and writing one byte at a time. Disk access is much slower than the processing performed in memory. That's why it's not a good idea to access disk 1000 times for reading a file of 1000 bytes. To minimize the number of time the disk is accessed, Java provides buffers, which are sort of "reservoirs of data". For example, the class BufferedInputStream works as a middleman between the FileInputStream and the file itself. It reads a big chunk of bytes from a file in one shot into memory, and, then the FileInputStream will read single bytes from there. The BufferedOutputStream works in a similar manner with the class FileOutputStream. Buffered streams just make reading more efficient.
You can use stream chaining (or stream piping) to connect streams - think of connecting two pipes in plumbing. Let's modify the example that reads the file abc.dat to introduce the buffering:
FileInputStream myFile = null;
BufferedInputStream buff =null
try {
myFile = new FileInputStream("abc.dat");
BufferedInputStream buff = new BufferedInputStream(myFile);
boolean eof = false;
while (!eof) {
int byteValue = buff.read();
System.out.print(byteValue + " ");
if (byteValue == -1)
eof = true;
}
} catch (IOException e) {
e.printStackTrace();
} finally{
buff.close();
myFile.close();
}
It's a good practice to call the method flush() when the writing into a BufferedOutputStream is done - this forces any buffered data to be written out to the underlying output stream.
While the default buffer size varies depending on the OS, it could be controlled. For example, to set the buffer size to 5000 bytes do this:
BufferedInputStream buff = new BufferedInputStream(myFile, 5000);
Character Streams
Java uses two-byte characters to represent text data, and the classes FileReader and FileWriter work with text files. These classes allow you to read files either one character at a time with read(), or one line at a time with readLine().
The classes FileReader and FileWriter also support have buffering with the help of BufferedReader and BufferedWriter. The following example reads text one line at a time:
FileReader myFile = null;
BufferedReader buff = null;
try {
myFile = new FileReader("abc.txt");
buff = new BufferedReader(myFile);
boolean eof = false;
while (!eof) {
String line = buff.readLine();
if (line == null)
eof = true;
else
System.out.println(line);
}
....
}
For the text output, there are several overloaded methods write() that allow you to write one character, one String or an array of characters at a time.
To append data to an existing file while writing, use the 2-arguments constructor (the second argument toggles the append mode):
FileWriter fOut = new FileWriter("xyz.txt", true);
Below is yet another version of the tax calculation program (see the lesson Intro to Object-Oriented Programming with Java). This is a Swing version of the program and it populates the populate the dropdown box chState with the data from the text file states.txt.
import java.awt.event.*;
import java.awt.*;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
public class TaxFrameFile extends java.awt.Frame implements ActionListener {
Label lblGrIncome;
TextField txtGrossIncome = new TextField(15);
Label lblDependents=new Label("Number of Dependents:");
TextField txtDependents = new TextField(2);
Label lblState = new Label("State: ");
Choice chState = new Choice();
Label lblTax = new Label("State Tax: ");
TextField txtStateTax = new TextField(10);
Button bGo = new Button("Go");
Button bReset = new Button("Reset");
TaxFrameFile() {
lblGrIncome = new Label("Gross Income: ");
GridLayout gr = new GridLayout(5,2,1,1);
setLayout(gr);
add(lblGrIncome);
add(txtGrossIncome);
add(lblDependents);
add(txtDependents);
add(lblState);
add(chState);
add(lblTax);
add(txtStateTax);
add(bGo);
add(bReset);
// Populate states from a file
populateStates();
txtStateTax.setEditable(false);
bGo.addActionListener(this);
bReset.addActionListener(this);
// Define, instantiate and register a WindowAdapter
// to process windowClosing Event of this frame
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.out.println("Good bye!");
System.exit(0);
}});
}
public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
if (source == bGo ){
// The Button Go processing
try{
int grossInc =
Integer.parseInt(txtGrossIncome.getText());
int dependents =
Integer.parseInt(txtDependents.getText());
String state = chState.getSelectedItem();
Tax tax=new Tax(dependents,state,grossInc);
String sTax =
Double.toString(tax.calcStateTax());
txtStateTax.setText(sTax);
}catch(NumberFormatException e){
txtStateTax.setText("Non-Numeric Data");
}catch (Exception e){
txtStateTax.setText(e.getMessage());
}
}
else if (source == bReset ){
// The Button Reset processing
txtGrossIncome.setText("");
txtDependents.setText("");
chState.select(" ");
txtStateTax.setText("");
}
}
// This method will read the file states.txt and
// populate the dropdown chStates
private void populateStates(){
FileReader myFile = null;
BufferedReader buff = null;
try {
myFile = new FileReader("states.txt");
buff = new BufferedReader(myFile);
boolean eof = false;
while (!eof) {
String line = buff.readLine();
if (line == null)
eof = true;
else
chState.add(line);
}
}catch (IOException e){
txtStateTax.setText("Can't read states.txt");
}
finally{
// Closing the streams
try{
buff.close();
myFile.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
public static void main(String args[]){
TaxFrameFile taxFrame = new TaxFrameFile();
taxFrame.setSize(400,150);
taxFrame.setVisible(true);
}
}
Data Streams
If you are expecting to work with a stream of a known data structure, i.e. two integers, three floats and a double, use either the DataInputStream or the DataOutputStream. A method call readInt() will read the whole integer number (4 bytes ) at once, and the readLong() will get you a long number (8 bytes).
The DataInput stream is just a filter. We are building a "pipe" from the following fragments:
FileInputStream --> BufferedInputStream --> DataInputStream
FileInputStream myFile = new FileInputStream("myData.dat");
BufferedInputStream buff = new BufferedInputStream(myFile);
DataInputStream data = new DataInputStream(buff);
try {
int num1 = data.readInt();
int num2 = data.readInt();
float num2 = data.readFloat();
float num3 = data.readFloat();
float num4 = data.readFloat();
double num5 = data.readDouble();
} catch (EOFException eof) {...}
Set of instructions transf. between viewers and artist. APEX!
public class Random {
public static void main(String ss[])
{
int sum=0;
java.util.Random diceRoller = new java.util.Random();
for (int i = 0; i < 10; i++) {
int roll = diceRoller.nextInt(6) + 1;
sum+=roll;
System.out.println(roll);
}
System.out.println(sum);
}
}
for more queries:- kumar976001@gmail.com
How to convert a .jar file into C dll?
You can refer to http://www.ikvm.net/devguide/net2java.html
1. Still retain your jar
2. Able to access your java library.
Or
http://msdn.microsoft.com/en-us/library/sxh73yst%28VS.80%29.aspx
http://msdn.microsoft.com/en-us/library/ms973842.aspx
What were the differences between methods of Bismarck and Vallabhai Patel?
bismark used his tactful way of unifying but patel was not like that
What is interface incompatibility?
interface incompatibility means two inherited methods are not Override
What is the difference between BufferedReader and InputStreamReader?
InputReader can covert bytes in different encodings to characters.
BufferedReader has a back-end reader which speeds up reading if you are only retrieving small parts at a time.
BufferedReader can mark a given position, and after already reading the bytes, reset back to the previous position.
What is difference between synchronization and inter thread communication?
Synchronization is the process by which, access to the objects by threads are controlled and at at time only one thread can access an object. This is done to ensure that there are no dirty read/write operations. If multiple threads access the same data simultaneously, we may end up with inconsistent data. To avoid it, we place such code in synchronized blocks/methods to ensure integrity of data.
Inter thread communication is the process by which java threads can communicate with one another. They communicate to one another through some commands like wait, notify, notifyall etc.
What are the Advantage and disadvantages of traditional procurement?
advantages and disadvantages of green procurement