Exercises for ja se

504 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
504
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Exercises for ja se

  1. 1. Exercises for Week 1
  2. 2. Public static void main (String args[]) <ul><li>The public keyword is an access specifier, which allows the programmer to control the visibility of class members. When a class member is preceded by public, then that member may be accessed by code outside the class in which it is declared.In this case, main( ) must be declared as public, since it must be called by code outside of its class when the program is started. The keyword static allows main( ) to be called without having to instantiate a particular instance of the class. This is necessary since main( ) is called by the Java interpreter before any objects are made. The keyword void simply tells the compiler that main( ) does not return a value. As you will see, methods may also return values.  As stated, main( ) is the method called when a Java application begins. Keep in mind that Java is case-sensitive. Thus, Main is different from main. It is important to understand that the Java compiler will compile classes that do not contain a main( ) method. But the Java interpreter has no way to run these classes. So, if you had typed Main instead of main, the compiler would still compile your program. However, the Java interpreter would report an error because it would be unable to find the main( ) method.  Any information that you need to pass to a method is received by variables specified within the set of parentheses that follow the name of the method. These variables are called parameters. If there are no parameters required for a given method, you still need to include the empty parentheses. In main( ), there is only one parameter, albeit a complicated one. String args[ ] declares a parameter named args, which is an array of instances of the class String. Objects of type String store character strings. In this case, args receives any command-line arguments present when the program is executed. </li></ul>
  3. 3. Class BufferedReader <ul><li>http://java.sun.com/j2se/1.4.2/docs/api/java/io/BufferedReader.html </li></ul><ul><li>Read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines. </li></ul><ul><li>The buffer size may be specified, or the default size may be used. The default is large enough for most purposes. </li></ul><ul><li>In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as File Readers and InputStreamReaders. For example, </li></ul><ul><li>BufferedReader in = new BufferedReader(new FileReader(&quot;foo.in&quot;)); will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient. Programs that use DataInputStreams for textual input can be localized by replacing each DataInputStream with an appropriate BufferedReader. </li></ul>
  4. 4. Class InputStreamReader <ul><li>An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified  charset . The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted. </li></ul><ul><li>Each invocation of one of an InputStreamReader's read() methods may cause one or more bytes to be read from the underlying byte-input stream. To enable the efficient conversion of bytes to characters, more bytes may be read ahead from the underlying stream than are necessary to satisfy the current read operation. </li></ul><ul><li>For top efficiency, consider wrapping an InputStreamReader within a BufferedReader. For example: </li></ul><ul><li>BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); </li></ul>
  5. 5. NOW TRY TO CREATE YOR OWN SLAM BOOK HAVING 15 QUESTIONS
  6. 6. CREATE A SIMPLE CALCULATOR THAT CAN PERFORM + - / * AND %
  7. 7. CREATE A PROGRAM TEPMPERATURE CONVERSION PROGRAM
  8. 9. WRITE AN ARRAY LIST THAT DIPLAY ALL THE MONTHS OF THE YEAR
  9. 11. WRITE A MESSAGE OR ANY COMMENT ABOUT YOUR INSTRUCTOR
  10. 12. DENOMINATION COUNTER PART1
  11. 13. DENOMINATION COUNTER PART 2
  12. 14. DENOMINATION COUNTER PART3
  13. 16. Create a program that will compute for the weight of an object weight (kg) equal to mass multiplied by gravitational pull of the earth(9.8 meter/sec).
  14. 19. FOOD FOR THE BRAIN Displays a message with no icons YES JOptionPane.PLAIN_MESSAGE Display Questions YES JOptionPane.QUESTION_MESSAGE Warning display YES JOptionPane.WARNING_MESSAGE Information display YES JOptionPane.INFORMATION_MESSAGE Error message display YES JOptionPane.ERROR_MESSAGE DESCRIPTION ICON MESSAGE DIALOG TYPE

×