Você está na página 1de 21

Java Tutorials

Basic
Data Type
Math Function
String Function
Basic
import java.io.*;
class AllEvenNum{
  public static void main(String[] args) {
    try{
      BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("Enter number : ");
      int num = Integer.parseInt(br1.readLine());
      System.out.println("Even Numbers:");
      for (int i=1;i <=num ; i++){
        if(i%2==0 ){
          System.out.print(i+",");
        }
      }
    }
    catch(Exception e){}
    
  }
}

import java.io.*;
class CircleArea{
  public static void main(String[] args){
    int r=0;
           try{
        BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter Radius of Circle  : ");
        r = Integer.parseInt(br1.readLine());
        double area = java.lang.Math.PI*r*r;
        System.out.println("Area of Circle : "+area);
        double  perimeter =2*java.lang.Math.PI*r ;
        System.out.println("Perimeter of Circle : "+perimeter);
      }
      catch(Exception e){
        System.out.println("Error : "+e);
      }        
  }
}
import

buffered reader which all the input data are stored and modified
input streamreader
integer.parseint parses the string character into decimal integer
readline
try
avoid any kind of input error
catch(Exception e)

java.lang.Math.PI*r*r;
Data Type
Primitive Data Types
Keyword Description Size/Format
Integers
byte Byte-length integer 8-bit two's complement
short Short integer 16-bit two's complement
int Integer 32-bit two's complement
long Long integer 64-bit two's complement
Real numbers
float Single-precision floating point 32-bit IEEE 754
double Double-precision floating point 64-bit IEEE 754
Other types
char A single character 16-bit Unicode character
boolean A boolean value (true or false) true or false
byte byteident = 3;
    short shortident=100;
    int intident = 10;
    long longident = 40000;
    char charident = 'a';
    String stringident = "chandan";
    float floatident = 12.0045f;
    double doubleident = 2333333.000000000033343343434f;
Math Function
Function Explanation

This is E field of the Math class which returns you a default exponent
value that is closer than any other to e, the base of the natural
E logarithms. 
This is also a field of the Method class which returns you a default pi
PI value, the ratio of the circumference of a circle to its diameter.
abs() This is the abs() function which returns you the absolute number.
This is the ceil() function which returns you the smallest value but greater
ceil() than the argument.
This is the exp() function which returns you the exponential value raised
exp() to the power of a double value.
This is the floor() function which returns you the largest value but less
floor() than the argument.
This is the IEEEremainder() which returns you the remainder for the given
IEEEremainder() dividend and divisor.
This is the max() function which distinguishes the maximum value from
max() the two given value.
This is the min() function which distinguishes the minimum value from
min() the two given value.
This is the pow() function which returns you the number raised to the
pow() power of a first given value by the another one.
This is the random() function which returns you the random number. It is
random() absolutely systemgenerated.
This is the rint() function which returns you a value closest to the given
rint() value.
This is the round() function which returns you a value that is in the
round() rounded form.
This is the sqrt() function which returns you the square root of the
sqrt() specified value.
String Function
Function
append()

insert()
reverse()
setCharAt()

charAt()
substring()

deleteCharAt()

length()
delete()

capacity()
Explanation
This is the append() function used for the concatenate the string in string buffer. This is better to use for dynamic string
concatenation. This function works like a simple string concatenation such as : String str = str + "added string";.

This is the insert() function used to insert any string or character at the specified position in the given string.
This is the reverse() function used to reverse the string present in string buffer.
This is the setCharAt() function which is used to set the specified character in buffered string at the specified position of the
string in which you have to set the given character.
This is the charAt() function which is used to get the character at the specified position of the given string.
This is the substring() function which is used to get the sub string from the buffered string from the initial position to end
position (these are fixed by you in the program).
This is the deleteCharAt() function which is used to delete the specific character from the buffered string by mentioning that's
position in the string.
This is the length() function is used to finding the length of the buffered string.
This is the delete() function is used to delete multiple character at once from n position to m position (n and m are will be
fixed by you.) in the buffered string.
This is the capacity() function is used to know about the current characters kept which is displayed like : number of characters
+ 6.
bin

demo
include
jre

lib
sample
COPYRIGHT
LICENSE
LICENSE.rtf
README.html

src.zip

THIRDPARTYLICENSEREADME
The bin directory provides all inessential tools for developing and testing the program through the help of command provided

This directory consists many applications and applets with source code.
It contains all header files like for 'C' programming language that enables you to combine C code into a Java program.
When you run any java program then you have to compile it by the help of Java interpreter or Java Runtime Environment (JRE
adaptation of JRE, which containing in the jre root directory.
This is a most important directory for development tools that contains libraries and it's supported files.

The jdk1.5.0 directory provides an html file that contains the detail information of SDK shown on the web browser. This file co
features and documentation links to represents all information's about the jdk1.5.0.
The zip file is a collection of one of more files that has been compressed or stored to '.zip' extension. Similarly, the scr.sip file c
It become necessary to extract the file that contain the source code from the ZIP file.
class HelloWorld { lower Proper
       public static void main(String[] args){ class
       System.out.println("Hello World!"); public static void main (
     } out.println("our text!");
}
}
Name File Name like HelloWorld
(String[] args) {
System.
}
Class
BufferedInputStream

BufferedOutputStream

BufferedReader

BufferedWriter

ByteArrayInputStream

ByteArrayOutputStream

CharArrayReader

CharArrayWriter

DataInputStream

DataOutputStream

File
FileDescriptor

FileInputStream

FileOutputStream

FilePermission

FileReader
FileWriter
FilterInputStream

FilterOutputStream

FilterReader

FilterWriter
InputStream
InputStreamReader
LineNumberReader
ObjectInputStream

ObjectInputStream.GetField

ObjectOutputStream

ObjectOutputStream.GetField

ObjectStreamClass
ObjectStreamField
OutputStream
OutputStreamWriter
PipedInputStream

PipedOutputStream

PipedReader
PipedWriter
PrintStream

PrintWriter

PushbackInputStream

PushbackReader

RandomAccessFile

Reader
SequenceInputStream

SerializablePermission
StreamTokenizer

StringReader

StringWriter
Writer
Interfaces:
The following summary of Interfaces provided by the java.io package shown in the table:
Interface
DataInput

DataOutput

Externalizable

FileFilter
FilenameFilter
ObjectInput

ObjectInputValidation

ObjectOutput

ObjectStreamConstants

Serializable

Exceptions Classes:

The following summary of the exception classes


provided by the java.io package shown in the table:
Exceptions
CharConversionException

EOFException

FileNotFoundException

InterruptedIOException

InvalidClassException

InvalidObjectException
IOException

NotActiveException

NotSerializableException

ObjectStreamException

OptionalDataException

StreamCorruptedException

SyncFaieldException

UnsupportedEncodingException
UTFDataFormatException

WriteAbortedException
Description
It used for creating an internal buffer array. It
supports the mark and reset methods.
This class used for writes byte to output stream. It
implements a buffered output stream.
This class provides read text from character input
stream and buffering characters. It also reads
characters, arrays and lines.
This class provides write text from character output
stream and buffering characters. It also writes
characters, arrays and lines.
It contains the internal buffer and read data from the
stream.
This class used for data is written into byte array. This
is implement in output stream class.
It used for char input stream and implements a
character buffer.
This class also implements a character buffer and it
uses an writer.
This class reads the primitive data types from the
input stream in a machine format.
This class writes the primitive data types from the
output stream in machine format.
This class shows a file and directory pathnames.
This class uses for create a FileInputStream and
FileOutputStream.
It contains the input byte from a file and implements
an input stream.
It uses for writing data to a file and also implements
an output stream.

It provides the permission to access a file or directory.


This class used for reading characters file.
This class used for writing characters files.
This class overrides all methods of InputStream and
contains some other input stream.
This class overrides all methods of OutputStream and
contains some other output stream.

It reads the data from the filtered character stream.


It writes data from the filtered character stream.
This class represents an input stream of bytes.
It reads bytes and decodes them into characters.
This class has a line numbers
This class used for recover the object to serialize
previously.
This class access to president fields read form input
stream.
This class used for write the primitive data types and
also write the object to read by the
ObjectInputStream.
This class access to president fields write in to
ObjectOutput.
Serialization's descriptor for classes.
This class describes the serializable field.
This class represents an output stream of bytes.
It writes bytes and decodes them into characters.
In this class the data bytes are written into piped
output stream. This class also connected into a piped
output stream.
This class also communicates the piped input stream
into piped output stream. It creates communication
between both.
It is a piped character-input stream.
It is a piped character-output stream.
This class adds the functionality of another output
stream.
This class adds the functionality of another input
stream.

It also include the another function of input stream.


Such as: "push back" or "unread" one byte.
This is a character stream reader and reads the data
push back into the stream.
It supports both reading and writing to a random
access file.
It used for reading character stream.
It represents the logical concatenation of other input
stream.
This is a serializable permission class.
It takes an input stream and parse it into "tokens" .
The token to be allowed at the read time.
This is a character string class. It has character read
source.
This is also a character string class. It uses to shows
the output in the buffer.
It uses for writing to character stream.
Interfaces:
ded by the java.io package shown in the table:
Description

This interface can be used for reading byte stream


and reconstructing the java primitive data types.
This interface can be used for writing the byte stream
and converting data from the java primitive data
types.
This is written in Serializable Stream. It save and store
it's contents.
It can be used for Filtering the Pathnames.
This interface used for Filter the Filenames.
This interface used for reading of objects and it
extends the DataInput interface.
This is a Callback interface. It allows the validation of
objects within a graph.
This interface used for writing of objects and it
extends the DataOutput interface.
This interface used for Constants writing into
Serialization Objects Stream.
This interface implementing in the java.io.Serializable
interface.

Description
It provides detail message in the catch block to
associated with the CharConversionException
This exception indicates the end of file. When the file
input stream to be end then EOFException to be
occuted.
When the open file's pathname does not find then
this exception to be occured.
When the I/O operations to interrupted from any
causes then it becomes.
Any problems to be created with class, when the
Serializing runtime to be detected.

When the de-serialized objects failed then it occurs.


When the I/O operations to be failed then it occurs.
The Serialization or deserialization operations are not
active then it occurs.
This exception when the instance is required to a
Serializable interface.
This is a supper class of all exception class. It used for
specific to Object Stream Classes.
When the reading data operations to failed then it
these exception occurs. It is belonging to the
serialized object
It thrown when the control information that was read
form an object stream vioaltes internal consistency
checks.
The sync operation is failed then SyncFaieldException
to be occure.
The Character Encoding is not supported.
A molformed UTF-8 has been read in a data input
stream, it implemented by data input interface.
In this exception to be thrown by the
ObjectStreamException during a write operating.
System.out.println("\n"); insert blank row

Você também pode gostar