Wednesday, April 14, 2010

1.)Topics in JAVA 1

Methods of getting input from keyboard:
1.)JOptionPane - use to get input from keyboard using a dialog box and found in javax.swing package.
ex:
To get input from keyboard:
num = JOptionPane.showInputDialog("Enter a number: ");
a = Integer.parseInt(num);

To output the result:
JOptionPane.showMessageDialog(null, "Num = " +a);

2.)BufferedReader - use to get output input from keyboard using the command prompt and found in java.io package.
ex:
BufferedReader dataIn = new BufferedReader ( new InputStreamReader ( System.in) );
System.out.print("Enter First test Score: ");
try{
x = dataIn.readLine();
}catch( IOException e){
System.out.println(“Error in getting input”);
}

2 Kinds of Control Structure:
1.)Decision Control Structure - Java statements that allows us to select and execute specific blocksof code while skipping other sections.
– if-statement
– if-else-statement
– If-else if-statement


2.)Repetition Control Structure - are Java statements that allows us to execute specific blocks of code a number of times.
– while-loop
– do-while loop
– for-loop

Java Arrays - an array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier.

To declare an array write the data type, followed by a set of square brackets[], followed by the identifier name.

ex:
int []ages;
or
int ages[];

Applet - is a special type of java program that is executed via internet.
Applets Life Cycle:
1.) init()
•First method called when the applet is loaded
2.) start()
Next method called after init
Invoked everytime the applet’s HTML document and the applet itself is displayed
3.)stop()
Called when the web browser leaves the applet’s HTML document
Inform the applet that it should stop its execution
4.)destroy()
Called when the applet needs to be removed from the memory completely
The stop method is always called before this method is invoked

Event Handling
Event Listeners
ActionListener Method
MouseListener Methods
MouseMotionListener Methods
WindowListener Methods
Guidelines for Creating Applications Handling GUI Events

To read input data, by default we use the computer keyboard. However, some of the data we need maybe stored in some data file. For example, if you have a class record stored in a file and you want to retrieve it, or simply want to read a text file using your java program.


Reading from a file:

The FileInputStream class allows you to read data from a file.

The class has the following constructors:

o FileInputStream(File file)
Creates a FileInputStream by opening a connection to an actual file, the file named by the File object file in the file system.

o FileInputStream(FileDescriptor fdObj)
Creates a FileInputStream by using the file descriptor fdObj, which represents an existing connection to an actual file in the file system.

o FileInputStream(String name)
Creates a FileInputStream by opening a connection to an actual file, the file named by the path name name in the file system.


No comments:

Post a Comment