Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Thursday, June 20, 2013

YOU SHOULD KNOW TO LEARN ANDROID

If you want learn android quickly you should know

  • Some experience with java.
  • Object-oriented programming concepts.
  • Experience with using IDE like Eclipse, IntelliJ IDEA.
  • Keep Updating the Android tools and Knowledge of Android capabilities. 

Android App Development.

It's been 3 months now started developing android apps. best way to learn is go with the official developer site training tutorials. it's free of cost  after that go and play with the samples from that you can learn some fundamentals and you will know how to use the sdk effectively. one who having the java knowledge can  learn easily.

Friday, December 14, 2012

Software Continuous Integration tool

Today am gone discussed about one of the Software Continuous Integration tool so far i used a lot of tools. one i recomend for continuous integration is CodePro Analytix. it was amazing tool. this product was developed by Google. it is very easy tool to work with an IDE just like eclipse. CodePro AnalytiX is a powerful software code quality, testing and static analysis tool designed to help developers automatically improve software quality, security, reliability and maintainability in Java applications they develop.

Am going to discuss features of CodePro Analytix one by one.

 Code Coverage
Powerful tools that measure what percentage of code is being executed using generated test cases or manual test scripts.

Dependency Analysis
Automated tools that analyze and visually depict the dependencies between projects, packages, and types

JUnit Test Editor
A rich JUnit test editing environment that enables rapid creation, organization, modification and execution of unit tests.

JUnit Test Generation
Time-saving facility that uses sophisticated flow path analysis techniques to automates the creation of comprehensive JUnit regression tests

Similar Code Analysis
Efficiently examines Java code to find duplicate or very similar segments of code containing copy/paste bugs or that can be refactored to improve application design and maintainability

Code Analysis
Dynamic, extensible tools that detect, report and repair deviations or non-compliance with predefined coding standards, popular frameworks, security and style conventions

Metrics
Automated tools that measure and report on key quality indicators in a body of Java source code

If you want to learn further you can simply google it. you will get the more information.

Tuesday, August 16, 2011

Important points about Enum in Java

1) Enums in Java are type-safe and has there own name-space. It means your enum will have a type for example "Currency" in below example and you can not assign any value other than specied in Enum Constants.
public enum Currency {PENNY, NICKLE, DIME, QUARTER};
Currency coin = Currency.PENNY;
coin = 1; //compilation error

2) Enums in Java are reference type like class or interface and you can define constructor, methods and variables inside java enum whichmakes it more powerful than Enum in C and C++ as shwon in next example of java enum type.


3) You can specify values of enum constants at the creation time as shown in below example:

public enum Currency {PENNY(1), NICKLE(5), DIME(10), QUARTER(25)};

But for this to work you need to define a member varialbe and a constructor because PENNY (1) is actually calling a constructor which accepts int value , see below example.
public enum Currency {
PENNY(1), NICKLE(5), DIME(10), QUARTER(25);
private int value;

private Currency(int value) {
this.value = value;
}
};
Constructor of enum in java must be private any other access modifier will result in compilation error. Now to get the value associated with each coin you can define a public getValue () method inside java enum like any normal java class. Also semi colon in the first line is optional.


4) Enum constants are implicitly static and final and can not be changed once created. For example below code of java enum will result in compilation error:
Currency.PENNY = Currency.DIME;
The final field EnumExamples.Currency.PENNY cannot be re assigned.
5) Enum in java can be used as an argument on switch statment and with "case:" like int or char primitive type. This feature of java enum makes them very useful for switch operations. Let’s see an example of how to use java enum inside switch statement:
 
Currency usCoin = Currency.DIME;
switch (usCoin) {
case PENNY:
System.out.println("Penny coin");
break;
case NICKLE:
System.out.println("Nickle coin");
break;
case DIME:
System.out.println("Dime coin");
break;
case QUARTER:
System.out.println("Quarter coin");
}


6) Since constants defined inside enum in java are final you can safely compare them using "==" equality operator as shwon in following example of java enum:
Currency usCoin = Currency.DIME;
if(usCoin == Currency.DIME){
System.out.println("enum in java can be"+
"compared using ==");
}

7) Java compiler automatically generates static values () method for every enum in java. Values() method returns array of enum constants in the same order they have listed in enum and you can use values() to iterator over values of enums in java as shown in below example:
for(Currency coin: Currency.values()){
System.out.println("coin: " + coin);
}
And it will print:
coin: PENNY
coin: NICKLE
coin: DIME
coin: QUARTER
Notice the order its exactly same with defined order in enum.


8) In Java Enum can override methods also. Let’s see an example of overriding toString () method inside enum in java to provide meaningful description for enum constants.
public enum Currency {
........
     
@Override
public String toString() {
switch (this) {
case PENNY:
System.out.println("Penny: " + value);
break;
case NICKLE:
System.out.println("Nickle: " + value);
break;
case DIME:
System.out.println("Dime: " + value);
break;
case QUARTER:
System.out.println("Quarter: " + value);
}
return super.toString();
}
};
And here is how it looks like when displayed:
Currency usCoin = Currency.DIME;
System.out.println(usCoin);

output:
Dime: 10

9) Two new collection classes EnumMap and EnumSet are added into collection package to support java enums. These classes are high performance implementation of Map and Set interface in Java and we should use this whenever there is any opportunity.


10) You can not create instance of enums by using new operator in java because constructor of Enum in Java can only be private and Enum constants can only be created inside Enum itself.


11) Instance of enums in java is created when any enum constants are first called or refrenced in code.


12) Enum in Java can implement the interface and override any method like normal class It’s also worth noting that enum in java implicitly implement both Serializable and Comparable interface. Let's see and example of how to implement interface using java enum:
public enum Currency implements Runnable{
PENNY(1), NICKLE(5), DIME(10), QUARTER(25);
private int value;
............
@Override
public void run() {
System.out.println("Enum in Java implement interfaces");
}
}


13) You can define abstract methods inside enum in Java and can also provide different implementation for different instances of enum in java. Let’s see an example of using abstract method inside enum in java
public enum Currency implements Runnable{
PENNY(1) {
@Override
public String color() {
return "copper";
}
}, NICKLE(5) {
@Override
public String color() {
return "bronze";
}
}, DIME(10) {
@Override
public String color() {
return "silver";
}
}, QUARTER(25) {
@Override
public String color() {
return "silver";
}
};
private int value;

public abstract String color();
private Currency(int value) {
this.value = value;
}
..............
}
In this example since every coin will have different color we made the color () method abstract and let each instance of enum to define there own color. You can get color of any coin by just calling color () method as shown in below example of java enum:

System.out.println("Color: " + Currency.DIME.color());
That’s all on Java enums , Plesae share if you have any nice tips on enum in Java and let us know how you are using java enum in your work.

What Benefits of Enums in Java

1) Enum is type-safe you can not assign anything else other than predefined enum constant to an enum variable.

2) Enum has its own name-space.

3) Best feature of Enum is you can use Enum in Java inside Switch statement like int or char primitive data type.

4) Adding new constants on Enum in Java is easy and you can add new constants without breaking existing code.

What is Enum in Java ?

enum is a keyword in java and on more detail term java enum is type like class and interface and can be used to define a set of enum constants. Enum constants are implicitly static and final and you can not change there value once created. Enum in Java provides type-safety and can be used inside switch statment like int variables. Since enum is a keyword you can not use as variable name and since its only introduced in JDK 1.5 all your previous code which has enum as variable name will not work and needs to be refactored.

"==" effect autoboxing in java

Some of the JVM cache objects of some wrapper class e.g. Integer from -128 to 127 and return same object which if compare via “ ==” can return true but after this range this validity doesn’t work and to make it worse this behavior is JVM dependented so better avoid this kind of check and use equals() method.
e.g.

Integer i1 = 260;
Integer i2 = 260;

if (i1 == i2)
System.out.println("i1 and i2 is equal");
else
System.out.println("i1 and i2 is not equal ");

Here you will most probably get "i1 and i2 is not equal " at least in my machine.
because in this case, unboxing operation is not involved. The literal 260 is boxed into two different Integer objects ( again it varies between JVM to JVM) , and then those objects are compared with ==. The result is false, as the two objects are different instances, with different memory addresses. Because both sides of the == expression contain objects, no unboxing occurs.

Integer i1 = 100;
Integer i2 = 100;

if (i1 == i2)
System.out.println("i1 and i2 is equal");
else
System.out.println("i1 and i2 is not equal ");

Here, most probably you will get the text "i1 and i2 is equal".
Because int values from -127 to 127 are in a range which most JVM will like to cache so the VM actually uses the same object instance (and therefore memory address) for both i1 and i2. As a result, == returns a true result.

this is very indeterministic and only shown by example since some JVM do optimization at certain integer value and try to return same object every time but its not guaranteed or written behavior.

So best is to avoid this kind of code in post java 1.5 and instead use equals() method to compare which is more deterministic.

Thursday, July 21, 2011

Can i serialize static variable in java ?

No you con't serialize static variable

Actually it working fine when you are going to serialize object it's contain static variables. but
A static variable is part of a class, not part of any one object. When you are going to serialize if your class contain static variables it leads to problems some time.

Consider this example
import java.io.*;    
public class Number implements Serializable
{
static int n1;
int n2;
public Number()
{
n1=10;
n2=15;
}
int number()
{
n2=20;
return n2;
}
public static void main(String[] ar)
{
Number n=new Number(); // constructor intialize values n1=10,n2=15
System.out.println("Before Serialization n1="+n.n1); //print n1=10;
System.out.println("Before Serialization n2="+n.number()); //here call the number() method on n so it set's n2 =20 and it return. and print.
try
{
FileOutputStream fos=new FileOutputStream("Number.txt");
ObjectOutputStream os=new ObjectOutputStream(fos);
os.writeObject(n); //when you are going to write n object it's values are n1 =10,n2=20
os.close();
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
FileInputStream fis=new FileInputStream("Number.txt");
ObjectInputStream ois=new ObjectInputStream(fis);
n=(Number)ois.readObject();
ois.close();
}
catch(Exception e)
{
e.printStackTrace();
}
//after retreving values. n1 = 10,n2 =20 only.
System.out.println("After Serialization n1="+n.n1);
System.out.println("After Serialization n2="+n.n2);
}
}

if you are class contain one static variable it is serialized. after that the value of static variable will be changed and again you are serialize the object. When you are going to deserialize of first object static variable value will not come before modified static value
so if you class including any static members, will already have been initialized.
with in this case you are write serialization and de-serialization in one class so you con't understand what happen actually.

Actually happening thing is this.
Am writing to programs if you are compile below 2 programs you can understand why static variables con't serialize

serialize the object
import java.io.*;  
class Serial
{
public static void main(String[] ar)
{
Number n=new Number();
System.out.println("Before Serialization n1="+n.n1);
System.out.println("Before Serialization n2="+n.n2);
try
{
FileOutputStream fos=new FileOutputStream("Number.txt");
ObjectOutputStream os=new ObjectOutputStream(fos);
os.writeObject(n);
os.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

de-serialization of object

import java.io.*;   
class Deserial {
public static void main(String[] args) {
Number n=null;
try {
FileInputStream fis=new FileInputStream("Number.txt");
ObjectInputStream ois=new ObjectInputStream(fis);
n=(Number)ois.readObject();
ois.close();
}
catch(Exception e) { e.printStackTrace(); }
System.out.println("After Serialization n1="+n.n1);
System.out.println("After Serialization n2="+n.n2);
}
}


if you are going to serialize and de-serialize in one class. at the time of de-serialization already initialized static variable values will be printed if you are going to serialize and de-serialize in different class you know the truth.

Sunday, May 29, 2011

Java Interview Questions

1. What is the diffrence between an Abstract class and Interface ?
2. What is user defined exception ?
3. What do you know about the garbate collector ?
4. What is the difference between C++ & Java ?
5. Explain RMI Architecture?
6. How do you communicate in between Applets & Servlets ?
7. What is the use of Servlets ?
8. What is JDBC? How do you connect to the Database ?
9. In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ?
10. What is the difference between Process and Threads ?
11. What is the difference between RMI & Corba ?
12. What are the services in RMI ?
13. How will you initialize an Applet ?
14. What is the order of method invocation in an Applet ?
15. When is update method called ?
16. How will you pass values from HTML page to the Servlet ?
17. Have you ever used HashTable and Dictionary ?
18. How will you communicate between two Applets ?
19. What are statements in JAVA ?
20. What is JAR file ?
21. What is JNI ?
22. What is the base class for all swing components ?
23. What is JFC ?
24. What is Difference between AWT and Swing ?
25. Considering notepad/IE or any other thing as process, What will happen if you start notepad or IE 3 times? Where 3 processes are started or 3 threads are started ?
26. How does thread synchronization occurs inside a monitor ?
27. How will you call an Applet using a Java Script function ?
28. Is there any tag in HTML to upload and download files ?
29. Why do you Canvas ?
30. How can you push data from an Applet to Servlet ?
31. What are 4 drivers available in JDBC ?
32. How you can know about drivers and database information ?
33. If you are truncated using JDBC, How can you know ..that how much data is truncated ?
34. And What situation , each of the 4 drivers used ?
35. How will you perform transaction using JDBC ?
36. In RMI, server object first loaded into the memory and then the stub reference is sent to the client ? or whether a stub reference is directly sent to the client ?
37. Suppose server object is not loaded into the memory, and the client request for it , what will happen?
38. What is serialization ?
39. Can you load the server object dynamically? If so, what are the major 3 steps involved in it ?
40. What is difference RMI registry and OSAgent ?
41. To a server method, the client wants to send a value 20, with this value exceeds to 20,. a message should be sent to the client ? What will you do for achieving for this ?
42. What are the benefits of Swing over AWT ?
43. Where the CardLayout is used ?
44. What is the Layout for ToolBar ?
45. What is the difference between Grid and GridbagLayout ?
46. How will you add panel to a Frame ?
47. What is the corresponding Layout for Card in Swing ?
48. What is light weight component ?
49. Can you run the product development on all operating systems ?
50. What is the webserver used for running the Servlets ?
51. What is Servlet API used for conneting database ?
52. What is bean ? Where it can be used ?
53. What is difference in between Java Class and Bean ?
54. Can we send object using Sockets ?
55. What is the RMI and Socket ?
56. How to communicate 2 threads each other ?
57. What are the files generated after using IDL to Java Compilet ?
58. What is the protocol used by server and client ?
59. Can I modify an object in CORBA ?
60. What is the functionality stubs and skeletons ?
61. What is the mapping mechanism used by Java to identify IDL language ?
62. Diff between Application and Applet ?
63. What is serializable Interface ?
64. What is the difference between CGI and Servlet ?
65. What is the use of Interface ?
66. Why Java is not fully objective oriented ?
67. Why does not support multiple Inheritance ?
68. What it the root class for all Java classes ?
69. What is polymorphism ?
70. Suppose If we have variable ' I ' in run method, If I can create one or more thread each thread will occupy a separate copy or same variable will be shared ?
71. In servlets, we are having a web page that is invoking servlets username and password ? which is cheks in the database ? Suppose the second page also If we want to verify the same information whethe it will connect to the database or it will be used previous information?
72. What are virtual functions ?
73. Write down how will you create a binary Tree ?
74. What are the traverses in Binary Tree ?
75. Write a program for recursive Traverse ?
76. What are session variable in Servlets ?
77. What is client server computing ?
78. What is Constructor and Virtual function? Can we call Virtual funciton in a constructor ?
79. Why we use OOPS concepts? What is its advantage ?
80. What is the middleware ? What is the functionality of Webserver ?
81. Why Java is not 100 % pure OOPS ? ( EcomServer )
82. When we will use an Interface and Abstract class ?
83. What is an RMI?
84. How will you pass parameters in RMI ? Why u serialize?
85. What is the exact difference in between Unicast and Multicast object ? Where we will use ?
86. What is the main functionality of the Remote Reference Layer ?
87. How do you download stubs from a Remote place ?
88. What is the difference in between C++ and Java ? can u explain in detail ?
89. I want to store more than 10 objects in a remote server ? Which methodology will follow ?
90. What is the main functionality of the Prepared Statement ?
91. What is meant by static query and dynamic query ?
92. What are the Normalization Rules ? Define the Normalization ?
93. What is meant by Servelet? What are the parameters of the service method ?
94. What is meant by Session ? Tell me something about HTTPSession Class ?
95. How do you invoke a Servelt? What is the difference in between doPost and doGet methods ?
96. What is the difference in between the HTTPServlet and Generic Servlet ? Expalin their methods ? Tell me their parameter names also ?
97. Have you used threads in Servelet ?
98. Write a program on RMI and JDBC using StoredProcedure ?
99. How do you sing an Applet ?
100. In a Container there are 5 components. I want to display the all the components names, how will you do that one ?
101. Why there are some null interface in java ? What does it mean ? Give me some null interfaces in JAVA ?
102. Tell me the latest versions in JAVA related areas ?
103. What is meant by class loader ? How many types are there? When will we use them ?
104. How do you load an Image in a Servlet ?
105. What is meant by flickering ?
106. What is meant by distributed Application ? Why we are using that in our applications ?
107. What is the functionality of the stub ?
108. Have you used any version control ?
109. What is the latest version of JDBC ? What are the new features are added in that ?
110. Explain 2 tier and 3 -tier Architecture ?
111. What is the role of the webserver ?
112. How have you done validation of the fileds in your project ?
113. What is the main difficulties that you are faced in your project ?
114. What is meant by cookies ? Explain ?
115. Problem faced in your earlier project
116. How OOPS concept is achieved in Java
117. Features for using Java
118. How does Java 2.0 differ from Java 1.0
119. Public static void main – Explain
120. What are command line arguments
121. Explain about the three-tier model
122. Difference between String & StringBuffer
123. Wrapper class. Is String a Wrapper Class
124. What are the restriction for static method
125. Purpose of the file class
126. Default modifier in Interface
127. Difference between Interface & Abstract class
128. Can abstract be declared as Final
129. Can we declare variables inside a method as Final Variables
130. What is the package concept and use of package
131. How can a dead thread be started
132. Difference between Applet & Application
133. Life cycle of the Applet
134. Can Applet have constructors
135. Differeence between canvas class & graphics class
136. Explain about Superclass & subclass
137. Difference between TCP & UDP
138. What is AppletStub
139. Explain Stream Tokenizer
140. What is the difference between two types of threads
141. Checked & Unchecked exception
142. Use of throws exception
143. What is finally in exception handling
144. Vector class
145. What will happen to the Exception object after exception handling
146. Two types of multi-tasking
147. Two ways to create the thread
148. Synchronization
149. I/O Filter
150. How can you retrieve warnings in JDBC
151. Can applet in different page communicate with each other
152. Four driver Manager
153. Features of JDBC 20
154. Explain about stored procedures
155. Servlet Life cycle
156. Why do you go for servlet rather than CGI
157. How to generate skeleton & Stub classes
158. Explain lazy activation
159. Firewalls in RMI
160. What is meant by Java ?
161. What is meant by a class ?
162. What is meant by a method ?
163. What are the OOPS concepts in Java ?
164. What is meant by encapsulation ? Explain with an example
165. What is meant by inheritance ? Explain with an example
166. What is meant by polymorphism ? Explain with an example
167. Is multiple inheritance allowed in Java ? Why ?
168. What is meant by Java interpreter ?
169. What is meant by JVM ?
170. What is a compilation unit ?
171. What is meant by identifiers ?
172. What are the different types of modifiers ?
173. What are the access modifiers in Java ?
174. What are the primitive data types in Java ?
175. What is meant by a wrapper class ?
176. What is meant by static variable and static method ?
177. What is meant by Garbage collection ?
178. What is meant by abstract class
179. What is meant by final class, methods and variables ?
180. What is meant by interface ?
181. What is meant by a resource leak ?
182. What is the difference between interface and abstract class ?
183. What is the difference between public private, protected and static
184. What is meant by method overloading ?
185. What is meant by method overriding ?
186. What is singleton class ?
187. What is the difference between an array and a vector ?
188. What is meant by constructor ?
189. What is meant by casting ?
190. What is the difference between final, finally and finalize ?
191. What is meant by packages ?
192. What are all the packages ?
193. Name 2 calsses you have used ?
194. Name 2 classes that can store arbitrary number of objects ?
195. What is the difference between java.applet.* and java.applet.Applet ?
196. What is a default package ?
197. What is meant by a super class and how can you call a super class ?
198. What is anonymous class ?
199. Name interfaces without a method ?
200. What is the use of an interface ?
201. What is a serializable interface ?
202. How to prevent field from serialization ?
203. What is meant by exception ?
204. How can you avoid the runtime exception ?
205. What is the difference between throw and throws ?
206. What is the use of finally ?
207. Can multiple catch statements be used in exceptions ?
208. Is it possible to write a try within a try statement ?
209. What is the method to find if the object exited or not ?
210. What is meant by a Thread ?
211. What is meant by multi-threading ?
212. What is the 2 way of creating a thread ? Which is the best way and why ?
213. What is the method to find if a thread is active or not ?
214. What are the thread-to-thread communcation ?
215. What is the difference between sleep and suspend ?
216. Can thread become a member of another thread ?
217. What is meant by deadlock ?
218. How can you avoid a deadlock ?
219. What are the three typs of priority ?
220. What is the use of synchronizations ?
221. Garbage collector thread belongs to which priority ?
222. What is meant by time-slicing ?
223. What is the use of ‘this’ ?
224. How can you find the length and capacity of a string buffer ?
225. How to compare two strings ?
226. What are the interfaces defined by Java.lang ?
227. What is the purpose of run-time class and system class
228. What is meant by Stream and Types ?
229. What is the method used to clear the buffer ?
230. What is meant by Stream Tokenizer ?
231. What is serialization and de-serialisation ?
232. What is meant by Applet ?
233. How to find the host from which the Applet has originated ?
234. What is the life cycle of an Applet ?
235. How do you load an HTML page from an Applet ?
236. What is meant by Applet Stub Interface ?
237. What is meant by getCodeBase and getDocumentBase method ?
238. How can you call an applet from a HTML file
239. What is meant by Applet Flickering ?
240. What is the use of parameter tag ?
241. What is audio clip Interface and what are all the methods in it ?
242. What is the difference between getAppletInfo and getParameterInfo ?
243. How to communicate between applet and an applet ?
244. What is meant by event handling ?
245. What are all the listeners in java and explain ?
246. What is meant by an adapter class ?
247. What are the types of mouse event listeners ?
248. What are the types of methods in mouse listeners ?
249. What is the difference between panel and frame ?
250. What is the default layout of the panel and frame ?
251. What is meant by controls and types ?
252. What is the difference between a scroll bar and a scroll panel.
253. What is the difference between list and choice ?
254. How to place a component on Windows ?
255. What are the different types of Layouts ?
256. What is meant by CardLayout ?
257. What is the difference between GridLayout and GridBagLayout
258. What is the difference between menuitem and checkboxmenu item.
259. What is meant by vector class, dictionary class , hash table class,and property class ?
260. Which class has no duplicate elements ?
261. What is resource bundle ?
262. What is an enumeration class ?
263. What is meant by Swing ?
264. What is the difference between AWT and Swing ?
265. What is the difference between an applet and a Japplet
266. What are all the components used in Swing ?
267. What is meant by tab pans ?
268. What is the use of JTree ?
269. How can you add and remove nodes in Jtree.
270. What is the method to expand and collapse nodes in a Jtree ?
271. What is the use of JTable ?
272. What is meant by JFC ?
273. What is the class in Swing to change the appearance of the Frame in Runtime.
274. How to reduce flicking in animation ?
275. What is JDBC ?
276. How do you connect to the database ? What are the steps ?
277. What are the drivers available in JDBC ? Explain
278. How can you load the driver ?
279. What are the different types of statement s ?
280. How can you created JDBC statements ?
281. How will you perform transactions using JDBC ?
282. What are the two drivers for web apllication?
283. What are the different types of 2 tier and 3 tier architecture ?
284. How can you retrieve warning in JDBC ?
285. What is the exception thrown by JDBC ?
286. What is meants by PreparedStatement ?
287. What is difference between PreparedStatement and Statement ?
288. How can you call the stored procedures ?
289. What is meant by a ResultSet ?
290. What is the difference between ExecuteUpdate and ExecuteQuery ?
291. How do you know which driver is connected to a database ?
292. What is DSN and System DSN and differentiate these two ?
293. What is meant by TCP, IP, UDP ?
294. What is the difference between TCP and UDP ?
295. What is a proxy server ?
296. What is meant by URL
297. What is a socket and server sockets ?
298. When MalformedURLException and UnknownHost Exception throws ?
299. What is InetAddress ?
300. What is datagram and datagram packets and datagram sockets ?
301. Write the range of multicast socket IP address ?
302. What is meant by a servlet ?
303. What are the types of servlets ? Explain
304. What is the different between a Servlet and a CGI.
305. What is the difference between 2 types of Servlets ?
306. What is the type of method for sending request from HTTP server ?
307. What are the exceptions thrown by Servlets ? Why ?
308. What is the life cycle of a servlet ?
309. What is meant by cookies ?
310. What is HTTP Session ?
311. What is the difference between GET and POST methods ?
312. How can you run a Servlet Program ?
313. How to commuincate between an applet and a servlet ?
314. What is a Servlet-to-Servlet communcation ?
315. What is Session Tracking ?
316. What are the security issues in Servlets ?
317. What is HTTP Tunneling
318. How do you load an image in a Servlet ?
319. What is Servlet Chaining ?
320. What is URL Rewriting ?
321. What is context switching ?
322. What is meant by RMI ?
323. Explain RMI Architecture ?
324. What is meant by a stub ?
325. What is meant by a skelotn ?
326. What is meant by serialisation and deserialisation ?
327. What is meant by RRL ?
328. What is the use of TL ?
329. What is RMI Registry ?
330. What is rmic ?
331. How will you pass parameter in RMI ?
332. What exceptions are thrown by RMI ?
333. What are the steps involved in RMI ?
334. What is meant by bind(), rebind(), unbind() and lookup() methods
335. What are the advanatages of RMI ?
336. What is JNI ?
337. What is Remote Interface ?
338. What class is used to create Server side object ?
339. What class is used to bind the server object with RMI Registry ?
340. What is the use of getWriter method ?
341. What is meant by Javabeans ?
342. What is JAR file ?
343. What is meant by manifest files ?
344. What is Introspection ?
345. What are the steps involved to create a bean ?
346. Say any two properties in Beans ?
347. What is persistence ?
348. What is the use of beaninfo ?
349. What are the interfaces you used in Beans ?
350. What are the classes you used in Beans ?
351. What is Entity Bean and Session Bean ?
352. What are the methods of Entity Bean?
353. How does Stateful Session bean store its state ?
354. Why does Stateless Session bean not store its state even though it has ejbActivate and ejbPassivate ?
355. What are the services provided by the container ?
356. Types of transaction ?
357. What is bean managed transaction ?
358. Why does EJB needs two interface( Home and Remote Interface) ?
359. What are transaction attributes ?
360. What is the difference between Container managed persistent bean and Bean managed persistent entity bean ?
361. What is J2EE ?
362. What is JTS ?
363. How many entity beans used and how many tables can u use in EJB project ?
364. What is scalable,portability in J2EE?
365. What is Connection pooling?Is it advantageous?
366. Method and class used for Connection pooling ?
367. How to deploy in J2EE(i.e Jar,War file) ?
368. How is entity bean created using Container managed entity bean ?
369. Sotware architechture of EJB ?
370. In Entity bean will the create method in EJB home and ejbCreate in Entity bean have the same parameters ?
371. What methods do u use in Servlet – Applet communication ?
372. What are the types of Servlet ?
373. Difference between HttpServlet and Generic Servlets ?
374. Difference between doGet and doPost ?
375. What are the methods in HttpServlet?
376. What are the types of SessionTracking?
377. What is Cookie ? Why is Cookie used ?
378. If my browser does not support Cookie,and my server sends a cookie instance What will happen ?
379. Why do u use Session Tracking in HttpServlet ?
380. Can u use javaScript in Servlets ?
381. What is the capacity the doGet can send to the server ?
382. What are the type of protocols used in HttpServlet ?
383. Difference between TCP/IP and IP protocol ?
384. Why do you use UniCastRemoteObject in RMI ?
385. How many interfaces are used in RMI?
386. Can Rmi registry be written in the code, without having to write it in the command prompt and if yes where?
387. Why is Socket used ?
388. What are the types of JDBC drivers ?
389. Explain the third driver(Native protocol driver) ?
390. Which among the four driver is pure Java driver ?
391. What are the Isolation level in JDBC transaction ?
392. How do you connect with the database ?
393. How do you connect without the Class.forName (" ") ?
394. What does Class.forName return ?
395. What are the types of statement ?
396. Why is preparedStatement,CallableStatement used for?
397. In real time project which driver did u use ?
398. Difference between AWT and Swing compenents ?
399. Is there any heavy weight component in Swings ?
400. Can the Swing application if you upload in net, be compatible with your browser?
401. What should you do get your browser compatible with swing components?
402. What are the methods in Applet ?
403. When is init(),start() called ?
404. When you navigate from one applet to another what are the methods called ?
405. What is the difference between Trusted and Untrusted Applet ?
406. What is Exception ?
407. What are the ways you can handle exception ?
408. When is try,catch block used ?
409. What is finally method in Exceptions ?
410. What are the types of access modifiers ?
411. What is protected and friendly ?
412. What are the other modifiers ?
413. Is synchronised modifier ?
414. What is meant by polymorphism ?
415. What is inheritance ?
416. What is method Overloading ? What is this in OOPS ?
417. What is method Overriding ? What is it in OOPS ?
418. Does java support multi dimensional arrays ?
419. Is multiple inheritance used in Java ?
420. How do you send a message to the browser in JavaScript ?
421. Does javascript support multidimensional arrays ?
422. Why is XML used mainly?
423. Do use coding for database connectivity in XML?
424. What is DTD ?
425. Is there any tool in java that can create reports ?

Friday, March 4, 2011

Java Interview Questions-I

Question: What is JVM
Answer: When we install a java package. It contains 2 things

* The Java Runtime Environment (JRE)
* The Java Development Kit (JDK)

The JRE provides runtime support for Java applications. The JDK provides the Java compiler and other development tools. The JDK includes the JRE.

Both the JRE and the JDK include a Java Virtual Machine (JVM). This is the application that executes a Java program. A Java program requires a JVM to run on a particular platform


Question: What is the main difference between Java platform and other platforms?
Answer: The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms. The Java platform has two components:

1. The Java Virtual Machine (Java VM)
2. The Java Application Programming Interface (Java API)


Question: What is the Java Virtual Machine?
Answer: The Java Virtual Machine is a software that can be ported onto various hardware-based platforms.

Question: What is the Java API?
Answer: The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.


Question: Why do we need public static void main(String args[]) method in Java?
Answer: We need
public: The method can be accessed outside the class / package
static: You need not have an instance of the class to access the method
void: Your application need not return a value, as the JVM launcher would return the value when it exits
main(): This is the entry point for the application

Question: What is the difference between “= =” and “equals()”?
Answer: “= =” does shallow comparison, It retuns true if the two object points to the same address in the memory, i.e if the same the same reference
“equals()” does deep comparison, it checks if the values of the data in the object are same

Question: What would you use to compare two String variables - the operator == or the method equals()?
Answer: I'd use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object


Question: What is an abstract method ?
Answer:An abstract method is a method that don't have a body. It is declared with modifier abstract.

Question: What is the difference between constructor and method?
Answer: Constructor will be automatically invoked when an object is created whereas method has to be called explicitly. Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.

Question: What is the difference between parameters and arguments?
Answer: While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.

Question: What is the difference between Overloading and Overriding?
Answer: Overloading : Reusing the same method name with different arguments and perhaps a different return type is called as overloading
Overriding : Using the same method name with identical arguments and return type is know as overriding

How do I check if a character representing a number?


/**---------------------------------------------------------*
* @author Madarapu Naveen *
* http://madarapunaveen.blogspot.com *
* ---------------------------------------------------------*
*/

public class CharacterIsDigit {
public static void main(String[] args) {
String numbers = "1234567890";
for (int i = 0; i < numbers.length(); i++) {
if (Character.isDigit(numbers.charAt(i))) {
System.out.println(numbers.charAt(i)
+ " is a number.");
}
else {
System.out.println(numbers.charAt(i)
+ " not a number.");
}
}
}
}

How do I know if an ArrayList contains a specified item?


/**---------------------------------------------------------*
* @author Madarapu Naveen *
* http://madarapunaveen.blogspot.com *
* ---------------------------------------------------------*
*/


import java.util.ArrayList;
import java.util.List;

public class ArrayListContains {
public static void main(String[] args) {
ArrayList list = new ArrayList();
list.add("Item 1");
list.add("Item 2");

if (list.contains("Item 1")) {
System.out.println("True");
}
else {
System.out.println("False");
}
}
}

How do I know the size of ArrayList?


/**---------------------------------------------------------*
* @author Madarapu Naveen *
* http://madarapunaveen.blogspot.com *
* ---------------------------------------------------------*
*/

import java.util.ArrayList;
import java.util.List;

public class ArrayListSize {
public static void main(String[] args) {
List list = new ArrayList();
list.add("Item 1");
list.add("Item 2");

int size = list.size();
System.out.println("size = " + size);
}
}


How do I use ArrayList class?

import java.util.ArrayList;
import java.util.List;

public class ArrayListExample
{
public static void main(String[] args)
{
List list = new ArrayList();

// adding items into array list
list.add("Item 1");
list.add("Item 2");
list.add("Item 3");

// remove the third item from array list
list.remove(2);

// iterate array list item and print it
for (int i = 0; i < list.size(); i++)
{
String item = (String) list.get(i);
System.out.println("Item = " + item);
}

Object[] array = list.toArray();
}
}

Thursday, January 20, 2011

Access Specifying

These are the keywords. That they specify how to access or read or retrive or get the members of class or class it self. These are four types in java.
They are
  • Private
  • Public
  • Protected
  • Default


  • Private:
  • Private members are not available any where outside of the class. These are available only inside the declared class.
  • Public:
  • Public members are always available outside the class to other classes and programs.
  • Protected:
  • protected members are available within the class as well as access one who extend the protected members declared class only.
  • Default
  • These members are accesse within the package and one who extends the another package classes also.

    Hashcode

    The unique identification number given to every object by the JVM is called hashcode or reference number.

    Methods

    A method represent a group of statements that performs a task. Method contains two parts
    • Method proto type (or) Method header
    • Method body
    • .


    Method proto type


    This part contains method name, method parameters and method return type.

    Method body


    Method body contains a group of statements representing the logical to perform the task.

    NOTE:


    A method can return a value using return statement. It cannot return more then one value.

    Methods in Java


    • Static Methods

    • Instance Methods

    • Factory Methods


    Static Methods


    A static method is a method that don’t act upon the instance variables. We can call static methods by using it’s class name or object name.

    NOTE:

    Static Methods Cannot access or read instance variable because JVM first executes the static methods and later creates the objects.

    Instance Methods


    Instance methods are methods which are act’s upon the instance variables. These are the two types one is accessor methods and another one is mutator methods.
  • Accessor Methods:
  • These methods access or read instance variables they do not modify.
  • Mutator Methods:
  • These methods not only read the instance variables but also modify them.



    Factory Methods


    Factory method is method that returns an object of that class tp which it belongs.

    Instance Variables

    Instance variable is a variable whose separate copy is available to every object. If the instance variable of an object is modified it will not effect the other object.

    When the programmer does not initialize the instance variables java compiler writes code in the class to initialize the instance variables with default values.

    Constructor

    A constructor is similar to a method that is used to initialize the instance variable.

    Some points to remember when writing constructors

    • The constructor name and class name must be same.

    • Constructor may or may not have parameters.

    • A constructor does not return any value not even void.

    • Constructor is called only once at the time of creating the objects.

    • A constructor with out any parameter is called default constructor.

    • A constructor with one or more parameters is called parameterized constructor.

    • Default constructors are stored the same data in all objects.

    • Parameterized Constructor is used with initialize the object with default data.

    • Writing two or more constructors with the same name but difference in the parameters is called constructor overloading.

    NOTE:


    When no constructor written in the class when java compiler act’s default constructor with default values.

    objects creation in java


    In java objects are created in several ways they are
    • using new operator
      ex: Employe obj = new Employe();

    • using factory methods
      ex: NumberFormat obj = NumberFormat.getNumberInstance();

    • using newInstance() method
      ex: class c = class.forName(“Employe”);
      Employe obj = c.newInstance();

    • using cloning : creating bit wise exact copy of an object is called cloning
      ex:Employe e1 = new Employe();
      Employee e2 = e1.clone();