Unit II
Unit II
Packages in Java
Built-in Packages:
These packages consists of a large number of classes which are a part of Java
API.
For e.g: we have used java.io package previously which contain classes to
support input / output operations in Java. Similarly, there are other packages
which provides different functionality.
Some of the commonly used built-in packages are shown in the table below :
Package
Description
Name
Contains language support classes ( for e.g classes which defines
java.lang primitive data types, math operations, etc.) . This package is
automatically imported.
java.io Contains classes for supporting input / output operations.
Contains utility classes which implement data structures like
java.util Linked List, Hash Table, Dictionary, etc and support for Date /
Time operations.
java.applet Contains classes for creating Applets.
Contains classes for implementing the components of graphical
java.awt
user interface ( like buttons, menus, etc. ).
java.net Contains classes for supporting networking operations.
1
1 ) import java.util.Vector; // import the Vector class from util package
or
2 ) import java.util.*; // import all the class from util package
User-defined packages:
➢ Creating a Package:
While creating a package, you should choose a name for the package and
include a package statement along with that name at the top of every
source file that contains the classes, interfaces, enumerations, and
annotation types that you want to include in the package.
The package statement should be the first line in the source file. There can be
only one package statement in each source file, and it applies to all types in the
file.
To compile the Java programs with package statements, you have to use -d
option as shown below.
You need to use fully qualified name e.g. mypack.Simple etc to run the class.
➢ Importing Packages
either an explicit classname or a star (*), which indicates that the Java
compiler should import the entire package.
ForExample:
import java.util.Scanner;
import java.io.*;
• The basic language functions are stored in a package inside of the java
package called java.lang. (Default Package)
• This is equivalent to the following line being at the top of all of your
programs:
• import java.lang.*;
There are three ways to access the package from outside the package.
• import package.*;
• import package.classname;
• fully qualified name.
3
public static void main(String import pack.A;
args[]){
A obj = new A(); class B{
obj.msg(); public static void main(String
} } args[]) {
A obj = new A();
obj.msg();
Complile: javac –d . B.java }
//(Because MainMethod occurs at }
B.java)
Output:Hello
Interfaces
Defining an Interface
Syntax:
access interface name {
return-type method-name (parameter-list); //Abstract Method
type final-varname1 = value;
type final-varname2 = value; //variables
default method-name (parameter-list)
{ //default method body; }
4
In other words, Interface fields are public, static and final by default, and the
methods are public and abstract.
Implementing Interfaces
➢ Once an interface has been defined, one or more classes can inherit that
interface by using implements Keyword
Syntax:
If a class implements more than one interface, the interfaces are separated
with a comma.
As shown in the figure given below, a class extends another class, an interface
extends another interface, but a class implements an interface.
Nested Interfaces
5
➢ A nested interface can be declared as public, private, or protected. This
differs from a top-level interface, which must either be declared as public or
use the default access level, as previously described.
➢ When a nested interface is used outside of its enclosing scope, it must be
qualified by the name of the class or interface of which it is a member.
Thus, outside of the class or interface in which a nested interface is
declared, its name must be fully qualified
class A {
// this is a nested interface
public interface NestedIF {
boolean isNotNegative(int x);
}
}
// B implements the nested interface.
class B implements A.NestedIF { //nested interface Declaration
public boolean isNotNegative(int x)
{ return x < 0 ? false : true; }
}
class NestedIFDemo {
public static void main(String args[]) {
A.NestedIF nif = new B(); // use a nested interface reference
if(nif.isNotNegative(10))
{ System.out.println("10 is not negative"); }
if(nif.isNotNegative(-12))
{ System.out.println("this won't be displayed"); }
}
}
Note:
Notice that A defines a member interface called NestedIF and that it is
declared public. Next, B implements the nested interface by specifying
implements A.NestedIF
Notice that the name is fully qualified by the enclosing class’ name. Inside the
main( ) method, an A.NestedIF reference called nif is created, and it is
assigned a reference to a B object. Because B implements A.NestedIF, this is
legal.
Applying Interfaces
6
➢ used to achieve abstraction.
Output:
drawing circle
interface Printable{
void print();
}
interface Showable{
void show();
}
7
class A implements Printable,Showable{
class A7
{
public static void main(String args[]){
A obj = new A();
obj.print();
obj.show();
}
}
Output:Hello Welcome
Interface inheritance
interface Printable{
void print();
}
interface Showable extends Printable{
void show();
}
class TestInterface4 implements Showable{
public void print(){System.out.println("Hello");}
public void show(){System.out.println("Welcome");}
Output:
Hello
Welcome
interface Drawable{
8
void draw();
default void msg(){System.out.println("default method");}
}
class Rectangle implements Drawable{
public void draw(){System.out.println("drawing rectangle");}
}
class TestInterfaceDefault{
public static void main(String args[]){
Drawable d=new Rectangle();
d.draw();
d.msg();
}}
Output:
drawing rectangle
default method
interface Drawable{
void draw();
static int cube(int x){return x*x*x;}
}
class Rectangle implements Drawable{
public void draw(){System.out.println("drawing rectangle");}
}
class TestInterfaceStatic{
public static void main(String args[]){
Drawable d=new Rectangle();
d.draw();
System.out.println(Drawable.cube(3));
}}
Output:
drawing rectangle
27
Difference between abstract class and interface
9
3) Abstract class can have final,
Interface has only static and final
non-final, static and non-static
variables.
variables.
4) Abstract class can provide the Interface can't provide the
implementation of interface. implementation of abstract class.
5) The abstract keyword is used to The interface keyword is used to
declare abstract class. declare interface.
6) An abstract classcan extend
An interface can extend another Java
another Java class and implement
interface only.
multiple Java interfaces.
7) An abstract classcan be extended An interface classcan be implemented
using keyword ?extends?. using keyword ?implements?.
8) A Javaabstract classcan have
Members of a Java interface are public
class members like private,
by default.
protected, etc.
9)Example: Example:
public abstract class Shape{ public interface Drawable{
public abstract void draw(); void draw();
} }
Java I/O (Input and Output) is used to process the input and produce the
output.
Java uses the concept of a stream to make I/O operation fast. The java.io
package contains all the classes required for input and output operations.
Streams
Java performs I/O through Streams. A Stream is linked to a physical layer by java I/O
system to make input and output operation in java. In general, a stream means
continuous flow of data. Streams are clean way to deal with input/output without
having every part of your code understand the physical.
In Java, 3 streams are created for us automatically. All these streams are
attached with the console.
1) System.out: standard output stream
10
2) System.in: standard input stream
3) System.err: standard error stream
1. ByteStreams
2. CharecterStreams
Byte Streams:
➢ A Byte stream will read a file Byte by Byte.
➢ Byte stream is defined by using two abstract class at the top of hierarchy,
they are InputStream and OutputStream.
➢ Java byte streams are used to perform input and output of 8-bit bytes.
Though there are many classes related to byte streams but the most
frequently used classes are, FileInputStream and FileOutputStream.
➢ These two abstract classes have several concrete classes that handle
various devices such as disk files, network connection etc.
11
Output stream that writes to a byte array
ByteArrayOutputStream
PipedInputStream
Input pipe
These classes define several key methods. Two most important are
12
FileInputStream Class
Java FileInputStream class obtains input bytes from a file. It is used for reading byte-
oriented data (streams of raw bytes) such as image data, audio, video etc. You can also
read character-stream data.
Syntax:
FileInputStream(String filepath)
FileInputStream(File fileObj)
forExample:
FileInputStream f0 = new FileInputStream("abc.txt")
or
File f = new File("abc.txt");
FileInputStream f1 = new FileInputStream(f);
fin.close();
}catch(Exception e){System.out.println(e);}
}
}
Output: W
read all characters:
import java.io.FileInputStream;
public class DataStreamExample {
public static void main(String args[]){
try{
FileInputStream fin=new FileInputStream("D:\\testout.txt");
int i=0;
while((i=fin.read())!=-1){
System.out.print((char)i);
}
fin.close();
}catch(Exception e){System.out.println(e);}
}
13
}
Output: Welcome to java
FileOutputStream Class:
Syntax:
FileOutputStream(String filePath)
FileOutputStream(File fileObj)
FileOutputStream(String filePath, boolean append)
FileOutputStream(File fileObj, boolean append)
They can throw a FileNotFoundException. Here, filePath is the full path name of a
file, and fileObj is a File object that describes the file. If append is true, the file is
opened in append mode.
write byte:
import java.io.FileOutputStream;
public class writestring {
public static void main(String args[]){
try{
FileOutputStream fout=new FileOutputStream("D:\\testout.txt");
String s="Welcome to JAVA.";
byte b[]=s.getBytes();//converting string into byte array
fout.write(b);
14
fout.close();
System.out.println("success...");
}catch(Exception e){System.out.println(e);}
}
}
import java.io.FileOutputStream;
public class writestring {
public static void main(String args[]){
try{
FileOutputStream fout=new FileOutputStream("D:\\testout.txt",true);
String s="\nWelcome to JAVA.";
byte b[]=s.getBytes();//converting string into byte array
fout.write(b);
fout.close();
System.out.println("success...");
}catch(Exception e){System.out.println(e);}
}
}
import java.io.*;
public class CopyFile {
try {
in = new FileInputStream("input.txt");
out = new FileOutputStream("output.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
}finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
15
}
}
BufferedInputStream class BufferedOutputStream class
Java BufferedInputStream class is used Java BufferedOutputStream class is
to read information from stream. It used for buffering an output stream. It
internally uses buffer mechanism to internally uses buffer to store data. It
make the performance fast. adds more efficiency than to write data
directly into a stream. So, it makes the
performance fast.
Syntax: Syntax:
BufferedInputStream(InputStream BufferedOutputStream(OutputStream
inputStream) outputStream)
or or
BufferedInputStream(InputStream BufferedOutputStream(OutputStream
inputStream, int bufSize) outputStream, int bufSize)
16
ByteArrayInputStream class ByteArrayOutputStream class
The ByteArrayInputStream is composed Java ByteArrayOutputStream class is
of two words: ByteArray and used to write common data into
InputStream. As the name suggests, it multiple files. In this stream, the data is
can be used to read byte array as input written into a byte array which can be
stream. written to multiple streams later.
The ByteArrayOutputStream holds a
Java ByteArrayInputStream class copy of data and forwards it to multiple
contains an internal buffer which is used streams.
to read byte array as stream. In this The buffer of ByteArrayOutputStream
stream, the data is read from a byte automatically grows according to data.
array.
The buffer of ByteArrayInputStream
automatically grows according to data.
Syntax: Syntax:
ByteArrayOutputStream( )
ByteArrayInputStream(byte array[ ]) or
or ByteArrayOutputStream(int numBytes)
ByteArrayInputStream(byte array[ ], int
start, int numBytes)
Output: Output:
17
ASCII value of Character is:38; Special
character is: &
SequenceInputStream Class:
Java SequenceInputStream class is used to read data from multiple streams. It reads
data sequentially (one by one).
Syntax:
SequenceInputStream(InputStream first, InputStream second)
or
SequenceInputStream(Enumeration <? extends InputStream> streamEnum)
(This constructor u can find by Enumeration process)
18
import java.io.*;
class InputStreamExample {
public static void main(String args[])throws Exception{
FileInputStream input1=new FileInputStream("D:\\testin.txt");
FileInputStream input2=new FileInputStream("D:\\testout.txt");
SequenceInputStream inst=new SequenceInputStream(input1, input2);
int j;
while((j=inst.read())!=-1){
System.out.print((char)j);
}
inst.close();
input1.close();
input2.close();
}
}
Here, we are assuming that you have two files: testin.txt and testout.txt which have
following information:
testin.txt:
Welcome to Java IO Programming.
testout.txt:
It is the example of Java SequenceInputStream class.
After executing the program, you will get following output:
Output: Welcome to Java IO Programming. It is the example of Java
SequenceInputStream class.
Character Stream Classes
A character stream will read a file character by character. Character Stream is a
higher level concept than Byte Stream .
Java Byte streams are used to perform input and output of 8-bit bytes,
whereas Java Character streams are used to perform input and output for 16-
bit unicode. Though there are many classes related to character streams but
the most frequently used classes are, FileReader and FileWriter.
Character stream is also defined by using two abstract class at the top of
hierarchy, they are Reader and Writer.
Reader
19
Reader is an abstract class that defines Java’s model of streaming character input. It
implements the Closeable and Readable interfaces. All of the methods in this class
(except for markSupported( )) will throw an IOException on error conditions.
Writer
Writer is an abstract class that defines streaming character output. It implements the
Closeable, Flushable, and Appendable interfaces. All of the methods in this class
throw an IOExceptionin the case of errors.
These two abstract classes have several concrete classes that handle unicode
character.
FilterReader
Filtered reader
PipedReader
Input pipe
20
Output Stream that contain print() and println()
PrintWriter
method.
FileReader Class
Java FileReader class is used to read data from the file. It returns data in byte format
like FileInputStream class. It is character-oriented class which is used for file handling
in java.
Syntax:
FileReader(String filePath)
FileReader(File fileObj)
Either can throw a FileNotFoundException. Here, filePath is the full path name of a
file, and fileObj is a File object that describes the file.
import java.io.FileReader;
public class FileReaderExample {
public static void main(String args[])throws Exception{
FileReader fr=new FileReader("D:\\testout.txt");
int i;
while((i=fr.read())!=-1)
System.out.print((char)i);
fr.close();
}
}
Here, we are assuming that you have following data in "testout.txt" file:
Welcome to JAVA.
Output:
Welcome to JAVA.
21
FileWriter Class
Syntax:
import java.io.FileWriter;
public class FileWriterExample {
public static void main(String args[]){
try{
FileWriter fw=new FileWriter("D:\\testout.txt");
fw.write("Welcome to JAVA.");
fw.close();
}catch(Exception e){System.out.println(e);}
System.out.println("Success...");
}
}
Output: Success...
testout.txt: Welcome to JAVA.
Copying From one File to another by using FileReader and FileWriter classes:
import java.io.*;
public class CopyFile {
try {
in = new FileReader("input.txt");
out = new FileWriter("output.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
}finally {
if (in != null) {
22
in.close();
}
if (out != null) {
out.close();
}
}
}
}
23
}
}
Output: Output:
Welcome to JAVA. success
24
out.writeTo(f1);
Output out.writeTo(f2);
out.writeTo(f3);
j : 106 out.writeTo(f4);
a : 97 f1.close();
v : 118 f2.close();
a : 97 f3.close();
t : 116 f4.close();
p : 112 System.out.println("Success...");
o : 111 }
i : 105 }
n : 110
t : 116 Output
Success...
a.txt:
Welcome to JAVA
b.txt:
Welcome to JAVA
c.txt:
Welcome to JAVA
d.txt:
Welcome to JAVA
25
PrintStream(OutputStream PrintWriter(Writer outputStream, boolean
outputStream) flushOnNewline)
PrintStream(OutputStream
outputStream, boolean flushOnNewline) Here, outputStream specifies an open
PrintStream(OutputStream OutputStream that will receive output.
outputStream, boolean flushOnNewline, The flushOnNewline parameter controls
String charSet) whether the output buffer is
automatically flushed every time println(
), printf( ), or format( ) is called. If
flushOnNewline is true, flushing
automatically takes place. If false,
flushing is not automatic. Constructors
that do not specify the flushOnNewline
parameter do not automatically flush.
2016 Output:
Hello Java
Welcome to Java JAVA provides tutorials of all technology.
26
Reading console Input and Writing Console Output:
In Java, there are three different ways for reading input from the user in the command
line environment(console).
This is probably the most preferred method to take input. The main purpose of the Scanner class is to
parse primitive types and strings using regular expressions, however it is also can be used to read input
from the user in the command line.
import java.util.Scanner;
class GetInputFromUser
{
public static void main(String args[])
{
// Using Scanner for Getting Input from User
Scanner in = new Scanner(System.in);
String s = in.nextLine();
System.out.println("You entered string "+s);
int a = in.nextInt();
System.out.println("You entered integer "+a);
float b = in.nextFloat();
System.out.println("You entered float "+b);
}
}
27
In Java, console input is accomplished by reading from System.in. To obtain a
characterbased stream that is attached to the console, wrap System.in in a
BufferedReader object.
Here, inputReader is the stream that is linked to the instance of BufferedReader that
is being created.
Reader is an abstract class. One of its concrete subclasses is InputStreamReader,
which converts bytes to characters.
To obtain an InputStreamReader object that is linked to System.in, use the following
constructor:
InputStreamReader(InputStream inputStream)
Putting it all together, the following line of code creates a BufferedReader that is
connected to the keyboard:
28
BufferedReader br = new // create a BufferedReader using
BufferedReader(new System.in
InputStreamReader(System.in)); BufferedReader br = new
System.out.println("Enter characters, 'q' BufferedReader(new
to quit."); InputStreamReader(System.in));
// read characters String str;
do { System.out.println("Enter lines of text.");
c = (char) br.read(); System.out.println("Enter 'stop' to quit.");
System.out.println(c); do {
} while(c != 'q'); str = br.readLine();
} } while(!str.equals("stop"));
} }
}
Here is a sample run:
➢ Java SE 6 adds the Console class. It is used to read from and write to
the console, if one exists.
➢ Console is primarily a convenience class because most of its
functionality is available through System.in and System.out.
Syntax:
29
import java.io.*;
class ConsoleDemo {
public static void main(String args[]) {
String str;
Console con = System.console(); // Obtain a reference to the console.
str = con.readLine("Enter a string: "); // Read a string and then display it.
System.out.println(str);
}
}
RandomAccessFile
• here fileObj specifies the name of the file to open as a File object.
• In the second form, the name of the file is passed in filename.
• In both cases, access determines what type of file access is permitted.
File Access parameter as:
• If it is “r”, then the file can be read, but not written.
• If it is “rw”, then the file is opened in read-write mode.
30
• If it is “rwd”, the file is opened for read-write operations and every change
to the file’s data will be immediately written to the physical device.
➢ The method seek( ), shown here, is used to set the current position of the
file pointer within the file:
}
}
Constructor Description
File(File parent, It creates a new File instance from a parent abstract
String child) pathname and a child pathname string.
It creates a new File instance by converting the given
File(String pathname)
pathname string into an abstract pathname.
31
File(String parent, It creates a new File instance from a parent pathname
String child) string and a child pathname string.
It creates a new File instance by converting the given
File(URI uri)
file: URI into an abstract pathname.
Syntax(Constructors):
For example:
File defines many methods that obtain the standard properties of a File object.
// Demonstrate File.
import java.io.File;
class FileDemo {
static void p(String s) {
System.out.println(s);
32
}
public static void main(String args[]) {
File f1 = new File("/java/COPYRIGHT");
p("File Name: " + f1.getName());
p("Path: " + f1.getPath());
p("Abs Path: " + f1.getAbsolutePath());
p("Parent: " + f1.getParent());
p(f1.exists() ? "exists" : "does not exist");
p(f1.canWrite() ? "is writeable" : "is not writeable");
p(f1.canRead() ? "is readable" : "is not readable");
p("is " + (f1.isDirectory() ? "" : "not" + " a directory"));
p(f1.isFile() ? "is normal file" : "might be a named pipe");
p(f1.isAbsolute() ? "is absolute" : "is not absolute");
p("File last modified: " + f1.lastModified());
p("File size: " + f1.length() + " Bytes");
}
}
Output:
File Name: COPYRIGHT
Path: /java/COPYRIGHT
Abs Path: /java/COPYRIGHT
Parent: /java
exists
is writeable
is readable
is not a directory
is normal file
is absolute
File last modified: 812465204000
File size: 695 Bytes
33
String st; BufferedWriter bw = new
while ((st = br.readLine()) != BufferedWriter(fw);
null)
System.out.println(st); String st="Object Oriented
} Programing ";
bw.write(st);
} bw.close();
}}
Serialization
The Java facilities for serialization and deserialization have been designed so
that much of the work to save and restore the state of an object occurs
automatically.
However, these cases in which the programmer may need to have control over
these processes. For example, it may be desirable to use compression or
encryption techniques.
34
public static void main(String args[]) {
// Object serialization
try {
MyClass object1 = new MyClass("Hello", -7, 2.7e10);
System.out.println("object1: " + object1);
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(object1);
oos.flush();
oos.close();
}
catch(IOException e) {
System.out.println("Exception during serialization: " + e);
System.exit(0);
}
// Object deserialization
try {
MyClass object2;
FileInputStream fis = new FileInputStream("serial");
ObjectInputStream ois = new ObjectInputStream(fis);
object2 = (MyClass)ois.readObject();
ois.close();
System.out.println("object2: " + object2);
}
catch(Exception e) {
System.out.println("Exception during deserialization: " + e);
System.exit(0);
}
}
}
class MyClass implements Serializable {
String s;
int i;
double d;
public MyClass(String s, int i, double d) {
this.s = s;
this.i = i;
this.d = d;
}
public String toString() {
return "s=" + s + "; i=" + i + "; d=" + d;
}
}
35
Enumerations
The java enum constants are static and final implicitly. It is available from JDK
1.5.
Enumeration is a list of named constants, and these Java enumerations define
a class type. By making enumerations into classes
Java Enums can be thought of as classes that have fixed set of constants.
• enum improves type safety
• enum can be easily used in switch
• enum can be traversed
• enum can have fields, constructors and methods
• enum may implement many interfaces but cannot extend any class
because it internally extends Enum class
Example:
class EnumExample1{
public enum Season { WINTER, SPRING, SUMMER, FALL }
}}
Output:
WINTER
SPRING
SUMMER
FALL
class EnumExample4{
36
enum Season{
WINTER(5), SPRING(10), SUMMER(15), FALL(20);
}}
Output:WINTER 5
SPRING 10
SUMMER 15
FALL 20
AutoBoxing
The automatic conversion of primitive data types into its equivalent Wrapper
type is known as boxing and opposite operation is known as unboxing. This is
the new feature of Java5. So java programmer doesn't need to write the
conversion code.
Example:
class BoxingExample1{
public static void main(String args[]){
int a=50;
Integer a2=new Integer(a);//Boxing
37
Integer a3=5;//Boxing
System.out.println(a2+" "+a3);
}
}
Output:50 5
Unboxing Example:
The automatic conversion of wrapper class type into corresponding primitive
type, is known as Unboxing. Let's see the example of unboxing:
class UnboxingExample1{
public static void main(String args[]){
Integer i=new Integer(50);
int a=i;
System.out.println(a);
}
}
Generics
The term generics means parameterized types. Parameterized types are
important because they enable you to create classes, interfaces, and methods
in which the type of data upon which they operate is specified as a parameter.
Thus, generics expand your ability to reuse code and let you do so safely and
easily.
The type parameters naming conventions are important to learn generics
thoroughly. The commonly type parameters are as follows:
1. T - Type
2. E - Element
3. K - Key
4. N - Number
5. V – Value
Generics Work Only with Objects
When declaring an instance of a generic type, the type argument passed to the
type parameter must be a class type. You cannot use a primitive type, such as
int or char.
For example, with Gen, it is possible to pass any class type to T, but you
cannot pass a primitive type to a type parameter.
ForExample:
38
class MyGen<T>
{
T obj;
T get()
{return obj;}
}
m.add(2);
//m.add("vivek");//Compile time error
System.out.println(m.get());
Output:
2
Example 2 Example 3
public class testgeneric1 { Example3:
public static < E > void // A simple generic class with two
printArray(E[] elements) { type
for ( E element : elements){ // parameters: T and V.
System.out.println(element ); class TwoGen<T, V> {
} T ob1;
System.out.println(); V ob2;
} // Pass the constructor a reference to
public static void main( String // an object of type T and an object
args[] ) { of type V.
Integer[] intArray = { 10, 20, 30, TwoGen(T o1, V o2) {
40, 50 }; ob1 = o1;
Character[] charArray = { 'J', 'A', ob2 = o2;
'V', 'A', 'T','P','O','I','N','T' }; }
// Show types of T and V.
System.out.println( "Printing void showTypes() {
Integer Array" ); System.out.println("Type of T is " +
printArray( intArray ); ob1.getClass().getName());
System.out.println("Type of V is " +
ob2.getClass().getName());
39
System.out.println( "Printing }
Character Array" ); T getob1() {
printArray( charArray ); return ob1;
} }
} V getob2() {
Output: return ob2;
Printing Integer Array }
10
20 }
30 public class testgeneric2
40 {
50 public static void main(String
args[]) {
Printing Character Array
J TwoGen<Integer, String> tgObj =
A new TwoGen<Integer, String>(88,
V "Generics");
A // Show the types.
T tgObj.showTypes();
P
O // Obtain and show values.
I int v = tgObj.getob1();
N System.out.println("value: " + v);
T String str = tgObj.getob2();
System.out.println("value: " + str);
} }
}
Output:
Type of T is java.lang.Integer
Type of V is java.lang.String
value: 88
value: Generics
40