Describe different ways that a function can handle errors?
There are two ways. The method can have a try catch block and handle the error/exception inside the method. Or The method can throw the exception under the assumption that the calling method would have the code to handle the exception that is thrown by this method
First of all the compiler converts our source code into byte code ,this is done by "javac" compiler.then we use interpretor that is the"java interpretor" for making our byte code executed.thats y java is called as an compiled and interpred language.by that way our java program will be interpreted. First of all our source code vl b converted into byte code by da java compiler named "javac" ,then dt byte code vl be executed by da interpretor named "java" interpretor. These are execution steps in java dts y v call java as a compiled and interpreted language.
import java.util.Scanner;
import java.io.File;
public class Filedemo {
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
String s=input.nextLine();
File f1=new File(s);
System.out.println("File Name:"+f1.getName());
System.out.println("Path:"+f1.getPath());
System.out.println("Abs Path:"+f1.getAbsolutePath());
System.out.println("Parent:"+f1.getParent());
System.out.println("This file is:"+(f1.exists()?"Exists":"Does not exists"));
System.out.println("Is file:"+f1.isFile());
System.out.println("Is Directory:"+f1.isDirectory());
System.out.println("Is Readable:"+f1.canRead());
System.out.println("IS Writable:"+f1.canWrite());
System.out.println("Is Absolute:"+f1.isAbsolute());
System.out.println("File Last Modified:"+f1.lastModified());
System.out.println("File Size:"+f1.length()+"bytes");
System.out.println("Is Hidden:"+f1.isHidden());
}
}
How do you open chm file in Java programming?
Hi,
Using desktop class u can open the .chm or any other kind of file that was in your computer.
Desktop.getDesktop().open( new File("D:/Documents and Settings/ Document.chm"));
Don't forget to include the line import java.awt.Desktop;
This class is available with Java 6 updates.
Java rocks!!!
To display an input string vertically by c?
// get input
char input[256];
gets(input);
// print one character on each line
int i;
for(i = 0; input[i] != '\0'; ++i) {
printf("%c\n", input[i]);
}
What is Packages in Java programming?
basically packages are a collection or a directory of similar classes.
there are some inbuilt packages in java which prove to be really useful like the java.lang package which automatically is imported into your program.
in addition you can also create your own packages and its really simple to create them! :)
How do you find odd numbers between two numbers in java?
import java.io.*;
class aeven
{
public static void main(String[] args)
{
try{
BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter 1st number : ");
int num1 = Integer.parseInt(br1.readLine());
System.out.println("Enter 2nd number : ");
int num2 = Integer.parseInt(br1.readLine());
System.out.println("Odd Numbers : ");
for (int i=num1;i <=num2 ; i++)
{
if(i%2!=0 )
{
System.out.print(i+ ", ");
}
}
}
catch(Exception e){}
}
}
How would you write an algorithm to calculate the average number of vowels in a passage?
String passage= new String("blah blah blah");
int vowelSum=0;
for(int i=0;i<passage.length();i++)
if(passage.charAt(i)=='a' passage.charAt(i)=='e' ...etc....
vowelSum+=1;
System.out.println(vowelSum);
That is a basic idea and in no way the best possible way to do it.
JBuck
Compare and contrast the IF single-selection statement and the while repetition statement?
The only difference is that an if statement will be evaluated at most one time and a while statement will be evaluated repeatedly until the loop condition evaluates to false.
What affect does java have on society?
I think you mean, either:
"What EFFECT does java(COFFEE) have on society?"
or
"What EFFECT does Java(TM) have on society?"
There is no single best answer to the COFFEE query, however, one of the best & probably the most comprehensive answer, may be found at this link:
http:/www.nationalgeographic.com/coffee
Pay particular attention to the article entitled, "Coffee Craze Spread With Islam."
Why must the value chosen for use as a sentinel be carefully selected?
The value must be unique enough that it will not be mistaken as a regular value in the list.
All data is stored in a computer as 0s and 1s. In order to make this more efficient, certain sets of bits can mean different things depending on what the data type is. Some languages, such as Java, make sure the programmer doesn't confuse these types and mess up the data. However, other languages allow you to do things like multiply a string and an array. If you don't pay careful attention to data types, you can easily end up with useless data.
// Set up a Scanner class to read from standard input
final Scanner in = new Scanner(System.in);
// Prompt for input and read the next integer
System.out.print("Please enter a positive integer: ");
int n = in.nextInt();
// Since we want to print out n lines, iterate n times
for (; n > 0; --n) {
// On each iteration, print out the numbers [1,n]
for (int i = 1; i <= n; ++i) {
System.out.print(i + " ");
}
System.out.println();
}
// Remember to close open resources when we're done.
in.close();
Example of area of rect inheritance program in java?
Let us first define a generic Shape class. This will be an abstract class, since the term "shape" is, itself, very abstract.
Let us also assume that this shape is defined in only two dimensions, for the sake of simplicity.
abstract class Shape {
/*
One of the properties of any 2D shape is the area it takes up. Since calculating the area depends on the shape, we'll make this method abstract - all subclasses should implement it differently.
*/
abstract int getArea();
}
Now that we have our base class defined, we can create a rectangle subclass.
class Rectangle extends Shape {
/*
While a rectangle has other properties, we are really only interested in the ones required to calculate the area - width and height.
*/
int width;
int height;
/*
What's the area of a rectangular shape?
area = width x height
*/
int getArea() {
return width*height;
}
}
Why long data type converted to double by multiplying by 1.0?
If two numbers are involved in a calculation (in this case a multiplication), the result is converted to the more precise data type, to avoid data loss. Even though between long and double data can be lost in either direction, a number with decimals (such as double) is generally considered to be more precise than a number without decimals (such as long). Even though languages such as Java also have a "float" data type, "double" is normally used by default in cases such as these, because of the greater precision. However, you can convert explicitly to float, if you like, using a cast. (Float uses 4 bytes, while double uses 8 bytes.)
What part of a function definition specifies the data type of the value that the function returns?
The function header. The return value is written before the name of the function. This return type must match the type of the value returned in a return statement.
// one dimensional array 'num' of type int...
int num[100];
{Sorry, diagrams are not possible in wiki.answers.com, you have to use words}
This is 100 copies of an integer data type, arranged sequentially in memory. The first one is called num[0], the tenth one is called num[9], and the 100th one is called num[99].
// two dimensional array 'matrix' of type float...
float matrix[10][20];
This is 200 copies of a floating point data type, arranged sequentially in memory. The first one is called matrix[0][0], the tenth one is called matrix[9][0], the eleventh one is called matrix[0][1], and the 200th one is called matrix[9][19].
In both cases, you don't want to "think" about the arrangement of bits and bytes within each int or float. Doing so is non-portable, and can lead to problems down the road. The only safe thing you can consider is the arrangement in memory of the copies of the fundamental type int or float.
2
<float_literals> -> <digit> { <digit> } [ . ] [ { <digit> } ]
<digit> -> "0" | <digit excluding zero>
<digit excluding zero> -> "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
hi dude
i wish you are satisfied with my answer
LOL ^^
How many bytes are allocated in the bool data type?
bool (lowercase, built-in type) has an unspecified size, but is typically 1 byte. When in doubt, use sizeof( <type> ) to determine the byte count of any data type.
The best IDE for Struts framework?
Jdeveloper
jdeveloper produced a virtual drag and drop environment for the Struts framework and helps the developer to manage and speed up the project.
IDEA
IDEA 8 has full fledged support for the Struts 2 framework
there are Struts plugins available
Eclipse
there are Struts plugins available
Can InetAddress be used with inet6 in java?
Yes.
Using the method InetAddress.getByName( String name) for instance.
What is the recommended system to run Java?
There is no "recommended system". Java is meant to be run in many different environments or systems. It is not designed preferentially for Windows, Linux, desktop computers, smartphones, or any other system. For some newer Java programs, you need to have sufficient RAM memory, and perhaps processor speed, to run them sufficiently fast, but this may vary, depending on the complexity of the program. A Java program may be anything from (for example) a simple calculator app or an interactive graph to show some physical principle, to a game with a 3D world, such as RuneScape (which was designed with Java).