You are on page 1of 20

JAVA

1.JDBC
java data base conectivity
it is jav api to connect and execute the query with the data base

2.JDBC API
to connect and acces the data in database

3.types of drivers in JDBC


1.JDBC ODBC bridge driver
2.Native driver
3.n/w protocal driver
4.thin driver

4.Why JDBC
ODBC is platoform dependent and JDBC is paltform independent and secure

5.what are the ways to connect data base


1.regiaster the driver class
2.create connection
3.create ststement
4.execute queries
5.close connection

6.What JDBC API will do


1.connect to data base
2.execute the quieries and update staements the statements to data base
3.retrieving the results from data base

7.how to register the class in JDBC


class.forName("oracle.jdbc.odbc.OracleDriver");

8.How to create connection


by using getConnection()
Connection con=DriverManager.getConnection(jdbc.odbc,"username","password");

9.How to create a statement?


by using createStatement()
Statement st=con.createStatement();

10.How to execute the executequieries?


by using executeQuery()
ResultSet rs=st.executeQuery();

11.How to close the connection?


con.close();
note:if the connection is closed the result set and statement will be closed
automatically

12.What is CallableStatement interface?


it is used to call the stored procedures and functions

Regex/Regular expression

1.java regular expression?


javaregex/regular expression is an API to define a pattern for searching or
manupulating strings.
it is used for password and email validation for strings
2.How many classes and interfaces in regex?
java regex provides 1 interface and 3 classes
1.MatchResult interface
2.Matcher class
3.Pattern class
4.PetternSyntaxExecption class

3.What is the package of regex?


java.Util.regex;

4.How the meta characters are differ from ordinary characters?


meta characters have the spl meaning to the regular expression
the meta characters are ^,*,$,+,.,

5.Write a regualr expreesion to validate a password


a password must start with an alphabet and followed by alpha numeric characters
the length must be in b/w 8-20

^[A-Za-z][A-Za-z0-9]{8-19}

Collections

1.collection frame work in java


collection frame work is a combination of classes and interface which is
used to store and manupulate data in the form of objects

2.Clasees in collection
1.ArrayList
2.Vector
3.Stack
4.HashSet

3.Interfaces incollection
1.List
2.Set
3.Queue

4.diff b/w array and collection


array:
its size is fixed
it stores homogeneous object
no instance method /build in methods
collection:
its size is dynamically changes
it store heterogeneous object
build in methods are avilable

5.various interfaces used in collections frame work


1.Collection
2.List
3.Set
4.Queue
5.Dequeue
6.Map

6.What is Collection interface?


Collection interface is a primary interface and every collection must
implement this interface
java.Util.Collection;
public Interface Collection<E> Iterable

7.What is List Interface?


List interface extends Collection interface
it is ordered collection of objects
it contains duplicate elements
random acess of element is possible in list
java.Util.List;
public Interface List<E> extends Collection<E>

8.Waht is set?
java.Util.Set;
it does'nt contains duplicate elements
it can only include inherited methods of Collection Interface
public Interface Set<E> extends Collection<E>

9.Queue
it is a Collection which defines a queue data structure
which stores the element in the form of FIFO
public Interface Queue<E> extends Collection<E>
java.Util.Queue;

10.Dequeue
it is a double needed queue
it allows the insertion and removal of elements from both ends
it can perform both stack and queue operations LIFO & FIFO
public Interface Dequeue<E> extends Collection<E>
java.Util.Dequeue;

11.Map?
it does not implement with any Collection Interface
it has key value pairs to store the elements
unique key and value may be duplicated
it consiste of two interfacse
1.Map Interfcae
2.Sorted Map

12.Diff b/w arraylist nad vector


ArrayList:
it is not synchronized
it is a legacy class
it increases size by "half its array size"
it is not thread safe
vector:
it is synchronized
it is legacy class
it increses size by "double the array size"
it is a thread safe
13.diff b/w arraylist nad linked list
ArrayList:
it uses dynamic array
ArrayList is not effeienct for manipiulation bcz too much data is required
it is better to store and fetch data
ArrayList provide random access of element
it takes less memory as it stores only object
LinkedList:
it uses double linked list
it ias efficient for manipulation
it is used only for manupiulation
it does not have random access of element
has more element as it store object as wel as the address of the object

14.Diff b/w Iterator and ListIterator?


Iterator:
it traverse the elements in forward direction only
they can be used in list,set and queue
it can only perform remove operation while traversing the elements
ListIterator:
it traverse the elements in forward direction as well as backward directions
it can be used in List only
it can perform add,remove while traversing the elements

15.Iterator and enumeration


Iterator:
it can only perform remove operation while traversing the elements
it can traval both legacy and non legacy
it is fast
enumeration:
it can not remove but perform only traversing(visiting)
it is not fast
it can traval only legacy elements

16.List and Set


List:
duplicate elements
maintains insertion order(ordered collection)
single legacy class(vector)
allow n number of null values
Set:
unique elments
unordered collection
does not contain any legacy class
allow only one null value

17.HashSet and TreeSet?


HashSet:
maintains no order
implemented by hash table
it is faster
it is maintened by HashMap
TreeSet:
maintains asscending order
implemented by tree searcher
it is not faster than hash set
it is maintened by TreeMap
18.HashMap and TreeMap
HashMap:
maintains no order
implemented by hash table
to sort,using key or value
contain null key and multiple null values
TreeMap:
maintains asscending order
implemented by tree searcher
it can be sorted by only key
it cannot hold a null key but can have multiple null values
19.HashMap and HashTable
HashMap:
it is not synchronized
it contains 1 null key and multiple null values
it inherit AbstractMap class
HashTable:
it is synchronized
it does not have any null key or null values
it inherit Dictionary class

20.Collection and collections


Collection:
it is an interface
it provide standard fuctionality to list,set and queue
it provide methods that can be used for data struture
Collections:
it is class
it is be for sort and synchronise collections element
it provide the static method which can be used for various operation on
collection

21.Comparable and Comparator


Comparable:
it provides only one sort of sequence
compareTO() is used
java.Util
the actual class is modified

Comparator:
it provides multiple sl
java.Lang
the actual class is not modified

22.blocking queue?
it extends Queue interface.it provides concurrency in operations like
retrievel,deletion,insertion and storing
it is thread safe
public Interface Blockingqueue<E> extends Queue<E>

23.property file?adv of property file?


it contains all the details,information
if we want change property file,we no need to compile java class
so,it make application easy to manage
it is used to store info,which is to be changed frequently

24.hashCode()
it returns only integer value
it returns same integer number,if two keys are identical by calling equal()
how ever,it is possible that two hashCode numbers can have diff other same
keys

25.why we override equals()?


it need to be overridden,if we want to check the objects based on the
property

26.How to synchronize list,set and map elements?


public static List synchronizedList(List l){
}
public static Set synchronizedSet(Set s){
}
public static Map synchronizedMap(Map m){
}
27.adv of generic collection
1.no need to type casting
2.generic confirms stability of the code by making bug detecting in the
compile time
3.checked compiled time exception will be thrown

28.hash collision in hash table?


two diff keys with same hash values is known as hash collision
two seperate entries will be kept in a single hash bucket to avoid the
collision
two ways to avoid collision
seperate trying
open addressing
29.dictionary class
it provide the capability to store key value pairs

30.default size of load factor in hashing?


load factor=0.75

31.diff b/w array and ArrayList


array:
fixed size
it is static type
it store primitive data type as well asd objects
ArrayList:
it is not fixed size,we can change size dynamically
it is dynamic type
it cannot store primitive data type,can store only object

32.diff b/w length array and size() array


int[] arr=new int[5];
system.out.println(arr.length);
ArrayList<String> a=new ArrayList<String>();
a.add("sathya");
a.add("sai");
system.out.println(a.size());

33.How to convert array to ArrayList and ArrayList to array?


asList()is used to convert from array to ArrayList
toArray()is used to convert from ArrayList to array

34.How to make java ArrayList read only?


By calling Collections.unmodifiableCollection()

35.How to remove duplicates from ArrayList?


HashSet
LinkedHashList
36.How to reverse ArrayList?
reverse()
37.How will youn sort ArrayList in descding order?
reverseOrder()
38.How to synchronize ArrayList?
we can synchronize ArrayList by two ways
Collections.synchronizedList();
copyOnWriteArrayList<T>

39.When to use ArrayList and LinkedList?


LinkedList is uesd for update operation
ArrayList is used for searching operation

40.Iteartor
It is used in Collections frame work to retrieve the elements one by one

41.diff b/w next() nad hasNext()


hasNext():
it returns true when you have more values
next():
it will return the next element in iteration

STRINGS
1.String?
it is an object that represents sequence of character values.
the array of characters is same as java string
char[] c={'c','a'}
String s=new string("char");

2.interfaces in string?
Serializable
Comparable
CharSequence

3.packages for string?


java.lang.String;

4.how to create a string object?


1.one by string literal
2.by new keyword

5.how to create string by string literal?


each time we create a string literal,JVM checks the vlaue in string pool to
know if it exists or not
if it is present,the refrence of string is used
it it is not present,new instance is created in the pool
String s="char";
String s1="char";

6.how to create string by new keyword?


the JVM will create a new string object in heap memory/non string pool and
string literal is placed in the string pool
String s=new string("char");

7.why java uses concept of string literal?


to make java memory more efficient.No new object are created because
already the object vare existed in string constant pool

8.which class is immutable in java?


in java String objects are immutable(unmodifible nad unchangeble)
String s="ram"
s.concat("kumar");
once a string object is created, the data cant be changed but a new string
object is created it is possible
String s="ram"
s1=s.concat("kumar");

9.why String is immutable?


java uses the concept of java string literal
consider there are five reference variables,all refers to 1 object
if one refrence variable change the value of object,it will effect all the
reference variable
so,string is immutable in java

10.What the the ways to comapre string in java?


equals()
== operator
compareTo()

11.How will you comapre by equals()?


String s1="Ram"
String s2="Ram"
String s3="kumar"
Sop(s1.equals(s2));
Sop(s2.equals(s3));

12.How will you comapre by "=="?


String s1="Ram"
String s2="Ram"
String s3="kumar"
Sop(s1==s2);
Sop(s2==s3);

13.compareTo()?
it compares the values lexico graphically and returns the integer value
if(s1==s2)
return 0;
if(s1>s2)
return 1;
if(s1<s2)
return -1;
String s1="Ram"
String s2="Ram"
String s3="kumar"
Sop(s1.compareTo(s2));
Sop(s2compareTo(s3));

14.ways to concat string?


by using "+" operator and concat()

15.substring() in java?
a part of string is subString
a subString is subset of another string
String s="java program"
s.subString(6);
s.subString(0,3);

16.What are java String class methods in java?


it is used to work on string.it can provide operations such as
trimming,concatenating,comparing,replacing string etc.,
methods are:
toUpperCase();
toLowerCase();
strtsWith();
endsWith();
valueOf();
replace();
length();
17.What is java StringBuffer class?
it is used to create an mutable(modifiable string).
StringBuffer class in java is same as String class the only diff is mutable

18.What is mutable string?


a string which can be modifiable/changeble in known as mutable
StringBuffer and StringBuilder are mutable strings in java

19.StringBuffer append()?
StringBuffer sb=new StringBuffer("java");
sop(sb.append("program"));

20.StringBuffer insert()?
it insert the given string with this string at the given position
StringBuffer sb=new StringBuffer("java");
sop(sb.insert(1,"program"));
O/P:jprogramava

21.StringBuffer replace()?
it replace the given string from the specified begin index and end index
StringBuffer sb=new StringBuffer("java");
sop(sb.replace(1,3,"program"));

22.StringBuffer delet()?
it delet string from specified begin index to end index
StringBuffer sb=new StringBuffer("java");
sop(sb.delet(1,3));
O/P:a

23.StringBuffer reverse()?
it is used to reverse the current string
StringBuffer sb=new StringBuffer("java");
sop(sb.reverse);
O/P:avaj

24.StringBuffer capacity()?
the capacity() of StringBuffer the current capacity of buffer
the default capacity of buffer is 16,
if nbr of characters increases from the current capacity,then it will be old
capacity*2+2=32;

25.What is StringBuilder?
it is used to create mutable(modifiable)
it is same as StringBuffer class but the diff is it is not thread safe
unlike stringBuffer,it is not synchronized

26.StringBiulder append()?
StringBuffer sb=new StringBuffer("java");
sop(sb.append("program"));

27.StringBuilder insert()?
StringBuffer sb=new StringBuffer("java");
sop(sb.insert(1,"program"));

28.StringBuilder replace()?
StringBuffer sb=new StringBuffer("java");
sop(sb.replace(1,3,"program"));
29.StringBuilder delet()?
StringBuffer sb=new StringBuffer("java");
sop(sb.delet(1,3));

30.StringBuilder reverse()?
StringBuffer sb=new StringBuffer("java");
sop(sb.reverse);

31.StringBuilder capacity()?

32.diff b/w string and stringBuffer?


string:
immutable class
it consumes more memory when yuou voncart two many strings
it overrides equals() of object class
stringBuffer:
mutable class
it is fast and consumes less mmemory when you concat strings
it can not override equals() of object class

33.diff b/w StringBuffer and StringBiulder?


StringBuffer:
it is synchroniozed i.e, thread safe(two threads cant cal the methods of
simultaneously)
it is less efficient than StringBuilder
StringBuilder:
it is not synchronized i.e., not thread safe(two threads can cal the methods
of simultaneously)
it is more efficient
34.How to create immutable class?
we can create immutable class by creating final class that has final data
members
public final class student{
final String id;
public Student(String id){
this.id=id;
}
public String getId(){
return id
}
}

35.toString()?
if we want to represent any object as a String,this method is used

36.adv of toString()?
to override toString() in object class,we can return the values of the
object.so we no need to write much code

37.StringTokenizer()?
this comes under Util package
it allows to break,the strings ointo Tokens
38.methods in StringTokenizer()?
6 methods
1.hasMoreTokens()
this is used when more tokens are allowed
2.nextToken()
it returns next token
3.nextToken(String delimiter)
it returns next token from delimiter
4.hasMoreElements()
5.nextElement()
6.countTokens()

39.charAtr()?
it returns the character value at the given index nbr
the index nbr starts with 0
String s="java";
sop(s.charAt(2));
40.compareTo()
it compares the values lexico graphically and returns the integer value
if(s1==s2)
return 0;
if(s1>s2)
return 1;
if(s1<s2)
return -1;
41.contains()
it search the sequence of characters in the String
it returns true,if sequence of character values found in the string o/w
returns flase
eg:String s="java is earliest program";
sop(s.contains("java is"));
sop(s.contains("java"));

42.endsWith()
if the strings ends with given suffix,it returns true else return false
String str="java program"
sop(s.endsWith(ram));

43.equals()
refer 11TH question

44.equalsIgnoreCase()
string s1="java";
String s2="java";
String str3="jaVa";
sop(s1.equalsIgnoreCase(s2));

45.format()
to format the representation of the string
String s="java";
sop("the name is %12s",s);

46.getBytes()
it return the byte(sequence of bytes) array of the string
string str="A B C D E"
byte[] b=s.getBytes();
for(int i=0;i<b.length();i++){
sop(b[i]);
}
String s2=new String(b);
sop(s2);
47.getChars()
it copy the content of the string in to character array
String s1="hello java program"
Char[] ch=new Char[16];
sop(s1.getChars(6,9,ch,0));
48.indexOf()
it returns indexOf() gien character value and strats with 0;
String s="How are are always";
sop(s.index("ar"));

49.intern()
It is used to return the intern string.
it can e used to return the string from the string constant fool
if the string is created by new keyword,it create the exact copy of heap
string object in string constant pool
string s1=new String("java");
String s2="java";
String s3=s1.intern();

50.isEmpty()
this method check,if the string is empty or not
string s1="";
string s2="java";
sop(s1.isEmpty());
sop(s2.isEmpty());

51.join()
this method returns string joined with a given delimiter
string res=String.join("-","hello","how","are","you");
sop(res);
O/p:hello-how-are-you

52.lastIndex()
it returns the last index of the given character value
string s="how are you"
sop(s.lastIndexOf("ar"));

53.length()
this method returns the length of the string
string s="java";
sop(s,length());

53.replace()
string s="java is easy";
sop(s.replace('a','e');
O/p:jeve is eesy

54.replaceAll()
it returns a string replacing all the sequence of characters matching regex
and replacement string
replace("\\s","");

55.split()
this is used to split the string into character array or array of characters
String s="java is easy";
string[] words=s.split("\\s",0);
for(string s1:words)
{
sop(s1);
}

56.startsWith()
it checks the given is satrts with given prefix
String str="java";
sop(s.startsWith("j"));

57.toCharArray()
java.array.toChararray() convert the String into charArray()
it returns a newly created character array,it is similar to the String
String s="java";
ch[] ch=s.toCharArray();
for(int i=0;i<ch.length90;i++){
sop(ch[i]);
}
by default string is a character array, but in java it is class
58.toLowerCase()
it converts string from upper case to lower case
String s="JAVA";
sop(s.toLowerCase());

59.toUpperCase()
it converts string from lower to upper

60.trim()
the trim method is used to eliminate leading and trailing space
string s="hello java";
sop(s.trim());

61.valueOf()
it convert diff types of value into string
int a=10;
string s=string.valueOf(a);
sop(s+10);

EXCEPTION

1.exceptions?
they are created when an abnormal situations are araised in pgm
they can be created by JVM
it is an object
it is present in java.lang:
in other words,we caqn say exception as run time error

2.State some situation,where exceptions may a raise in java?


1.accesing the element that does not exist in
array(ArrayIndexOutOfBoundsException)
2.invalid conversion of nbr to string and string to
nbr(NumberFormatException)
3.pointing to an object which is no longer avaliable(NullPointerException)

3.What is exception handling in java?


it is a mechanism,what to do when some abnormal situation araises in a prgm
if any abnormal situation araises ion prgm,it leads to termination of
prgm,when it is not handled properly
significance of exception handling is not to terminate program and to
continue with rest of prgm normally
4.what is an error in java?
errors are caused by a prgm
when errors atre caused by prgm, we call it as exceptions
but some times exceptions are fast due to some environment ruuning out of
memory in such cases
exceptions which cannot be recovered are called errors
eg:out of memoery

5.adv of exception handling?


1.catagarizing into diff types of Exception that can easily handle
2.seperating nrml code from exception handling code to avoid abnormal
termination

6.in how many ways we can handle exceptions in java?


1.declaring a method with throws class
2.by specifying in try catch block,where we can catch the exception

7.List five keywords related to exception handling?


1.throw
2.throws
3.try
4.catch
5.finally

8.Explain try and catch keywords in javba?


in try block, we define all exception causing error
in catch block,it catches the exception thrown by try block
catch block cannot catch an exception thrown by another try block
if there is no exception in prgm,no need to use try-catch block
syntax:
try{
}
catch(Exception){
}

9.Can we have abtry block without catch block?


each try block requires atleast one catch block and finally block
a try block without catch or finally block results in compiler error
wee can finally block but not try and catch

10.Can we have multiple catch block for try block?


in some cases,prgm may throw more than one exception
in such case,we can specify two or more catch block
try with multiple catch block is highly recommended in java

11.Explain importance of finally block in java?


it is used for cleaning up of resources such as closing connections etc.,
if try block exceutes with no exception,then finally block called
if there is exception thrown in try block,finally block is called
immeadiately,after catch block
if an exception is thrown by try block,finally block is exceuted even if the
no catch block handles the exception

12.can we have any code b/w try and catch?


we should not declare any code b/w try and catch block
catch block should immeadaitely starts after try block

13.Can we had any code b/w try nad finally block?


we should not do it

14.Can we catch more than one Exception with single catch block?
we can catch mopre than 1 exception in single catch
this type of handling reducesz code duplication
eg:
15.What are checked Exceptions?
all the sub clases of throwable class except error,RunTimeExceptions and
subclases are called as checked exceptions
they can be thrown with keyword throws/should be providedd by try catch block
if not doing this,then it will be complier error
SQLException
IOException
FileNotFoundException
InstanciationException

16.Unchecked exception
all subclases of runtimeexceptiuons are called unchecked exception
they are unchecked becz the compiler does not check if a method hadles or
throws exception
if any exception occurs the prgm will terminate
it is very difficult to handle this kind of exception
eg:StringINdexOutOfBoundsEcxeption
NullPointerException
ClassCastException

17.Diff blw checked and unchecked exception


checked:
all sub clases of throwable calss,except run time exceptions are called asa
checked exception
need to be handled at compile time
unchecked:
all sub clasesof run time exceptions are called as unchecled exception
does not hadled at compile time

18.Default exception handling in java


after creation of object in jvm,it checks whether there is exception handling
code or not,
then exception is hadled and continues the prgm
if there is no code,the responsibility will be given to the default handler
it contains following info
1.Name of xception
2.description about exception
3.location of exception
note:main dis adv of default exception handing is prgm will abort and cannot
continue

19.Throw keyword in java


generally jvm throw the exception and we handle it by try and catch block
but there are some situation where we have to throw user defined exceptions
or run time exception
in such cases we use throw keyword explicitly
syntax:
throwable instance must be a type of thowable class

20.can we write any code after throw keyword?


after throw statement,jvm starts execution
if you try ro write any statement after throw,compiler will not compile it
mad code will be unreachable code

21.Throws keyword in java?


it is used at the end of method to indicate that an exception of given type
may be thrown from the method
in unchecked exception,no need to use throws keyword,wqe can use throws
keyword,only for throwable types
if the error is unchecked,no need to use try catch block

22.Expalin the importance of finally over return statement?


finally block is more imp than return statement when both are present in
return styatemen t
eg:if there is nay return statement present inside in a try or catch block
and finally block is also present,
finally will be exceuted first nad return staement will vbe considered

23.Explain the situation where fianlly block will not be exceuted


System.exit(0);
it will not be exceuted,when jvm shut down
if we use system.exit(0) in try statement,finally block is not be executed

24.can we use catch statement for checked exception


we3 camnt declare catch block for handling checked exception.this raises
compile time error

25.What are user defined exception?


to create a customise error msgs,we use user defined exception
we can create user defined exception for checked as wel as unchecked

26.can we rethrow the same exception from catch handler


yes,we can rethrow the same exception from our catch handler
if we want to rethrow the exception from a catch block,we need to declare
that exception

27.can we nested try starements in java


try statement can be nested,we can declare try statement inside the block of
another statement

28.Expalin the imp of throwable class nad its method?


it is a root class for exception
all the execeptions are derivede from this throwable class
the two sub class of this calss are
1.Exception
2.Error
3 methods are used
1.printStackTrace();-prints name of excepotion
2.getMessage();-description
3.toString();-name & description

29.Explain when ClassNotFoundException will be raised?


when jvm tries to load a class by string name and could not be able to find
the class

30.Exlpain when NoClassDefFoundError


when jvm tries to load the class,but no defination of class is found

multi trhereading
1.multi threading
exceutiong multiple threads simultaneously to obtain multi tasking
it is to ovbtain the multi tasking
it consumes less memory and gives fast and effiecient performance
adv:
thtread can share same addrrsesss space
thread is light wait

2.thread?
it is a light wait process
it creates separate path of execution bcz each thread is runs in a diff stack
frame
a process may contain multiple threads
a threads can share all process resources but still they exceuted
independently

3.diff b/w Process and thread


Process:
a prgm in exceuition is called process
they may share diff address space
any changes in the parent class does not effect the child class
thread:
it is subset of process
they share same address space
any changes in the parent thread will effect the child thread

4.Inter thread communication


the process of communication b/w synchronized thread is known as Inter thread
communication
it is used to vaoid thread poling in java
the thread is fast in running in its critical session,another
thread is allowed to enter or lock in the same critical session
it can be obtained by wait(),notify() nad notifyAll()

5.Purpose of wait() in jva?


it is provided by object class
it is used in Inter thread communication
it is to pause current thread and wait untill another thread does not call
the notify() or notifyAll()
public final void wait()

6.Why must wait() be called from the synchronized block?


we must call the wait() otherwise it will throw
java.lang.IllegealMonitorStateException
it must be present in the synchronized block for the proper and current comm
will stops

7.adv of multi threading


it can be exceuted iundependently
utilization of catch memory bcz thread sharing the same address space

8.State in thread life cycle?


1.new-thread is created by new oprator.after creating thread object,it will
not alive.thread does not start until we cal start()
2.runnable-thread is ready to run after calling the start(),how ever the
thread is not selected by thread scheduler
3.running-thread schedular picks the thread from the ready state and thread
will be in a running state
4.waiting/blocked-thread is not running but alive or it is waiting for othet
thread to finish
5.dead/terminate-a thread is terminated,when the run() exists

9.diff b/w Premetive scheduling and time slicing?


Premetive scheduling
the highest priority time
time slicing
10.Context switching?
the state of the process
11.Two weays to create thread?
extending thread class
implementing runnable interface
12.What is join()?
it wait for a thread to die
in other words,it causes the currently running to stop exceuting until the
thread it joins with complete task
13.purpose of sleep()
it used to block/suspend/wait the thread for a particular time

14.diff b/w wait() and sleep()?


wait():
defined in object class
release the lock
sleep():
defined in thread class
does not trelease the lock

15.Is it possible a thread to start same time?


no,we cannot start the thread twice bcz
once the thread start and exceute,it goes to dfead state.therefore,if we try
to start a thread twice
it gives java.lang.IllegalThreadStateException

16.Deamon thread?
this is a low priority thread that probide a background support and services
to user thread
deamon threads are get automatically terminated by the jvm,if the prgm
remains with in the deamon thread
and all user threads are died

17.can we make a user thread as a deamon thread if the thread is strated?


no,it gives java.lang.IllegalThreadStateException
user thread will not be a deamon thread bcz deamon thread will start before
running

18.How should we interrupt a thread?


by using isInterrupt();

19.Synchronization()
control the access of multiple thread,to any shared resources

20.Synchronized block?
synchronization providing block is known as Synchronized block
21.diff b/w notify nad notifyall()
notify:
unblock only one waiting thread
notifyall():
unblock all the waiting thread
22.thread schedular in java?
after creating the thread,it was superwised by thread schedulkatr which is
aprt of jvm,
thread schedular is only res[ponsible for only which thread is executed
it used two mechanism
time slicing
premitive scheduling

23.does Each thread is having stack in multi threading prgming?


yes,in mutli threded prgming,it provide own stack memoery as every thread is
independent

24.Threadpool?
it represent the group of worker thread in thread pool which are waiting for
the service provider who will give task

IO package

1.javaio?
io stands for input and output,used to process th ei/p and produce the o/p

2.java input stream


it is a sequence of data
it is composed of bytes
used to read data from
System.in
system.out
System.err

3.Output stream
used to write data in file
it is an abstract class

4.diff b/w o/p and i/p stream class


o/p:
it is a super class of all classes representing an o/p stream of bytes
i/p:
it is an abstract class and super class of all classes representing an i/p
stream of bytes
5.file O/p stream
used for writing data for file
it focuses on character data

6.file i/p stream?


used for reading data from file
it focus on image,data,audio,video

7.BufferReader class
it is used to read the text from character based i/p stream
it can be read data from readLine();

8.BufferWriter class
it is used to provide write instances
it can be efficient for writing arrays,strings

9.File reader?
this class iss used to read data from file
it returns the data in byte format
it shoiuld be comes with i/p stream reader

10.File writer?
file writer should come with o/p file writer

11.BufferReader and scanner


scanner:

scanner is in util package


in scanner ,we pass the parameters manuallay
for int nextInt(),next()
BufferReader:

bf used in io package
it can allocate
readLine() and nextLine()
12.Stream?
it is sequence of data and composed pof bytes

Packages

1.package in java?
package is a mechanism that contains group of realted classes,interfaces
etc., into a single module

2.Naming conventions
package name starts with small letters
we cannot have more than one package statement in source file

3.can we define a package after import statement in java?


we cant do it.

4.types of packages?
user defined
system

5.User defined?
we can creatye package with import stataemne
package package name:
can use in another class by importing it into
that

You might also like