How can you embed a Java program in PHP webpage?
In the output stream (i.e. using echo), output an "embed" tag (or if using older HTML, the "applet" tag). Note that the Java will run on the client, not on the server, meaning that PHP variables, etc, will not be available to it.
Write a java program to count the space from the given line?
....
String line = "This is example program with spaces";
String[] tokens = line.split(" ");
System.out.println(tokens.length-1);
.......
A complete java code to make calculator?
import java.io.*;
import java.util.*;
public class Calculator
{
public static void main(String args[])
{
System.out.println("Make your arithmetic selection from the choices below:\n");
System.out.println(" 1. Addition");
System.out.println(" 2. Subtraction");
System.out.println(" 3. Multiplication");
System.out.println(" 4. Division\n");
System.out.print(" Your choice? ");
Scanner kbReader = new Scanner(System.in);
int choice = kbReader.nextInt();
if((choice<=4) && (choice>0))
{
System.out.print("\nEnter first operand. ");
double op1 = kbReader.nextDouble();
System.out.print("\nEnter second operand.");
double op2 = kbReader.nextDouble();
System.out.println("");
switch (choice)
{
case 1: //addition
System.out.println(op1 + " plus " + op2 + " = " + (op1 + op2) );
break;
case 2: //subtraction
System.out.println(op1 + " minus " + op2 + " = " + (op1 - op2) );
break;
case 3: //multiplication
System.out.println(op1 + " times " + op2 + " = " + (op1 * op2) );
break;
case 4: //division
System.out.println(op1 + " divided by " + op2 + " = " + (op1 / op2) );
}
}
else
{
System.out.println("Please enter a 1, 2, 3, or 4.");
}
}
}
In java how do you use a for loop to print out a word as many times of its length?
Its simple:
String a="Suraj Acharya"//consider this to be your string
for(int i=0;i<a.length();i++)
System.out.println("Its Simple");
Why is a Java Download so important?
Java is important because it a program to run certain games or videos.
Is String class a final class?
The core classes in the java.lang.* package (e.g. String, Integer, double, Boolean, etc.) are all declared final.
How to you Create 2 text-field and 1 button in java using applet and then get the input as integers in 2 text-field and to display the output in label already created when you click the button?
please send immediately,needed urgently
there r 4 logical operator not 3
AND, OR, XOR, and NOT
What is KNN imputation method?
KNN means k-nearest neighbors (KNN). KNN imputation method seeks to impute the values of the missing attributes using those attribute values that are nearest to the missing attribute values.
Why doesn't Java use header files?
A header file in C is used to import the features of parent classes in our class. The same feature is provided by the import statement in Java hence the header files are not used.
Method 'CopyFile' of object 'IFileSystem3' Failed?
This error is due to the write protection
check if the destination file is open. If the file is open close that file, it Will fix the issue.
JAVA RING
JAVA RINGS..
OUTLINE
HISTORICAL BACKGROUND
In the summer of 1989, Dallas Semiconductor Corp.
produced the first stainless-steel-encapsulated memory
devices utilizing the Dallas Semiconductor 1-Wire
communication protocol.
By 1990, this protocol had been refined and employed
in a variety of self-contained memory devices.
Originally called "touch memory" devices, they were
later renamed iButtons
One of the first impressive devices powered by the Java Card
technology came in the formÃ'Â of now famous Java Rings at the
Ã'Â Sun's JavaOne conference, in March 1998.
WHAT IS JAVA RING ??
The Java Ring is a stainless-steel ring, 16-millimeters (0.6 inches) in diameter that houses a 1-million-transistor processor, called an iButton
The Java Ring is a tiny wearable computer with 134kilobytes of RAM.
RAM has 6KB of data memory and to 32KB 0f program memory
6KB may not sound like much, but it is 20 percent more memory
than the first computer ever used .
Even 6 K is enough to hold your secret codes, your credit cards
numbers, your driver license, other wallet contents, and even some electronic cash. The ring can also store a few important URLs.
CONTD..
The Java Ring is a wearable computer that can be used to
authenticate users to services on the Internet. A user only has to
push the ring on her finger on a Java Ring reader for about a
second.
The key issue about a wearable computer is not whether it is a ring
or another form factor: the deciding point is that we will always
have it with us. Many aspects of computing change once there
is no need to go to a special room to get at the computer.
INSIDE JAVARING
JAVA VIRTUAL MACHINE
134KB RAM
32KB ROM
REAL TIME CLOCK
IBUTTON
BLUE DOT RECEPTOR
CONTD..
JAVA VIRTUAL MACHINE
JVM is the piece of software that recognises java language and translate the byte code, which is used by system connected to java ring via reader.
134KB of RAM
* It is used to store program and data.
* The NVRAM offers high R/W speed and also provides temper resistance through instantaneous clearing of all memory when tempering is detected. This process called as Rapid Zeroization.
* Energy provided by lithium backup preserves complete state of machine when java ring is disconnected from user.
CONTD..
* Performs garbage collection to deal with the objects which are out of scope and recycle memory.
* Applets can be loaded or unloaded from java iButton
32KB of ROM
* Special kind of operating system called E-commerce based on java and JVM is stored in the ROM. This is because it is not supposed to be altered by the user.
* Operating system handles all operations happening in iButton.
REAL TIME CLOCK
* It gives exact time of the day. It can run upto 10 years by energy provided by lithium backup.
* Processor clock frequency is not constant and cannot be determined by external means.
It means "International Baccalaureate" which is a type of high school which promotes very high standards of accademics and vigrous homework and classwork assignments.
Why does indexing start with 0 in Java?
Primarily to be compatible with C and C++, which was one of the goals of Java when it was being designed (minimize the learning curve for those familiar with C and C++ to increase adoption). Speaking from a lower-level perspective, arrays are accessed by a pointer and an index. If you call the pointer PTR, and the index IDX, you can access an element in the array by using PTR+IDX. In order to avoid wasting memory, IDX may be zero, since PTR is already allocating that memory to the existence of the array. In languages where IDX starts at 1, PTR[0] stores the number of elements in the array, and can't be directly accessed. Java stores the length of the array elsewhere (in the variable "length"), and so it can start its element allocation at zero.
Does sony laptop support java application?
Yes. All computers and laptops can run and support Java. You can download Java from Sun's website and then install it in your computer to use it.
These should work, if used correctly.
// stores srcL + srcR into dest
// NOTE: dest must be at least as large as srcL + srcR
void strConcat(const char* srcL, const char* srcR, char* dest) {
const int lengthL = strLength(srcL);
const int lengthR = strLength(srcR);
// copy srcL into front of dest
int i;
for(i = 0; i < lengthL; ++i) {
dest[i] = srcL[i];
}
// copy srcR into the rest of dest
for(i = 0; i < lengthR; ++i) {
dest[lengthL + i] = srcR[i];
}
dest[lengthL + i] = '\0';
}
// copies characters from src to dest
// NOTE: dest must be at least as large as src
void strCopy(const char* src, char* dest) {
const int length = strLength(src);
// copy
int i;
for(i = 0; i < length; ++i) {
dest[i] = src[i];
}
}
// reverses str and puts the result in buff
// NOTE: buff must be at least as large as str
void strReverse(const char* str, char* buff) {
const int length = strLength(str);
// special case for zero-length strings
if( length == 0 ) {
return;
}
// reversify
int i;
for(i = 0; i < length; ++i) {
buff[i] = str[length - i - 1];
}
buff[i] = '\0';
}
// returns the number of characters in str
int strLength(const char* str) {
int length = 0;
// take advantage of the fact that all strings MUST end in a null character
while( str[length] != '\0' ) {
++length;
}
return length;
}
Java vowel consonant space counts switch?
// Prints out the number of vowels, consonants, and space characters in str.
static void printCounts(final String str) {
// Keep track of totals
int numVowels = 0;
int numConsonants = 0;
int numSpaces = 0;
// All lowercase chars will simplify the check for letters.
final String strLower = str.toLowerCase();
for (final char ch : strLower.toCharArray()) {
// Switch on the type of character of ch and update the correct total
switch (getType(ch)) {
case VOWEL:
++numVowels;
break;
case CONSONANT:
++numConsonants;
break;
case SPACE:
++numSpaces;
break;
}
}
// Done
System.out.println("Vowels:\t" + numVowels);
System.out.println("Consonants:\t" + numConsonants);
System.out.println("Spaces:\t" + numSpaces);
}
private enum CharType {VOWEL, CONSONANT, SPACE, OTHER;}
// Returns the CharType of ch
static CharType getType(final char ch) {
if (ch >= 'a' && ch <= 'z') { // letters
switch (ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
return CharType.VOWEL;
default:
return CharType.CONSONANT;
}
} else if (ch == ' ') { // spaces
return CharType.SPACE;
}
return CharType.OTHER;
}
How do you add items in GridLayout in Java?
You don't actually add items to a LayoutManager object. You should set the layout of the Container you want to add your Components to and the GridLayout will put them where they need to be.
Container myContainer = new Container();
int numRows = 3;
int numCols = 2;
GridLayout myLayoutManager = new GridLayout(numRows, numCols);
myContainer.setLayout(myLayoutManager);
// Add some JButtons to the container...
myContainer.add(new JButtons ("1"));
myContainer.add(new JButtons ("2"));
myContainer.add(new JButtons ("3"));
myContainer.add(new JButtons ("4"));
myContainer.add(new JButtons ("5"));
myContainer.add(new JButtons ("6"));
Your final component will look something like the following:
| 1 | 2 |
| 3 | 4 |
| 5 | 6 |
How do you fix 'identifier expected after this token' error in java?
Probably you've called some methods not within the main method:
public class Foo{
public static void main(String []args){
// Calling methods here.
}
}
I believe your problem is:
public class Foo{
// Calling methods here. This is wrong.
}
What are the different kinds of variables in java and their uses?
Java is a powerful language that gives us options to have data in different forms. We have several data types that we can use for our needs. The basic data types that java offers us are termed as Primitive Data Types. Though all programming languages have varied data types java offers us with a variety of data types that are much powerful and simplified to use when compared to other languages. The Java programming language is strongly-typed, which means that all variables must first be declared before they can be used. This involves stating the variable's type and name. int age = 10; The above statement tells the java compiler that a field named "age" which holds numeric data and having an initial value of 10 is declared. A variable's data type determines the values it may contain, plus the operations that may be performed on it. In addition to int, the Java programming language supports seven other primitive data types. A primitive type is predefined by the language and is named by a reserved keyword. Primitive values do not share state with other primitive values. The eight primitive data types supported by the Java programming language are: * byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation. * short: The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same guidelines apply: you can use a short to save memory in large arrays, in situations where the memory savings actually matters. * int: The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice unless there is a reason (like the above) to choose something else. This data type will most likely be large enough for the numbers your program will use, but if you need a wider range of values, use long instead. * long: The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by int. * float: The float data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead * double: The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency. * boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined. * char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive). In addition to the eight primitive data types listed above, the Java programming language also provides special support for character strings via the java.lang.String class. Enclosing your character string within double quotes will automatically create a new Stringobject; For ex: String name = "Rocky"; would create a new String object of name "name" and holding an initial value "Rocky" String objects are immutable, which means that once created, their values cannot be changed. The String class is not technically a primitive data type, but considering the special support given to it by the language, you'll probably tend to think of it as such. Default Values It's not always necessary to assign a value when a field is declared. Fields that are declared but not initialized will be set to a reasonable default value by the compiler. Generally speaking, this default will be zero or null, depending on the data type. Relying on such default values, however, is generally considered bad programming style. The default values for the primitive data types are: 1. byte - 0 2. short - 0 3. int - 0 4. long - 0L 5. float - 0.0f 6. double - 0.0d 7. char - '\u0000' 8. String or any other object - null 9. boolean - false These default values are assigned only to class level variables or class instance variables. Local variables are slightly different; the compiler never assigns a default value to an uninitialized local variable. If you cannot initialize your local variable where it is declared, make sure to assign it a value before you attempt to use it. Accessing an uninitialized local variable will result in a compile-time error.