Parts of A Java Program
Parts of A Java Program
Parts of A Java Program
*;
public class jez
{
public static void main(String[]args) throws IOException
{
BufferedReader input= new BufferedReader(new
InputStreamReader(System.in));
String a,b,c,d;
double q,w,e,r,t;
System.out.println("Enter CS");
c= input.readLine();
r= Double.parseDouble(b);
e=(q+w)/2*(0.40)+(r*0.10)+(t*0.5);
System.out.println("Your Prelim Grade is " +e );
}
}
The keyword public denotes that a method can be called from code in other classes, or that a class
may be used by classes outside the class hierarchy. The class hierarchy is related to the name of the
directory in which the .java file is.
The keyword static in front of a method indicates a static method, which is associated only with the
class and not with any specific instance of that class. Only static methods can be invoked without a
reference to an object. Static methods cannot access any method variables that are not static.
The keyword void indicates that the main method does not return any value to the caller. If a Java
program is to exit with an error code, it must call System.exit() explicitly.
The method name "main" is not a keyword in the Java language. It is simply the name of the method
the Java launcher calls to pass control to the program. Java classes that run in managed environments
such as applets and Enterprise JavaBean do not use or need a main() method. A java program may
contain multiple classes that have main methods, which means that the VM needs to be explicitly told
which class to launch from.
The main method must accept an array of String objects. By convention, it is referenced as args
although any other legal identifier name can be used. Since Java 5, the main method can also use
variable arguments, in the form of public static void main(String... args), allowing the main method
to be invoked with an arbitrary number of String arguments. The effect of this alternate declaration is
semantically identical (the args parameter is still an array of String objects), but allows an alternate
syntax for creating and passing the array.
IOException - if an I/O error occurs. Most methods of this IO class throw an exception if anything
goes wrong. Therefore you have to put block of the code that call this method inside a try-catch block.
The compiler will complain if you don't do this.
BufferedReader is a wrapper around the InputStreamReader which simply buffers the input which
can, and usually does, bring performance benefits. 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.
InputStreamReader is a Reader "wrapper" around this InputStream which then allows you to read
characters, i.e. it is a Character stream, rather than a byte stream.
parseDouble(String). Returns a new double initialized to the value represented by the specified
String, as performed by the value of method of class Double.