Home


Core Java

Java Introduction OOPS concepts Casting Operations
Java Features
Java Drawbacks
Static Blocks
View all
Data Binding, Hiding, Encapsulation
Inheritance
Interfaces–Multiple Inheritance
View All
Data Type CastingObject Casting
Java int to byte
View all
Packages Arrays String & StringBuffer
Predefined Packages–Java API
Creating User-defined Packages
Access Specifiers
View All
Arrays Introduction & Properties
Jagged Arrays
View All
Introduction – Immutable Nature
StringBuffer – Length and Capacity
View All
Exception Handling IO Streams Collections Framework (DS)
Exceptions – Meaning
try – catch – finally
One stop destination for all Exceptions
View All
Streams – Overview
File Copying
Keyboard Reading
View All
Stack
Vector
LinkedList
View All
Multithreading Applets Multimedia
Creating and Spawning Threads
Heavy and Lightweight Threads
Synchronization
View All
Applets Vs Applications
Life Cycle of Applet
Drawing Strings & Graphics
View All
Drawing Images
Animation and Flickering
Multimedia – Image and Animation
Networking AWT Graphics Java Events
Chat Program (TCP/IP)
Echo Server (UDP)
URLConnection & URL
View All
Graphics – Introduction
Drawing Rectangles (Applet graphics)
Drawing Cylinder, Cube, Circle
View All
Java Event Handling View All
AWT Components java.lang java.util
Button – Learning 8 Steps
TextField – Login Screen Validation
View All
Inner classes
Garbage Collection
class System
View All
class StringTokenizer
class GregorianCalendar
class Random
View All
Inner classes Java Reflection API Annotations
Inner classes – Introduction
Java Nested Classes
Nested Interfaces
Class inside Interface
View All
Reflection API
Retrieve fields with data type
Access Specifiers and Modifiers
View All
Annotations Introduction
Java Standard Annotations
Java Meta Annotations
View All
Java Questions Java Performance Tuning Miscellaneous
Test Your Java 1
Test Your Java 2
Test Your Java 3
View all
Core Java – 1
JDBC Tuning
Servlets & JSP Tuning
View All
Java Conversions
Java Comparisons (vs)
JDK 1.7 Features
JDK 1.8 Features
View All

Advanced Java

Swing Design Patterns JDBC
Java JFC Swing Introduction
Swing Overview
JButton with Images and Labels
JLabel Multiline Text
View All
Java Singleton Pattern JDBC Tutorial
What is Driver and JDBC Driver TypesLearning JDBC Programming
View All
Serialization Hibernate Spring
What is Serialization?
Java Serialization Example
View All
Tutorial for Beginners
Simple Example-Insert a Record
View All
Introduction to Spring Framework
Developing a Simple Application
View All
Servlets JSP (Java Server Pages) RMI
Servlets Introduction, Architecture
First Servlet Step-by-Step Explanation – Login Screen Validation
7 Steps – Servlets Tomcat Execution
View All
What are the prerequisites to learn JSP?
What is JSP (Java Server Page)?
15 advantages of JSP over Servlets
View All
Java RMI Tutorial for Beginners
Java RMI Architecture
RMI Application Programs Explanation
View All

774 thoughts on “Home”

  1. Sir,

    i have three years of experience providing training of core java, servlet, jsp, I want to switch in development but i don’t have any real time development experience, guide me for that, and how can I go for corporate training. Please help waiting your guidance.

    1. It seems you have institute training experience. As you are in training, you must be very good at subject. Do one or two dummy projects with realtime reflection, keep fake experience (now a day, it is going much) and appear for interviews. Definitely you get job. To join for corporate training, catch one or two consultants. They get. If you would need I get the names of consultants.

  2. Hi Sir ,
    I completed SQL part in oracle. should i go for pl/sql part in oracle because i am fresher.

  3. Sir, is there any way to see the logic of length() method that java applies on String or write a method to count String length without using any String in-built methods. I have also decompiled the String.class but got nothing as there is no logic given their. I want this logic because as per my knowledge we cannot separate String’s characters without using tocharArray() or charAt() and I don’t want to use any in-built String method for count length of String…. please help me , this is pissing my mind… thanks in advance… will wait for your reply…

  4. Hi Sir ,

    this is Vivek. your old student ….
    I want to learn advanced Java. So, can you please tell me where you are teaching now ..?

  5. Ravindra Bohra

    Class Binding
    {
    public void final show()
    {
    /* code
    }
    public void getInstance(Binding b)
    {
    b.show();// which binding?
    }
    }

    which binding is determine when the b.show() method call
    static or dynamic and why?

  6. Sir,
    I am your old student. I am blessed to see you again as I am far from HYD now and I can contact you through this way.Sir I have doubt can you clear this.
    In servlets,
    PrintWriter pw = response.getWriter();
    response is a reference variable and we cannot call methods by using reference variable as it can hold only address.
    Then how can we call getWriter(); using response reference variable?
    Thanks in advance.

  7. Hi Sir,
    Why Hashtable doesn’t allow key & value as null whereas HashMap allows null key&value atleast once.
    please help me.

  8. I’ve knowledge in core java but I want to make it more. …Can you please offer online classes to me through skype

  9. Hi Sir,

    ** Completely am talking about compile time but not runtime**

    My doubt is that, how the Object(is also a java) class(specific) methods is available to user defined Test “interface” (am not talking about class) reference ( Here the getClass() method is defined inside Object class, but not declared inside my Test interface even though i am able to access the method on Test reference and no compilation issue, if i call any other method(except Object class method) which is not declared in Test interface (call on Test interface reference) compilation error occurs)

    In the below example we can see t.getClass(), in the interface Test no getClass() method is declared even on Test interface reference getClass() method is called i.e defined in Object class, in the same way how could make available User defined class(TestImpl specific methods) methods inside interface Test.

    You can see in my previous post, Test interface does not contain any methods and it is not extending any other interface also.
    Rule : Methods which are declared inside an interface, we can call only those methods on that interface reference, so you can observer in my example am able to call getClass() method on Test interface reference.

    (As per my understanding the methods which are defined in Object class are by default available to every interface and every class, Object class is super class to every java class so by default all the methods which are defined in object class are available for all java class. But i am not clear with how the object class methods getting available to interface ? )

    TestImpl.java
    ==========
    public class TestImpl implements Test {
    static Test t;

    public static void main(String[] args) {
    System.out.println(t.getClass()); // Runtime NPE will occure but not compilation error
    }
    }

    Thanks In advance,
    AnandRam

    1. Hi Sir,
      I am waiting for your response for the above posted question ?

      Thanks,
      AnandRam.

  10. Hi Sir,

    Test.java
    =======
    public interface Test {

    }

    TestImpl.java
    ==========
    public class TestImpl implements Test {
    static Test t;

    public static void main(String[] args) {
    t = new TestImpl();
    System.out.println(t.getClass());
    System.out.println(t.displayName());
    }

    public String displayName() {

    return “way2Java”;
    }
    }

    /*
    In the above program we can observer a point, on Test interface reference am able to access getClass() (t.getClass() in this case no compilation issue ) method is defined in Object class, but am not able access displayName() method is defined in TestImpl class (at line number : 7(t.displayName()) am getting compilation error saying “The method displayName() is undefined for the type Test”. My doubt is that, “getClass()” method is not declared inside Test interface, even i am not getting any compilation error, how object class methods are getting available
    inside Test interface?
    */

    Thanks,
    AnandRam

    1. The general rule says “If the super class method is overridden by subclass and also when the super class object is assigned with subclass, the super class object will call subclass overridden method”. On this principle, the dynamic polymorphism works. Now
      1. if the super class method is not overridden, the super class object will call its own method.
      2. if the super class does not have the method and if the subclass have the method, it is compilation error. This is your problem.

  11. interface Printable{
    void print();
    }

    interface Showable{
    void show();
    }

    class A implements Printable,Showable
    {

    public void print()
    {System.out.println(“Hello”);}
    public void show()
    {System.out.println(“Welcome”);}

    public static void main(String args[])
    {
    A obj = new A();
    obj.print();
    obj.show();
    }
    }
    this can be a program to define multiple inheritance with interfaces.
    My question was : why we cannot define two different bodies of two different methods ( void print()) of the interfaces Showable and Printable respectively like we did (with print() and show() method) in this program?

  12. Respected Sir,
    The java code below (interface) is the one I have trouble in understanding:

    interface Printable{
    void print();
    }

    interface Showable{
    void print();
    }

    class testinterface1 implements Printable,Showable{

    public void print(){System.out.println(“Hello”);}

    public static void main(String args[]){
    testinterface1 obj = new testinterface1();
    obj.print();
    }
    }
    My doubt is: when we have two different interfaces which are not connected to each other, rather connected to a common child class (testinterface1) which executes the method void print(), then why don’t we declare the body of two different methods( void print()) of the interfaces Showable and Printable respectively.
    Moreover, this make the concept of Multiple Inheritance useless as both the methods are bound to execute same code and thus reduces their functionality.
    Kindly, help me to fix this problem.

    Thanking you in anticipation,
    Ayushi

  13. Hi Sir,

    Thank you for giving soon response and i have one more doubt please clarify this also please,

    Does an interface extend Object class in java.? if yes how it is possible in java please explain a scenario or if not then why( & how) we can call methods of Object class on interface variable?

    Thank you :)

  14. Hi Sir,

    why static is not allowed for a constructor? I have gone through your notes in this website but i did not get it. Please explain in a clear cut way.

    regards,
    Sampath

  15. The following cannot be abstract:
    (Please select ALL that apply)

    Select an answer
    A. Constructors
    B. Static methods
    C. Private methods
    D. Interface methods

  16. Sir i request you help me in writing code for below example….
    let ‘S’ be class
    class S,S1;
    S={1,2,3};
    S1={4,5,6};
    S.chain(S1);

    //it should combine two sets into single set ‘S’

  17. Hi Sir,

    Can you explain about wait() and notify() methods and why these methods are in object class but not in thread class and explain scenario.

    Thank you in advance.

    1. The methods works on the locks and locks are associated with object and not threads.hence ,it is in Object class.

  18. Hi sir thanks for your great support and work… i got a question asked in an interview can we have ‘private class java if not what is the reason’ please help me sir…

  19. Sir,
    I have a doubt that static blocks are executed as part of classloading or after executing the class.
    If as part of classloading then is it possible to create object of the class before completion of class loading

  20. when i compaile the following programme i will get an error like “unreachable statment”.

    public static void main(String args[])
    {
    return;
    System.out.println(“hai”);
    }
    when i compaile the following programme i will not get any error.

    public static void main(String args[])
    {
    int a=10;
    if(a==10)
    return;
    System.out.println(“hai”);
    }
    why did i get error in first programme and why did i not get error in second programme?

  21. Hello sir,

    What are the pre-requisites to learn HADOOP/BIGDATA..?
    Which institute will give best training..?

    Please suggest me and Thankyou very much in advance sir.

  22. Hi Sir,

    what is the difference between Comparable and Comparator interface? when should we use Comparable and Comparator?
    How compareTo() method performs sorting? Here it compares “this object” with the “passed object”? What is this object here?
    please explain in a clear cut way………

    Sample:
    ————-
    Employee e1 = new Employee(100,”apple”);
    Employee e2 = new Employee(101,”mango”);
    Employee e3 = new Employee(102,”pineapple”);
    Employee e4 = new Employee(103,”orange”);
    ArrayList al = new ArrayList();
    al.add(e1);
    al.add(e2);
    al.add(e3);
    al.add(e4);

    Regards,
    Sampath

  23. Hi Sir,
    One more doubt is that,
    we can achieve immutability using final class and final variables. what is the use of applying private modifiers to the variables?

    Please explain me in a clear cut way….Thanks in advance.

    regards,
    Sampath

  24. i want to do real time projects in java..i am btech 2012 passout. sir any good instutute you refer for projects in hyderabad?

  25. Thnx for this site sir..sir i have completed core java and also studied servlets and JSP..now what should i study next..plz tell me the topics to study nxt and the order in which i should study..

  26. public static void main(String args[])
    {
    byte b=4;
    final byte a=b;
    switch(b)
    {
    case 1:System.out.println(“one”);
    break;
    case 2:System.out.println(“two”);
    break;
    case 3:System.out.println(“three”);
    break;
    case a:System.out.println(“four”);
    break;
    case 5:System.out.println(“five”);
    break;
    default:System.out.println(“default”);
    }
    } when i compiled the above code i got the error like
    constant expression required
    case a:System.out.println(“four”);
    if we declare any variable with final keyword then it is treated as constant but why i got error in the above program sir?

      1. when i assign a final byte ,final short and final int variables into char variable the program gives no error but when i assign a final long variable into char variable it gives error.why does it give error in case of long?

        program 1:in which i didn’t get any error.
        public static void main(String args[])
        {
        final int a=10;
        char b=a;
        System.out.println(b);
        }
        program 2:in which i got error.
        public static void main(String args[])
        {
        final long a=10l;
        char b=a;
        System.out.println(b);
        }

  27. Hi sir,
    Im a passed out mechanical Engineering Graduate(2014). Im working as an Application Developer. Though im from Mechanical Background, i love programming and im passionate about it. i’ve learned the basics of core java, jsp, servlet in my Training days, and i want to be a java programmer and continue in my career life. i would like to know what would be the future for java programmers., and is there any problem for a mechanical engineer like me in programming world?

  28. Sir, I really want to learn java from you. Can you please tell me the name of organization where you teach java.

  29. Hello sir…!

    What are weak references..?

    Can u explain it in detail..?

    Please, Thank you verymuch in advance.

  30. Hello Sir, I have some doubts related to yield, join methods. As yield means it causes to pause execution of current Thread and give priority to equal priority Threads for Execution. I got it but In real Life where we can apply Yield method and Join method.
    Real life means like static keyword we used when we need to share some common memory space among all the objects.
    Same i want to know where we can use these methods yield and join.

  31. Hi Sir,
    i have Small confusion about what is the Difference between ClassNotFoundException And ClassdefNotfound Exception.

  32. Hello sir,

    Why we need to use objects form when data is transmitted on the network…?
    Why can’t we use primitive type form..?

  33. Hi sir,
    Thank u so much providing this tutorial.
    i was attended many interviews in some interviews they asking what is interface where it is using in real time,
    Stringbuffer,serialization,Hashmap, Arraylist, Encapsulation,Vector,.
    i need a clarification above topics

  34. Sir,
    Is it possible to restrict user to delete any content of Hard Disk like file,folder using java ?

  35. Neeraj Srivastava

    sir,plz post all basic programmes of string and array without using inbuilt method….
    like1.reverse of string,2.sorting of string, 3.removing char from string,4.duplicate the element of string,5.length of string,6.count total duplicate alphabet of string,7.count total words of string.8 programme of finding even and odd without using any operator.. etc, plz sir post this all as soon as possible,,, i daily refer ur site,,nd mostly concepts i hav learned from ur site….ur site is ULTIMATE sir,,,,u r great person sir,, u doing great job.thank u so much sir,,,,i am waiting for those programmes….

      1. neeraj srivastava

        sir,no another sites can understand like you,your real time example is mind blowing,before 3 months i didnot know much about JAVA,but when i started to learn about your site,then got real scenario of java,,,thank u so much sir,,

      1. neeraj srivastava

        sir,i already read all your concepts,,today i have good knowledge of collections ,string,but sir company ask for simple logics,so sir plzz,post all those programs in java without inbuilt method,i have read collection,and i know where to use which method,sir plzz do something..we all waiting for those programs.

  36. Sir,

    What is the difference b/w Iterable and Iterator why there are not related to Collection Framework Hierarchy

  37. Hi Sir,
    I m beginner in java having basic understanding in j2se and also have knowledge of j2ee.
    I m confused which framework should I learn which explore my knowledge in web development?

  38. Sir,

    Plez explain below Program how they are communicate and what happen there?

    ServletConfig conf=getServletConfig();
    ServletContext cont=conf.getServletContext();

    1. When a Web server starts, for the whole application one ServletContext object is created. This works as a global object that can be used by every Servlet of the application. Whenever a Servlet is loaded, while creating a Servlet object, the server also creates a ServletConfig object. A Servlet can access ServletContext object through ServletConfig object. For this reason, getServletContext() object returns an object of ServletContext. That is internally, ServletConfig is connected with ServletContext.

  39. sir plzzz…explain the , what is the difference between constructors and initializers with suitable example

  40. Dasari Rama Krishna

    Sir, iam create a simple registration form in this i have a checkboxes, and dorpdown list, i didnot store checkbox values,and dropdown list values in database by the servlet, so plez tell me how to store checkbox values and dropdown list values in database by the servlet programming. Will you plez explain a simple code for that.

    1. Sir,
      I want to store Multiple values in a database example knownlangauges like english,telugu,hindi thise are the three checkboxes values so i want stored in database. But i am try to store values by the getParameter(),but i donot store three values only single value is stored on database,but i know we have to use getParameterValues() method, i dont no how to use getParameter() method,plez explain about getParameterValues() method and give a simple exple for that.

  41. Hello Sir,

    I created a gui application with swing and oracle 10g, it is working in my system, but I want to provide the accessibility of database from the server so I create database on server but now when I am trying to access database with the help of application by providing IP of server in place of @localhost, it throwing an IO exception that network adapter could not establish the connection. please provide me the solution for this issue sir.

  42. sir,i wont know, why java is platform independent and how, with proper proof and example

  43. Prakhar Sharma

    Hello Sir,

    I am working as a Trainer in a company, and want to go in development, please suggest how to switch in development from training if, any also suggest me if about scope in training.

    Thanks

    1. Scope of training is very good and ever lasting. You must update your Java knowledge with the time like Hibernate, Spring, Struts, Web services etc. If you very good in these and capable to take laterals, freelancer will be fetching.

  44. Sir,I want get Installed Antivirus Details in java.Please guide me how it is possible to get any antivirus and is it possible to get its last update date and time.

    thank you

      1. Hi Sir,

        Myself Manjula from HR Department of Sunera Technolgies.

        You have trained our BC1 and BC2 on Java skills, participants were very happy with your teaching.

        Now that we have hired next set of Freshers who are from Top Universities. So we would like you to train them on Basic Java and Core Java.

        Please reach me on 8008366994

        Regards,
        Manjula Kolthur
        Sunera Technologies

  45. Sir, can I block Particular USB Port by using Java.means I am having 4 ports but I want to enable only one port so how can it will be done .
    Is there any way to do so.

    Thank You.

  46. Praveen Kumar

    Respected sir,
    you are really great one sir. You did me a great favour. I am searching for job from 2 years on java.. actually i don’t have knowledge on it before. even though i went for so many institutes didn’t gain any Knowledge on it. But after learning from your site I’m confident that now i can crack any interviews.
    Really Thanks a lot sir.

  47. Sir,
    How to Block Particular websites using Java Code ?
    Is there any solution for this .Please Reply

    Thanks

  48. subod kumar Naidu

    I have a drop down list in an applet.I want to sent the value from applet to servlet when i click on an item in that drop down list. Same way i want to receive an value/data/item from servlet to the same drop down list .Please help me.It’s urgent.

    1. See how this helps you.

      Applet to Servlet Communication

      Applet to Servlet communication is of 2 types:

      1. Text-based communication
      2. Object-based communication

      1) Text based Communication

      It is assumed that there exists a table Employee with following fields:

      empid number
      empname varchar2(15)
      empsal number(6, 2)

      The source code involves 3 programs:

      1. FetchRecordApplet.hmtl for calling applet
      2. FetchRecordApplet.java to display an UI to take user’s input of empid and forward it to the servlet. This UI receives the employee particulars from the servlet and displays them in the text fields.
      3. FetchRecordServlet.java to receive data from the applet, search for database Employee table, take the values and send them to the applet.

      When you run this program, you may get Security Exception. To overcome this, do the following:

      Browser menu bar  Tools  Internet Options  Security  Internet  Custom Level  Miscellaneous  Access Data Sources across domains  Select enable

      Also with

      Browser menu bar  Tools  Internet Options  Security  Local Intranet  Custom Level  Miscellaneous  Access Data Sources across domains  Select enable

      1st Program: FetchRecordApplet.html (copy to examplesWebApp)

      2nd Program: FetchRecordApplet.java (copy to examplesWebApp)
      (for applet file, web.xml file need not be written)

      import java.applet.*; import java.awt.*; import java.awt.event.*;
      import java.net.*; import java.io.*;

      public class FetchRecordApplet extends Applet implements ActionListener
      {
      TextField idField, nameField, salaryField ;
      Button fetchButton ;

      public void init( )
      {
      setLayout(new BorderLayout( ) );
      Panel p1 = new Panel( );
      p1.setLayout(new GridLayout( 2, 2, 5, 5 ) );
      p1.setBackground(Color.cyan);

      Panel p2 = new Panel( );
      p2.setBackground(Color.pink);
      p2.setLayout(new GridLayout( 2, 2, 5, 5 ));

      p1.add( new Label(“Enter Employee ID” ));
      p1.add( idField = new TextField(15) );
      p1.add( new Label(“Click for Details” ));
      p1.add( fetchButton = new Button(“Fetch Details” ));
      fetchButton.setBackground(Color.yellow);

      p2.add( new Label( “Employee Name” ));
      p2.add( nameField = new TextField(15));
      p2.add( new Label( “Employee Salary” ));
      p2.add( salaryField = new TextField(15) );

      fetchButton.addActionListener(this);

      add(p1, “North”); add(p2, “South”);

      }
      public void actionPerformed(ActionEvent e)
      {
      try
      {
      String str = idField.getText( );

      URL u1 = new URL(“http://home:7001/examplesWebApp/
      myFetchRecordServlet?t1=”+str);
      URLConnection ucon = u1.openConnection( );

      InputStream istream = ucon.getInputStream( );

      BufferedReader br = new BufferedReader(new
      InputStreamReader(istream));
      String details[ ] = new String[2];

      int i = 0 ;
      String str1=””;

      while( (str1 = br.readLine( ) ) != null )
      {
      details[i] = str1 ;
      i + + ;
      }
      br.close( );

      nameField.setText(details[0]);
      salaryField.setText(details[1]);
      }
      catch(Exception e1)
      {
      nameField.setText(“Some Problem” + e1);
      salaryField.setText(“Data not received”);
      }
      }
      }

      3rd Program: FetchRecordServlet.java (copy to examplesWebApp)

      import javax.servlet.*;
      import javax.servlet.http.*;
      import java.io.*;
      import java.sql.*;

      public class FetchRecordServlet extends HttpServlet
      {
      public void doGet(HttpServletRequest req, HttpServletResponse res) throws
      ServletException, IOException
      {
      res.setContentType(“text/plain”);
      PrintWriter out = res.getWriter( );
      String idno = req.getParameter(“t1”);

      try
      {
      Class.forName( “sun.jdbc.odbc.JdbcOdbcDriver” );
      Connection con = DriverManager.getConnection(
      “jdbc:odbc:snrao”,”scott”,”tiger”);
      Statement stmt = con.createStatement( );

      ResultSet res1 = stmt.executeQuery(“select *from Employee where
      empid=” + idno);
      res1.next( );

      String name = res1.getString(2);
      String salary = res1.getString(3);
      out.println(name);
      out.println(salary);
      out.flush( );

      res1.close( ); stmt.close( ); con.close( ); out.close( );
      }
      catch(ClassNotFoundException e)
      {
      out.println(“The database driver is not found”);
      }
      catch(SQLException e)
      {
      out.println(“Name not found”);
      out.println(“Salary not found”);
      }
      }
      }

      2. Object-based Communication:

      In this objects are passed and retrieved.
      The source code involves 3 independent programs.

      1st Program: ObjectCommunicationApplet.html


      2nd Program: ObjectCommunicationApplet.java ( copy it to the examplesWebApp
      directory)
      import java.applet.*; import java.awt.*; import java.awt.event.*;
      import java.net.*; import java.io.*; import java.util.*;

      public class ObjectCommunicationApplet extends Applet implements ActionListener
      {
      TextField idField, nameField, salaryField ;
      Button fetchButton;

      public void init( )
      {
      setLayout(new BorderLayout( ) );
      Panel p1 = new Panel( );
      p1.setLayout(new GridLayout( 2, 2, 5, 5 ));
      p1.setBackground(Color.cyan);

      Panel p2 = new Panel( );
      p2.setBackground(Color.pink);
      p2.setLayout(new GridLayout(2,2,5,5));

      p1.add( new Label(“Enter Employee ID” ));
      p1.add( idField = new TextField(15) );
      p1.add( new Label(“Click for Details” ));
      p1.add( fetchButton = new Button(“Fetch Details” ));
      fetchButton.setBackground(Color.yellow);

      p2.add( new Label( “Employee Name” ));
      p2.add( nameField = new TextField(15));
      p2.add( new Label( “Employee Salary” ));
      p2.add( salaryField = new TextField(15) );

      fetchButton.addActionListener(this);

      add(p1, “North”); add(p2, “South”);

      }
      public void actionPerformed(ActionEvent e)
      {
      try
      {
      String str = idField.getText( );

      URL u1 = new URL(“http://home:7001/examplesWebApp/
      myObjectCommunicationServlet”);

      URLConnection ucon = u1.openConnection( );

      ucon.setUseCaches(false);
      ucon.setDoInput(true);
      ucon.setDoOutput(true);
      ucon.setRequestProperty(“Content-Type”, “application/octet-stream”);
      // code to send data(employee id) to the servlet
      OutputStream ostream = ucon.getOutputStream( );
      ObjectOutputStream oos = new ObjectOutputStream(ostream);

      Integer i1 = new Integer( str );

      oos.writeObject( i1 );

      oos.flush( );
      oos.close( );
      // code to receive data(employee name and salary) from the servlet

      InputStream istream = ucon.getInputStream( );
      ObjectInputStream ois = new ObjectInputStream(istream);
      // get an object from the servlet that contains the data
      Object obj = ois.readObject( );
      Vector vect1 = (Vector) obj;
      ois.close( );

      String name = (String) vect1.elementAt( 0 );
      String salary = (String) vect1.elementAt( 1 );

      nameField.setText(name);
      salaryField.setText(salary);
      }
      catch(Exception e1)
      {
      nameField.setText(“Some Problem” + e1);
      salaryField.setText(“Data not received”);
      }
      }
      }

      3rd Program: ObjectCommunicationServlet.java

      import javax.servlet.*; import javax.servlet.http.*; import java.io.*;
      import java.sql.*; import java.util.*;

      public class ObjectCommunicationServlet extends HttpServlet
      {
      public void service(HttpServletRequest req, HttpServletResponse res) throws
      ServletException, IOException
      {
      res.setContentType(“text/plain”);

      ObjectInputStream ois = new ObjectInputStream(req.getInputStream( ));
      ObjectOutputStream oos = new ObjectOutputStream(
      res.getOutputStream( ) );
      res.setContentType(“application/octet-stream”);

      try
      {
      Integer idno1 = (Integer) ois.readObject( );
      String idno = idno1.toString( );

      Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
      Connection con = DriverManager.getConnection( “jdbc:odbc:snrao”,
      “scott”,”tiger”);
      Statement stmt = con.createStatement( );

      ResultSet res1 = stmt.executeQuery(“select *from Employee where
      empid = ” +idno);
      res1.next( );

      String name = res1.getString(2);
      String salary = res1.getString(3);

      Vector vect2 = new Vector( );
      vect2.addElement(name);
      vect2.addElement(salary);

      oos.writeObject(vect2);

      res1.close( ); stmt.close( ); con.close( );
      }
      catch(ClassNotFoundException e)
      {
      e.printStackTrace( );
      }
      catch(SQLException e)
      {
      e.printStackTrace( );
      }
      }
      }

  49. Hello sir,
    i went to a internship test today. there i had a question like this.
    Could you please provide your answer?

    How many objects created here?
    String s1 = new String(“String”);
    String s2 = “new”;
    String s3 = null;
    s1 = “test”;
    s2 = s1 + “done”;
    s3 = s2 + “”;

      1. Sir
        i don’t understand. i mean whenever we create a String variable or change an existing String variable values, a new String object is created. am i correct? and i answered as 6 (since there are 6 objects created).
        if i am wrong, could you please explain little more?

          1. Sir this is the question.
            How many objects created here?
            String s1 = new String(“String”);
            String s2 = “new”;
            String s3 = null;
            s1 = “test”;
            s2 = s1 + “done”;
            s3 = s2 + “”;

  50. Prakhar Sharma

    Sir,

    I want to prepare for the OCJP Certification please help me and suggest me, how to prepare for that, I dont know what kind of question they asked, please help me.

  51. sir I got a problem in (from HTML page) loading an image from my system into oracle table.
    it is unable to read the full path of the file what is the reason..? How can i overcome it please suggest me..?
    Here is my code…

    NAME

    FATHER NAME

    DOB

    Village/Town/City

    District

    IMAGE

    GENDERMale: Female:

    E-MAIL

      

  52. Sir,

    Do we have generics concept explained in here? I would love to see it here and learn more of it. The way the concepts are presented here are very very useful. Thank you in this regard.

  53. Sir,Where do I get information about network management system in java in which i have to monitor network computers for unauthorised users,inaccessible media,software upgradation,internet connection ,etc.
    please sir help me for that atleast tell me some sites where i get relative code for the same

    thank you

      1. Sir,I am in Mumbai .can you please help me to get some code so that i can manage by myself to do the application.

  54. Sir, could u plz provide some useful tips and tutorials site where i could learn iOS development and related materials.

  55. Hello Sir,

    1.) What is the difference between int a=10; and Integer ob=new Integer(10);
    2.) In Above example , What s difference between a.equals(ob) & a==ob.
    3.) And Also Describe the Pool String Concept & Integer Concept with example ??

  56. sampath kumar

    Hi sir,

    To create an immutable class in java, why the class should be declared as final. doesn’t it enough to create the instance variables of that class are final?? please explain me in a clear cut manner…..

    Regards,
    Sampath Kumar

  57. sampath kumar

    Hi sir,

    String s1 = “apple”;
    String s2 = new String(“apple”);

    In the first example, one object namely “apple” will get created in the Sting constant pool.
    In the second example, two objects will get created. One in String constant pool and other in heap memory.

    But the object “apple” is already there in the String constant pool. So my doubt is, does second example again place the “apple” object in the String constant pool .

  58. Hai Sir,

    Please provide a page numbers and a key/option to change from one page to another otherwise if we want to read the next topic we should go back and get it which is bit tedious… Page changing option will help a lot to the readers…

      1. Yes exactly like that.. If I open one unit I should be continuous without coming back to the index and going to next topic by clickking on it.. I expect reading like books..

    1. If you are a C or C++ programmer, you might have found much of the syntax of Java, particularly at the level of operators and statements, to be familiar. Because Java and C are so similar in some ways, it is important for C and C++ programmers to understand where the similarities end. There are a number of important differences between C and Java, which are summarized in the following list:
      No preprocessor
      Java does not include a preprocessor and does not define any analogs of the define, #include, and #ifdef directives. Constant definitions are replaced with static final fields in Java. (refer java.lang.Math.PI field for an example.) Macro definitions are not available in Java, but advanced compiler technology and inlining has made them less useful. Java does not require an #include directive because Java has no header files. Java class files contain both the class API and the class implementation, and the compiler reads API information from class files as necessary. Java lacks any form of conditional compilation, but its cross-platform portability means that this feature is very rarely needed.
      No global variables
      Java defines a very clean namespace. Packages contain classes, classes contain fields and methods, and methods contain local variables. But there are no global variables in Java, and, thus, there is no possibility of namespace collisions among those variables.
      Well-defined primitive type sizes
      All the primitive types in Java have well-defined sizes. In C, the size of short, int, and long types is platform-dependent, which hampers portability.
      No pointers
      Java classes and arrays are reference types, and references to objects and arrays are same as pointers in C. Unlike C pointers, however, references in Java are entirely opaque. There is no way to convert a reference to a primitive type, and a reference cannot be incremented or decremented. There is no address-of operator like &, dereference operator like * or −>, or sizeof operator. Pointers are a notorious source of bugs. Eliminating them simplifies the language and makes Java programs more robust and secure.
      Garbage collection
      The Java Virtual Machine performs garbage collection so that Java programmers do not have to explicitly manage the memory used by all objects and arrays. This feature eliminates another entire category of common bugs and all but eliminates memory leaks from Java programs.
      No goto statement
      Java doesn’t support a goto statement. Use of goto except in certain well-defined circumstances is regarded as poor programming practice. Java adds exception handling and labeled break and continue statements to the flow-control statements offered by C. These are a good substitute for goto.
      Variable declarations anywhere
      C requires local variable declarations to be made at the beginning of a method or block, while Java allows them anywhere in a method or block. Many programmers prefer to keep all their variable declarations grouped together at the top of a method, however.
      Forward references
      The Java compiler is smarter than the C compiler, in that it allows methods to be invoked before they are defined. This eliminates the need to declare functions in a header file before defining them in a program file, as is done in C.
      Method overloading
      Java programs can define multiple methods with the same name, as long as the methods have different parameter lists.
      No struct and union types
      Java doesn’t support C struct and union types. A Java class can be thought of as an enhanced struct, however.
      No enumerated types
      Java doesn’t support the enum keyword used in C to define types that consist of fixed sets of named values. This is surprising for a strongly typed language like Java, but there are ways to simulate this feature with object constants.
      No bitfields
      Java doesn’t support the (infrequently used) ability of C to specify the number of individual bits occupied by fields of a struct.
      No typedef
      Java doesn’t support the typedef keyword used in C to define aliases for type names. Java’s lack of pointers makes its type-naming scheme simpler and more consistent than C’s, however, so many of the common uses of typedef are not really necessary in Java.
      No method pointers
      C allows you to store the address of a function in a variable and pass this function pointer to other functions. You cannot do this with Java methods, but you can often achieve similar results by passing an object that implements a particular interface. Also, a Java method can be represented and invoked through a java.lang.reflect.Method object.
      No variable-length argument lists
      Java doesn’t allow you to define methods such as C’s printf() that take a variable number of arguments. Method overloading allows you to simulate C varargs functions for simple cases, but there’s no general replacement for this feature.
      Operators
      Java adds a new right shift operator >>> which inserts zeroes at the top end.
      The + operator scan be used to concatenate strings.
      Java adds another operator instanceof to identify objects.
      Operator overloading is not possible in Java.
      Classes
      Class definitions take the similar form in Java as in C++, but there is no closing semicolon.
      There is not scope resolution operator :: in Java.
      No destructors in Java
      No templates in Java.
      Inheritance in Java has the same effect an in C++, but the syntax is different.
      Java does not provide direct support for multiple inheritance. We can accomplish
      multiple inheritance by using interfaces.
      All instance variables have default values
      We need not externally define storage for static members like we do in C++.
      A class in Java can have an access specifier to determine whether it is visible outside the file.
      Arrays
      Arrays are quite different in Java. Array boundaries are strictly enforced. Attempting to
      read past the end of an array produces an error.
      One array can be assigned to another in Java.
      Strings
      Strings in C/C++ are arrays of characters, terminated by a null character. But strings in
      Java are objects.
      Strings can be concatenated with + operator.

      Differences between C and Java in a nutshell
      1. C is a procedural language, Java is object oriented
      2. C’s main structuring element are functions in files. Java organizes code in classes and packages, thereby providing better namespaces.
      3. C code gets compiled into machine code for a specific CPU. Java code gets compiled into bytecode which is interpreted on a virtual machine (JVM). Java code can get compiled into machine code as well (just-in-time compilers etc.)
      4. C does not have exceptions. Errors are handled through return codes.
      5. C types like structures (objects without methods) can be allocated on the stack. Java needs to allocate all non-primitives on the heap using expensive memory management functions (e.g. “new”).
      6. Arrays and strings in C are not bounds-checked. It is the programmers responsibility to stay within the allocated bounds
      7. lets programmers access memory addresses directly through the use of POINTERS. Pointers are variables which contain a memory address. Text (code), data, heap and stack areas are all within a programmers reach. Java lets only the virtual machine access a programs stack, e.g. to perform security checks.
      8. Java primitive types are fixed in length. C types can vary per machine. This lets C take maximum use of hardware specifics (e.g. 16 bit register size vs. 32 bit register size). It also creates portability problems.
      9. C has a preprocessor and include files. The preprocess works like a macro processor which substitutes macros in the program file.
      Top Ten Advantages of Java over C++
      Sub-systems can be modelled with packages
      Object-oriented systems typically consist of groups of classes, or “sub-systems”, which provide services, rather than a whole bunch of individual classes. The Java package mechanism provides direct support for sub-systems.
      All pointer manipulation is done by the compiler
      Java takes away the burden of pointer manipulation from the developer. Objects are actually pointers, but there is no need to de-reference objects, take addresses or use a special notation. All that is handled internally by the compiler.
      Automatic garbage collection
      In C++, the memory for local variables is freed automatically when they go out of scope, but it’s up to developers to free memory which is allocated dynamically. In Java, the run-time system performs automatic garbage collection of dynamically-allocated memory.
      No need for header files
      C++ classes are typically written in two files: a header file for the class declaration and a separate source file for the implementation. The only use for the header file is so that it can be included in the compilation of other source files which use the class.
      Java doesn’t use header files. An entire class is written in a source file. The compiler can look at other files when compiling a class to check function prototypes and access specifiers.
      Method functions are “virtual” by default
      Designers of a C++ class need to decide which methods could be overriden in the future by derived classes, and declare these methods virtual. In Java, methods are considered virtual by default, unless explicitly declared otherwise. This is more in keeping with the object-oriented principle of keeping derived class information out of base classes.
      Rich class library
      The standard C++ library is relatively small, consisting mainly of stream operations, plus whatever’s in the C Standard Library. The proposed ANSI standard library adds a lot more functionality, but it’s still some time before it becomes an official standard and becomes supported by all compiler vendors.
      Java comes with a rich class library, with support for strings, collection classes, network operations, user interface components, and more.
      Robust exception handling
      The Java exception mechanism is similar to that in C++, except that Java insists on correct exception specifiers for all functions. This guarantees that the behaviour of a function is predictable because all its exceptions are declared as part of the function declaration.
      Standard sizes for basic data types
      C++ makes no guarantees about the representation of basic data types. Simple types like int and float are typically implementation based on what’s convenient for the underlying machine. Java specifies standard sizes for its basic data types.
      Built-in multi-threading
      Java has built-in support for spawning and controlling multiple threads of control in a single process.

  59. Hello sir.
    i always wanted to know about callback method? i did a Google search and visited many sites but i didnt get full idea of it.
    could you please explain with example?

    Thank you

    1. Callback method is that one which is implicitly called by the software, in our case, JVM. Good example is main() method. You write the main() method, are you calling it? No it is called automatically by JVM at the start of execution. main() method is known as callback method.

      All applet methods init(), start() etc. are callback methods called by Browser at appropriate times for the smooth execution of applet.

      run() method in Thread is callback method.

      paint() method is a callback method called implicitly when frame is created or when frame is resized.

      In Servlets, service() method is callback method.

      Like that many methods are in frameworks like Struts, Spring and Hibernate.

      1. Thank you sir,
        I completely understood. So we cannot create call back method but we can override it ?

  60. Hello Sir,
    I want a code to insert data in table as well as fetch that data to edit,delete,print in tabular format in struts1.3

    1. Please do not ask me for code. To write the code it takes sometime. But I have got lot of other activities.

      I will give an idea. Develop the code slowly; it increases your skills, even though at the beginning it may takes a little bit more time. Write a JDBC code in Action class. To print in tabular form use JSP.

  61. Hi,

    When we extend a class, will subclass get a copy of super class? Because how will the superclass members available to subclass when we extend it?

    1. If it is the case, if a class has 10 super classes, then the last subclass will get 10 copies of super classes. Is it not memory and processing waste. I do not think any language designer venture it. Apart each class object pointing the its own variables, it is designed that all the subclass objects also point the same super class variable maintaining encapsulation.

  62. Hi,

    As we know JAVA is platform independent because of JVM. My question is if we would have developed CVM(C Virtual Machine) for C langauage, then we should have had C as a platform independent. Isn’t it? And slight modifications to the C language made C as a JAVA that means all the features of JAVA might have come in C. It would have saved so many things. What do you say? Was it a necessary to develop a new language JAVA?

    1. Your are 100 right in your option. I will say a small example. The Earth gets gravity due to lead (Pb) metal in the earth. Somebody asked Scientist Einstein if all the lead is removed from earth, then the earth looses its gravity and every object floats in the air. Einstein replied yes definitely all objects float. But the Scientist asked, is it possible to remove entire lead from earth? Same answer for your question.

      Java was released in 1995, almost 20 years back. But so far no software company (including the software giants like IBM, Microsoft) did not able to develop JVM or nearer to JVM. That is the secrecy of JVM.

      A day may come, as you said, every language may becomes platform-independent. But is it possible?

      1. Yes it will possible one day in future. Any way thanks for your answer with an excellent example.

  63. sampath kumar

    Hi Sir,

    byte a=10;
    byte b=20;
    byte c=a+b;
    S.O.P(c);

    It is giving me compilation error……But the following program is working well

    final byte a=10;
    final byte b=20;
    byte c=a+b;
    S.O.P(c);

    please clarify me……..what is the reason behind this

    Regards,
    Sampath Kumar

      1. sampath kumar

        Thanks for the reply……How come java compiler know it?? pls need detail explanation on it

          1. Hi all, thanks for sharing ur answers but the fact is that int or smaller mathematical expressions(+,-,*,/ etc) always results to an int. But how the following program works well even if we add two byte non final varibales.

            byte a=10;
            byte b=10;
            a+=b;
            S.O.P(a);

            Why casting is not necessary here and how come does it perform autocasting?

    1. With generics everything goes smooth. You need not write wrapper objects. It is the purpose of Generics.

      Before JDK 1.5 code:

      int x = 10;
      Integer i1 = new Integer(x);
      new Stack().push(i1);

      From JDK 1.5:

      int x = 10;
      new Stack().push(x);

      That is difference with Generics feature.

  64. Chaitanya Krishna

    Hi Sir,
    Recently Java 8 was released.Could you please briefly explain the differences and advancements that are there in java 8.

    Thanks in advance.

    Regards
    Chaitanya Krishna
    Sunera Technologies.

  65. Hi Sir,
    Could u please let me know that if suppose I have the hirarchy like
    class a{ Sysout}
    class b extends a{ Sysout}
    class c extends b{ Sysout}
    class d extends c{ Sysout}
    and from test class I need to call “a” class method so how to achieve this.

    Thanks in advance.

  66. Hello sir,

    I really appreciate your work. My request to you is to add SEARCH OPTION in your web site. That will be a great help.

  67. package UserPackage;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;

    public class CalculationPage
    {
    private final String url=”jdbc.odbc:XE”;
    private final String user=”system”;
    private final String password=”123″;
    int amount=0;
    String ATName=””;

    static
    {
    try
    {
    Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
    System.out.print(“driver loaded”);
    }
    catch(Exception ee)
    {
    System.out.print(“\nIn calculation java driver “+ee);
    }
    }

    public CalculationPage()
    {
    System.out.print(“\nObject of CalculationJava class created\n”);
    }

    public boolean amountCalculation(int AccountNo,String service,int amt)
    {
    boolean f=false;
    try
    {
    System.out.print(“\nInside amountCAl method 0”);
    Connection co=DriverManager.getConnection(url,user,password);
    System.out.print(“\nInside amountCAl method 0.6”);
    PreparedStatement st1=co.prepareStatement(“select * from INDEXLIST WHERE ACCOUNTNO=?”);
    System.out.print(“\nInside amountCAl method 1”);
    st1.setInt(1,AccountNo);
    ResultSet rs1=st1.executeQuery();
    System.out.print(“\nInside amountCAl method 2”);

    if(rs1.next())
    {
    ATName=rs1.getString(“ACCOUNTTABLENAME”);
    }
    else
    {
    System.out.print(“Invalid Account”);
    }

    System.out.print(“\nCode reach till Name “+ATName);
    rs1.close();
    st1.close();
    ///taking new entry check it and manipulate
    PreparedStatement st2=co.prepareStatement(“select * from “+ATName+” WHERE ACCOUNTNO=?”);
    st2.setInt(1,AccountNo);
    ResultSet rs2=st2.executeQuery();

    if(rs2.next())
    {
    amount=rs2.getInt(“AMOUNTBALANCE”);
    }
    System.out.print(“\nCode reach till Name amount 1 “+amount);
    rs2.close();
    st2.close();
    if(service.equals(“Deposit”))
    {
    amount=amount+amt;
    }

    else
    {
    if(amount<=1000)
    {}
    else
    {
    amount=amount-amt;
    }
    }
    System.out.print("\nCode reach till Name amount 2 "+amount);
    f=true;
    co.close();
    }
    catch(Exception ep)
    {
    System.out.print("\nIn amountCAlculation Method Error No. "+ep);//1st excception thrown
    }
    return f;
    }

    public boolean createEntry(String ser,String WName,int WCIFNo,int WAccountNo,String WSDate,String WSPlace,int WChequeNo,int WDDNo)
    {
    boolean ce=false;
    try
    {
    Connection co=DriverManager.getConnection(url,user,password);
    PreparedStatement st=co.prepareStatement("insert into "+ATName+" VALUES(?,?,?,?,?,?,?,?,?,?,?,?)");
    st.setString(1,WName);
    st.setInt(2,WAccountNo);
    st.setInt(3,WCIFNo);
    st.setInt(4,amount);
    st.setString(5,ser);
    st.setString(6,WSDate);
    st.setString(7,WSPlace);
    st.setInt(8,0);
    st.setInt(9,0);
    st.setInt(10,0);
    st.setInt(11,WChequeNo);
    st.setInt(12,WDDNo);
    st.executeUpdate();
    ce=true;
    st.close();
    co.close();
    }
    catch(Exception e)
    {
    System.out.print("\nException in data Entry "+e);//2nd excception thrown
    }
    return ce;
    }
    }

    it is giving /throwing exception both the excetion plzz help me to resolve this exception

  68. Why do we need exception handling in java,without that also can implement.
    Below snipet. Say array with 10 element
    int array[]=new int[10];
    to get any element check with its size so we can avoid runtime error,

  69. Why there should be only one public class per source file, Any technical reason.
    Why hashtable wont allows null as key/value but hashmap allows.

      1. Hello sir!
        First of all thank you very much for your tutorials.
        Actually Hashtable allows null as key. for example we can do like this

        Hashtable table = new Hashtable();
        table.put(null, new Double(3434.34));

    1. i think its give indication to new operator to Reserved memory for this class.

      Student s=new Student();

  70. 1) To read HTML from any website say “http://www.google.com” ( You can use any API of inbuilt APIs in Java like URLConnection )
    2) Print on console the HTML from the url above and save it to a file ( web-content.txt) in local machine .
    3) JUnit test cases for the above programme.

    sir ,first two step completed but help me in third step how to make test case ? please some suggestion is required
    thanks

  71. abstract class MainMethodOverloadDemo {

    public static void main(String[] args) {
    main(10);
    /*main(10,12.3f);
    main(123.4);
    MainMethodOverloadDemo demo=new MainMethodOverloadDemo();
    demo.main(20);
    demo.main(20, 20.13);
    demo.main(123.45);*/

    }
    static void main(int i)
    {
    System.out.println(“i=”+i);
    }
    void main(int j,float f)
    {
    System.out.println(“j”+j);
    System.out.println(“f=”+f);
    }
    void main(Double d)
    {
    System.out.println(“d=”+d);
    }
    }
    class A extends MainMethodOverloadDemo
    {
    A()
    {
    MainMethodOverloadDemo demo=new A();
    demo.main(100);
    demo.main(109, 125.67f);
    demo.main(123.456);
    }
    }

    Sir,is this program is right and i have to execute class A and call all the methods present in other class

  72. Hello Sir,
    can we access main method of abstract class in another general class ?

    I have to access all the methods from below program to another class suppose class A,please tell me how to access that methods

    abstract class MainMethodOverloadDemo {

    public static void main(String[] args) {
    main(10);
    }
    static void main(int i)
    {
    System.out.println(“i=”+i);
    }
    void main(int j,float f)
    {
    System.out.println(“j”+j);
    System.out.println(“f=”+f);
    }
    void main(Double d)
    {
    System.out.println(“d=”+d);
    }
    }

      1. package sample_03_03_2014;

        abstract class MainMethodOverloadDemo {

        public static void main(String[] args) {
        main(10);
        /*main(10,12.3f);
        main(123.4);
        MainMethodOverloadDemo demo=new MainMethodOverloadDemo();
        demo.main(20);
        demo.main(20, 20.13);
        demo.main(123.45);*/

        }
        static void main(int i)
        {
        System.out.println(“i=”+i);
        }
        void main(int j,float f)
        {
        System.out.println(“j”+j);
        System.out.println(“f=”+f);
        }
        void main(Double d)
        {
        System.out.println(“d=”+d);
        }
        }
        class A extends MainMethodOverloadDemo
        {
        A()
        {
        MainMethodOverloadDemo demo=new A();
        demo.main(100);
        demo.main(109, 125.67f);
        demo.main(123.456);
        }
        }

        Sir I have to execute class A,can you please help me for that

  73. I was very pleased to discover this web site. I need to to thank you for your time
    for this wonderful read!! I definitely really liked every
    part of it and I have you saved as a favorite to check out new things on your website.

  74. Dear sir,

    Could you please explain me about following 2 programs???

    1)int a=5,b=6,c=7;
    c=++b+c++;
    System.out.println(c);

    O/p is 14 but how???

    2) float a=2;
    if(a==2)
    System.out.println(“true”);
    else
    System.out.println(“false”)

    O/P is true=> but how?? a is float type and 2 is integer type.. how it was true??

      1. Thanks for your response sir,

        c=++b+c++; => in this statement 1st b becomes 7 and c(7) both are added and asigned to c ..so c=14,, and again v have c++.. so it wil be like 14++ is equal to 15…..?????????

      2. Dear Sir,
        i completed my b.tech(e.c.e) in 2009. i currently working with core related company, i have 3 years of experience in electronics. But now i want to change my carrier field (software).
        Sir please suggest me is there any chance to get software job now. can i get good job in 1year?

  75. Is there any facility to courier your study material for people who are outside Hyderabad

    Thanks
    Sunny Sachdeva

  76. Hello sir,

    I am very happy for your response….
    It is really helping…

    Sir, I have a doubt..?

    How the below statement is processed…?

    int x=-42,y;

    y=x>>-2;

    what is the value of y?

    Thank you in advance sir….

  77. Hi, when i execute below program,
    class F
    {
    final int a;
    F()
    {
    a=10;
    }
    void display()
    {
    System.out.println(a);
    }
    public static void main(String args[])
    {
    F ob = new F();
    ob.display();
    }
    }
    Output is: 10

    But when i execute below program,

    class F
    {
    final int a;
    F()
    {

    }
    void display()
    {
    System.out.println(a);
    }
    public static void main(String args[])
    {
    F ob = new F();
    ob.display();
    }
    }

    Output is: Error why so???

    In second program, the constructor should initialize the final variable with it’s default value (i.e 0) in the same way it initializes the instance variable in the first program. But Why error???

    Regards,
    sampath kumar

  78. What is meant by instance initilisation block and it’s rules??

    When static initialisation block is useful??

    Regards,
    sampath

  79. The static variable gets memory only once in class area at the time of class loading. Here class loading means??

    regards,
    sampath

  80. Sir
    I am practicing on java string example and want to compress a java string of larger length into smaller one can u please provide me any idea what to do?

    thank you in advance

  81. Why public class name should be same as the java file name?? When i try to define two classes as public in the same java file, it is throwing following error while compiling…..>Why??

    C.java:1: error: class A is public, should be declared in a file named A.java
    public class A
    ^
    C.java:15: error: class B is public, should be declared in a file named B.java
    public class B
    ^
    2 errors

    Regards,
    sampath kumar

  82. this progarm is for dra a line by user as like ms-paint..
    Sir, it is giving null ponter exception plzz help me to remove this exception……

    import java.awt.*;
    import java.awt.event.*;

    public class Project extends Frame
    {

    Image im;
    Graphics gs;
    Label locX,locY;
    int h,w,x=0,y=0,spX=0,spY=0,epX=0,epY=0;
    String msg=””,corX=””,corY=””;

    public Project()
    {
    w = getSize().width;
    h = getSize().height;
    setForeground(Color.black);

    im=createImage(h,w);
    gs=im.getGraphics();
    gs.setColor(Color.white);
    setLayout(new FlowLayout());
    locX=new Label();
    locY=new Label();
    setLayout(new FlowLayout());
    addWindowListener(new win());
    addMouseListener(new moulist());
    addMouseMotionListener(new moumovlist());
    add(locX);
    add(locY);
    }

    public class win extends WindowAdapter
    {
    public void windowClosing(WindowEvent we)
    {
    System.exit(0);
    }

    }

    public class moumovlist extends MouseMotionAdapter
    {
    public void mouseDragged(MouseEvent me)
    {

    spX=me.getX();
    spY=me.getY();
    gs.drawLine(spX,spY,epX,epY);
    repaint();
    }

    public void mouseMoved(MouseEvent me) {
    x = me.getX();
    y = me.getY();
    corX=String.valueOf(x);
    corY=String.valueOf(y);
    locX.setText(corX);
    locY.setText(corY);
    repaint();
    }

    }

    public class moulist extends MouseAdapter
    {
    public void mouseClicked(MouseEvent me)
    {
    x=me.getX();
    y=me.getY();
    msg=”clicked”;
    repaint();
    }

    public void mousePressed(MouseEvent me)
    {
    x=me.getX();
    y=me.getY();
    spX=me.getX();
    spY=me.getY();
    msg=”pressed”;
    repaint();
    }

    public void mouseReleased(MouseEvent me)
    {
    x=me.getX();
    y=me.getY();
    epX=me.getX();
    epY=me.getY();
    msg=”released”;
    repaint();

    }

    }

    public void paint(Graphics g)
    {
    g.drawString(msg,x,y);
    g.drawLine(spX,spY,epX,epY);
    g.drawImage(im,0,0,this);
    }

    public static void main(String args[])
    {
    Project obj=new Project();
    obj.setSize(new Dimension(500,500));
    obj.setVisible(true);
    obj.setTitle(“hi”);
    }

    }

          1. sir,
            but same program i’m using in applet it runs withot any exception..error is ocurring frame
            as i have to make a windowed program..??

  83. Hi,

    why can’t we use this keyword in a static method?. please explain it in a clear cut manner.

    Regards,
    sampath

    1. “this” refers the current object or specific (or particular) object. For example,

      public class Demo
      {
      int x;
      public void display(int x)
      {
      this.x = x;
      }
      }

      Now if you call as d1.dipslay(10), then d1 gets a value of 10 and if you call d2.display(20), d2 gets a value of 20. In first case this refers d1 and in second case this refers d2. If display() is static, display() can be called without the help of an object. See this.

      public static void display(int x)
      {
      this.x = x; // error
      }

      now I call the method directly as display(100) without the help of an object. Then 100 should be given to which object. You tell me. But this refers always an object. For this reason, this is not allowed from static methods.

  84. Hi,

    Why this keyword is not used in a static method?? pls explain in a clear cut manner…..

    Regards,
    sampath

  85. Hello Sir, I have completed studying core java part but want full in depth about every topic as i dont want to just read every thing just by defination and examples want to learn how to apply this in real time sceniories so please guide me or provide some website for getting in depth information about every topic

    Thank you in advance for looking into it.

      1. Sir maine aap se question pucha tha ap jawab nai de rahe ho..plzz rply…is there any Action adapter class or not..???

  86. Hi,
    Sir,
    Before last six months you had suggested me Java: The Complete Reference for core java. The book is very useful for me and Thank you for the suggestion.
    Now I want to learn Servlet so please suggest me good book for beginner . I am in waiting for your reply.

  87. import java.awt.event.*;
    import java.awt.*;

    public class SimpleInterest extends Frame implements ActionListener
    {

    Button b;
    int x,y,z,ss,aa;
    TextField a,p,i,r,t;

    public SimpleInterest()
    {
    addWindowListener(new window());

    Label P =new Label(“Principal”);
    Label R=new Label(“Rate”);
    Label tt=new Label(“Time”);
    Label si=new Label(“SI”);
    Label A=new Label(“Amount”);

    a=new TextField();
    p=new TextField(10);
    i=new TextField();
    r=new TextField(10);
    t=new TextField(10);

    b=new Button(“Calculate”);

    add(b);

    add(a);
    add(p);
    add(i);
    add(r);
    add(t);

    add(P);
    add(R);
    add(tt);
    add(si);
    add(A);

    //b.addActionListener(this);

    }

    public void actionPerformed(ActionEvent ae)
    {
    String x1,y1,z1,ss1,aa1;
    x1=p.getText();
    x=Integer.parseInt(x1);
    y1=r.getText();
    y=Integer.parseInt(y1);
    z1=t.getText();
    z=Integer.parseInt(z1);
    ss=(x*y*z)/100;
    aa=ss+x;
    ss1=String.valueOf(ss);
    aa1=String.valueOf(aa);
    i.setText(ss1);
    a.setText(aa1);
    }
    public class window extends WindowAdapter
    {
    public void windowClosing(WindowEvent we)
    {
    System.exit(0);
    }
    }

    public void paint(Graphics g)
    {

    }

    public static void main(String args[])
    {
    SimpleInterest ob=new SimpleInterest();
    ob.setSize(new Dimension(400,400));
    ob.setVisible(true);
    ob.setTitle(“Simple Interest”);
    }
    }

    it it showing only amount…why so..
    and it want this solution in frame ……plzz
    explain…?????

  88. import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;

    public class AppWindow extends Frame
    {
    int x,y;
    String msg=””;
    public AppWindow()
    {
    addMouseListener(new MyMouseList(this));
    addMouseMotionListener(new MyMouseMov(this));
    addWindowListener(new WinList(this));
    }

    public void paint(Graphics g)
    {
    g.drawString(msg,200,200);
    }

    public static void main(String args[])
    {
    AppWindow a=new AppWindow();
    a.setSize(new Dimension(600,600));
    a.setTitle(“Practice frame”);
    a.setVisible(true);
    }
    }

    class MyMouseList extends MouseAdapter
    {
    AppWindow aa;
    public MyMouseList(AppWindow aa)
    {
    this.aa=aa;
    }

    public void mousePressed(MouseEvent me)
    {
    aa.x=me.getX();
    aa.y=me.getY();
    aa.msg=”Clicked At “+aa.x+”,”+aa.y;
    aa.repaint();
    }
    }

    class MyMouseMov extends MouseMotionAdapter
    {
    AppWindow aa;
    public MyMouseMov(AppWindow aa)
    {
    this.aa=aa;
    }
    public void mouseMoved(MouseEvent me)
    {
    aa.x=me.getX();
    aa.y=me.getY();
    aa.showStatus(“Mouse Moving At ” + aa.x + “,” + aa.y);
    }
    }

    class WinList extends WindowAdapter
    {
    AppWindow aa;
    public WinList(AppWindow aa)
    {
    this.aa=aa;
    }
    public void windowClosing(WindowEvent we)
    {
    System.exit(0);
    }
    }

    plzz resolve the error occurring in aa.showStatus(),…it is saying cannot find symbol

  89. Sir,

    I never seen java tutorial like yours. You explained all topics very clear. Only suggestion to you is it would be nice if you maintain index for each topics. For example : if we open collections topic there is no proper order of index like from which link we need to refer in need to start referring collections topics. When i opened collections topic i find difficulty in order to search the initial link from where collections topic begins. I felt like this in all topics. I am sorry if i am wrong. This is the only suggestion i want to give. Remaining all are excellent.

    Thanks a lot Sir for making this website. Thanks you so much, this helped me a lot.

      1. Thanks a lot Sir for your immediate response. Just now I checked your changes. Now it is good to read. Thanks a lot once again.

  90. Abhishek Thapliyal

    class Dimen
    {
    int l,b,h;
    Dimen(int l,int b,int h)
    {
    this.l=l;
    this.b=b;
    this.h=h;
    System.out.print(“\nLength = “+l);
    System.out.print(“\nBreadth = “+b);
    System.out.print(“\nHeight = “+h);
    }
    }

    class vol extends Dimen
    {
    int volume()
    {
    return l*b*h;
    }

    }

    public class Inhritence {

    public static void main(String[] args)
    {
    Dimen d=new Dimen(2,3,4);
    vol v=new vol();
    System.out.print(“\nVolume == “+v.volume());
    }
    }

    Sir,
    why this program is giving error…??
    if i am using super(2,3,4) in sub class then it is fine why so…??
    i want’t breif explanation…..

    1. First add this public Dimen() {} in Dimen class as sub class construct calls super class constructor and is will not be created as you are overloading the constructor.

      Second point is the values 2, 3 and 4 belong to d object but not v object. v object takes default 0 values.

  91. class MyMouseAdapter extends MouseAdapter {
    AdapterDemo adapterDemo;
    public MyMouseAdapter(AdapterDemo adapterDemo) {
    this.adapterDemo = adapterDemo; ///what value this is ssigninig here..???
    }
    // Handle mouse clicked.
    public void mouseClicked(MouseEvent me) {
    adapterDemo.showStatus(“Mouse clicked”);
    }
    }
    ///plz explain this code sir..??

  92. Sir please give me the answer..
    What is connection pool? and how to manage connection pool in jdbc?

    Sir please explain this things with some code..

    Thank you in advance

  93. HI can u please help me….
    here i just want print only integer value and remove all string value
    from list please correct the code…
    public class B
    {
    public static void main(String[] args)
    {
    List l= new ArrayList();
    l.add(1);
    l.add(2);
    l.add(“e”);
    l.add(“aa”);
    l.add(4);

    System.out.println(l);
    }
    }

    1. Here is the code.

      import java.util.*;
      public class B
      {
      public static void main(String[] args)
      {
      List l= new ArrayList();
      l.add(1);
      l.add(2);
      l.add(“e”);
      l.add(“aa”);
      l.add(4);

      Iterator it = l.iterator();
      while(it.hasNext())
      {
      if(it.next() instanceof String)
      {
      it.remove();
      }
      }
      System.out.println(l);
      }
      }

  94. Hi sir
    Please tell me what are the access specifiers and access modifiers in java?
    Is there any difference between access specifiers and access modifiers?

  95. Hi. .
    Sir I want to join in testing tools course.please suggest me which institute is better for it.

  96. sir,
    give me………….how to create an employee registration form in “database management system” project with coding ……………………………………using front end java and back end sql……………………………………………………………………………………sir give me one example………………..sir, i was so respectfull to u.

  97. Hi

    How to implement single linked list in java using LinkedList class. I have tried but i am not getting it.. Please help me in this regard

    regards,
    Sampath

  98. sir plz send me d oracle download link(for jdbc purpose) and structs download link.I already downloaded some oracle databases bt those are suitable for sql operations only not for jdbc…

  99. List list=new ArrayList() vs ArrayList list=new ArrayList(). Could give me some real time examples.

  100. Hi,

    I am getting confused with the following statement.\

    Iterator it = al.iterator(); where al is reference to the ArrayList class.\

    Could you please explain the above statement in detail

    Regards,
    Sampath

  101. Hi,

    Does ArrayList class in java collections, implemants all the methods of an Iterator interface???

    Regards,
    Sampath

  102. collection framework(Data structure) topics can not be found after 1st page(2 to 6 pages are not found),why this problem is happened?

  103. But class seems to can be declared protected in an inner class…….How to access the methods declared in such protected inner classes outside the package???

    Regards,
    Sampath Kumar

  104. When I create user defined exception be extending RuntimeException it makes uncheked, If class extends Exception then it makes Checked Exception. How it will JVM understand checked & unChecked when runtimeException extends Exception. Even I saw the both class source code. Nothing much difference.
    Could you explain please?

  105. Can We write a business logic code at annotations?
    @Override its interface, How its check method being overddien properly or not by subclass?

  106. Sir Please guide me
    are there better opportunities in java testing and what are the salary range in this line.
    and what will be the future?

      1. But class seems to have been declared protected in an inner class…….How to access the methods declared in such protected inner classes???

        Regards,
        Sampath Kumar

  107. Hi,

    Can we declare class as protected??? I heard that, we can declare the class as protected but only subclasses are able to create the object for that super class. But when i tried the same, iam getting an erros as “modifier protected not allowed here”. Please explain it???

    Regards,
    Sampath kumar

  108. for fresher having java knowledge which platform will be better to choose if company is providing option to choose platform for training options in SAP,ORACLE BI and JAVA?

  109. Prakash Kumar Sahu

    Hello Sir,
    Is software job insecure really ?
    If no then how can i have a secure life in IT field.

    Please Reply Sir…

    1. What you mean by secure? Your job should be guaranteed even when you do not satisfy your employer. In the world, no job is guaranteed. The only difference is software employment does not have any unions or associations to fight against injustice done a software employee where as others has got like banks, LIC has strong unions to fight.

  110. sir,
    i have written below program….i got the output But i did not understand it pls tell me

    class Request
    {
    static void disp( )
    {
    Request r1=new Request();
    Request r2=new Request();
    System.out.println(r1);
    System.out.println(r2);
    }
    public static void main(String ar[])
    {
    disp( );
    }
    }

    output:- [email protected]
    [email protected]

    Sir, what is the meaning of the output ..?
    what it is displaying….?
    Please leave comments…
    Thanks in advance..

    1. To call a method in Java, you require an object. But to call a static method, you don’t require an object.

      final has 3 meanings in 3 places. final variable cannot be reassigned (here, works like const of C), final method in a super class cannot be overridden by its subclass and final class cannot be inherited by another class.

      Refer:

      http://way2java.com/oops-concepts/static-keyword-%e2%80%93-philosophy/

      http://way2java.com/oops-concepts/many-meanings-of-final-keyword-%e2%80%93-in-and-outs/

  111. Hi,

    When should we use “throws” keyword. Explain the rules that we need to follow when we use “throws” keyword with awesome examples.

    Regards,
    Sampath

    1. First property to be noted is a constructor can not be overridden. If a construct is abstract and if not permitted to override, then what is the use abstract?

      If a constructor is synchronized and there by locked by one object, then you cannot create other objects of the class. For this reason, a constructor cannot be synchronized.

    1. It is part of JVM. JIT stands for Just-In-Time compiler. Do not misguide by the word compiler. Java’s bytecode conversion to binary code can be treated as another compilation. Here, compilation means format change. JIT compiler preserves the binary code of a method first time when it is called. If called again and again, the same binary code stored earlier is called but does not convert every time when the method is called.

  112. Hi Sir,

    What are the actions of Class loader and JVM in java????
    Explain in a very clear cut manner??

    1. JDK comes integrated with many components like JVM JRE, Class loader, debugger, bytecode verifier, standard libraries etc.

      When a program is compiled, the .class file generated is stored in hard disk. When the class is executed, it must be loaded from the hard disk into the RAM. This is done by the class loader. JVM job is to covert platform independent bytecode into platform dependent binary code(machine code). To execute the program, it requires package classes like System and String etc. These are also loaded. JVM and libraries put together known as JRE (Java Runtime Environment). So basically, JDK comes with a compiler and JRE. Browser contains JRE only but not a compiler because to browser we give pre compiled programs (known as applets).

  113. Sir,
    I am a beginner in java when came to “this and super” keywords I confused…why it s used, what is the purpose..? Is it for constructor chaining..? Can you please make me clear…?
    Thanks in advance….

    1. In Java there are this, super, this() and super().

      1. “this” keyword is used to refer an object
      2. “super” keyword is used to call super class variables and methods by the sub class when they are overridden by the subclass.
      3. this() is used to access (call) one constructor from another where both constructors belong to the same class.
      4. super() is used to access super class constructor from sub class constructor.

      A) this() and super() are used with constructors only.
      B) super is with variables and methods only
      C) this is used with objects only.

  114. class Simple
    {

    public void finalize()
    {
    System.out.println(“Object is garbage collected”);
    }

    public static void main(String args[])
    {
    Simple ob1 =new Simple();
    Simple ob2 =new Simple();
    ob1=null;
    ob2=null;
    System.gc();
    System.out.println(“Hello World”);

    }
    }

    I have two Questions on the above program
    First: why “Hello World” will get printed first though the garbage collector is called by using System.gc() before printing the “Object is garbage collected” . What’s the reason in spite it is not using any object for printing the message “Object is garbage collected”.

    Second: I heard that, finalize() method will be called by the Garbage Collector depending upon the number of unreferenced objects. Here there are 2 unreferenced objects. So, the message “Object is garbage collected” should be displayed twice. But it is displaying the mesaage only once.

    I would be very greatful to you, if you clarify me with all the possibilities.

    1. On my system it is printing twice mostly and very less times prints only once. I got JDK 1.7 version.

      Hello World is printed first because first preference is given to program execution by the garbage collector. Garbage collection comes into action when the processor is free only (or if no memory is available, it comes into action immediately).

  115. Hi sir,
    What does thread occupy the same address space mean?? Hopefully, i will get an answer for the previous post and for this as well…..
    Regards,
    Sampath Kumar

    1. A thread being an object stored in heap area. Every thread has got its own stack and program counter and these are stored in stack.

      Every thread has a reference to the class to which it belongs.

      This is general; but each JVM comes with its own implementation of memory. For this, there is no correct answer.

      But do not worry much about memory problems and memory is implicitly managed as per JVM architecture. But has a light idea of memory management like constant pools etc.

      Java stacks are created private to a thread. Every thread will have a program counter (PC) and a java stack. PC will use the java stack to store the intermediate values, dynamic linking, return values for methods and dispatch exceptions. This is used in the place of registers.

  116. Hi Nageswara Rao,

    Do thread occupy stack memory or heap memory? As far as i know, thread occupy heap memory as we are allocating memory using new operator. But i referred some sites and way2java even where it is written as stack memory…..could you please help in this regard???

    Regards,
    Sampath Kumar

    1. There is not DataInputStreamReader, it is DataInputStream. The difference between DataInputStream and BufferedReader is, the first one belongs byte streams introduced with JDK 1.0 and the later is character streams introduced with JDK 1.1. The most significant is, the readLine() method of DataInputStream is deprecated but not of BufferedReader.

  117. Sir, I completed MCA in 2009. Now i know core and advanced java…but now i am looking for
    job in IT sector. I am in confusion to do either j2ee or any other course….pls suggest me.

      1. Warm Greetings Sir,

        what is the difference in these two?

        final x=10; // Constant
        static final x=10 // though its a constant

        Thanks for your time sir

  118. I have a doubt, if the thread of an object instance(say obj) acquires the lock on the object when it goes under the synchronized method(say syncmethod1();), so if a new thread of same object instance(say obj) is trying to access another synchronized method(say syncmethod2();), what will happen? iam thinking the new thread will not be able to access the synchronized method(syncmethod2();) since the lock has not been released yet by the first synchronized method(syncmethod1();)

      1. if two threads of same obj can access two different synchronized methods, then there is a chance of the object behaviour getting changed in one synchronized method and not getting reflected in another synchronized method, which would result an incorrect output? isnt it? correct me plz if iam wrong

  119. Hello sir , this code is showing errors. pls verify n say the correct code:

    import java.rmi.*;
    public class HelloClient
    {
    public static void main(String args[]) throws Exception
    {
    Hello h2=(Hello)Naming.lookup(“roses”);
    String s1=h2.sayHello(“nagarjuna”);
    System.out.println(s1);
    }
    }

    1. E:\>javac Hello*.java
      HelloClient.java:2: error: class, interface, or enum expected
      Public class HelloClient
      ^
      HelloClient.java:4: error: ‘;’ expected
      Public Static void main(String args[])throws Exception
      ^
      2 errors

  120. Dear sir, could u please answer this
    Q:-what have extra significance in interface but not in abstract class?
    note:-i know only multiple inheritance,is there other anser.

    1. The answer is in using them. Do you know interface gives a template of methods from which new classes can be developed easily. Interface is used when you want to give full implementation of methods to derived classes. If you would like to a few methods to the derived class to implement use abstract class.

  121. Hi sir,
    I am working in a company as a java portal developer.I career i very bad .
    i have very poor mark on +2 .I have only 45% mark in my +2.
    Will it create any problame further in my future.

    Please please replay me sir…..

    1. Less marks scoring will not effect your future career once you gain the experience of 3 years. But what matters is your poor knowledge in the computer subjects and your poor logic. Improve them very fast else you may have to leave the profession.

  122. sir i am preparing for se 7 exam …so i want some sample test or mock tests …so could you please help and can you provide any tests papers of that exam standard

  123. import java.util.*;
    class Book
    {
    String name;
    int price;
    Book(String name, int price)
    {
    this.name=name;
    this.price=price;
    }
    public String toString()
    {
    return(name+” “+price);
    }
    }

    class ColletionSortTest
    {

    public static void main(String… s)
    {

    ArrayList al=new ArrayList();
    al.add(new Book(“Java”,5000));
    al.add(new Book(“.Net”,300));
    al.add(new Book(“C#”,4000));
    al.add(new Book(“Maths”,1200));
    Collections.sort(al);
    for(ArrayList ob:al) // error class cast Exception Becuase non generic and dwon cast not done here so exception
    System.out.println(ob);
    }
    }

    sir ,plz explain the ClassCastException

  124. Chaman Bharti

    Dear Sir,
    I am persuing BCA 4th sem from IGNOU. IGNOU’s java book is not good for beginner, so pls tell me best book about java. I want to make career as a java developer so pls tell me java book and its author.

    1. If you want the total number of duplicate items and not each duplicate item how many times occur, one easy way first find the size of the array, then convert array into HashSet (hash set removes duplicates automatically), find the size of the HashSet, the difference gives the number of duplicates. Else write your own code.

  125. Prabhat Ranjan Sinha

    sir,
    I want to provide the any practic book pdf (programming problelms) for the related topic wise .

  126. Sir,
    I’m just want to jion hadoobi and i’m having 1 year experiance. Can you please tell me whether it will helpful to my future or not??

  127. good evening sir,
    I am planning to join selenium testing tool at one of the institute will it help me in getting a job,Is that tool Demand in the market.Can u suggest.

  128. Sir

    i really liked your website, will you please explain the spring and hibernate frame work also.

  129. Good Evening Sir,
    Sir I am a ex-student of your core java at config.While in the class you repeatedly told that there is a consultancy which provides training to Freshers can u please give the address of that consultancy.I am a 2012 fresher looking for software job.
    Thanks in advance.

      1. actually i came to config they told that you are not training in that institute can u tell at what time timings you will be available sir.Thanks in advance

  130. in your materail its mentioned as static methods can use only static variables, but the main method is a static method which uses the non-static variables. Can you explain how is this possible sir?

    Thanks in advance!

    1. static method allows local variables and in main() we use only static or local variables.
      just try to use that variables of main() method out side the main they will not be accessible, that means they are local variables.
      And static method can use local variables.

  131. sir,String class is immutable we don,t change the value of String after assignment ,but we use
    String s=new String(); why ?
    hum humare program mae null string kyu use karaegae jismae value hi na ho ?

    1. The statement, String s1 = “hello”; is internally converted into String s1 = new String(“hello”);. Infact, String s1 = “hello”; is a shortcut for String s1 = new String(“hello”);.

      Sometimes in coding, local variables should be given values when they are declared. If not, atleast, must be given null, else some compilers raises error.

      If you would like to take the value from keyboard at runtime, you must do like this.

      String s1 = null;
      s1 = “hello” where hello can be taken from keyboard.

  132. sir,can u provide full information about java.lang package i.e about process,process builder,enum….etc

  133. Madhava Nandan Rao

    Hello sir,
    Is there any alternate for sizeof() operator of c in java?

    Thank you sir

  134. Yes sir if i do not join i will loose experience.But i am tensed that how it adds experience to me ,as it is not used by any other company??Is JAVA and EIFFEL are similar??help me sir!!
    Thank you

  135. Sir,
    I am B.Tech 2012 ECE passout. I got job in platform EIFFEL Programming language.I am unable to understand whether it is useful or not in further ???Please help me sir!!!
    Thank you

    1. EIFFEL is an object-oriented language and many of its concepts are taken into Java design. You, being a fresher, do not think whether useful or not. Just work for two years (not only EIFFEL but on any other platform) and later you will have bright future. If you do not join, you may have to spend another year to search for job where you will loose one year experience.

        1. internally the content of object is converted into hashcode (hashing).by using euals() method compares two objects

  136. sir you have mentioned that static blocks execute before main method nd when we run the below program static blocks executes and a error is displayed that main() is missing ,but i am getting only error of missing main() nd static blocks are not executed can u tell me the reason why it is so????

    P.S. :: i am using java 1.7

    public class MultiStaticBlocks
    {
    static
    {
    System.out.println();
    System.out.println(“From first static block.”);
    }
    static
    {
    System.out.println(“From second static block.”);
    }
    static
    {
    System.out.println(“From third static block.”);
    }
    }

  137. Sir,
    I am expecting “Both objects are equal” as the response but I am getting “unequal objects “class testToString. I know the correct answer can come only if we override equals() & hashcode() , but i dont know how to override these methods in this code. Kindly help. Thanks.
    {
    public static void main(String args[])
    {
    checkToString cs = new checkToString(2);
    checkToString c = new checkToString(2);

    if( cs.equals(c))
    System.out.println(” Both objects are equal”);
    else
    System.out.println(” Unequal objects “);
    }
    }

    class checkToString
    {
    int i;
    checkToString()
    {
    i=10;
    }
    checkToString(int a)
    {
    this.i=a;
    }
    }

  138. sir i have small doubts
    1.>why byte code has to interpreted only?why not compiled?
    2.>how can jit compiler speed up the interpreting?
    3.>where exactly abstract class only used?and where exactly interface only used?

    1. Infact, bytecode to binary code interpretation is nothing but another compilation, in the sense, a compilation results in a different format of code. Example, C/C++ compilation results in binary code and Java results in bytecode. For this reason, some people call Java interpretation is another compilation.

      JIT compiler stores a method binary code (when first time the method is called). Subsequently, for every method call, the same already interpreted binary code of the method is called. In JDK 1.0, each time the same method is called, every time the bytecode to binary code is done.

  139. Sir,
    I want to ask 2 questions:
    Why static methods does not have “this” ?
    Why static methods can not be added into an interface ?

    1. We know when a method is called with an object, the instance variables in the method are linked with the object implicitly and there by encapsulation is maintained (explained in Using Variables from Methods. We also know static method can be called without object also. If called, to what instance variables the object is to be linked. For this reason static methods do not work with this keyword.

      If an interface does not permit to override its abstract methods, then there is no meaning and purpose of an interface. by principle, static methods cannot be overridden. For this reason, static methods cannot be added to an interface.

      1. Thank you sir …there are very few people like u who impart education for free with so much dedication .

  140. what is the difference between an object and a reference variable?

    could you please explain with an example..

  141. can we create the object for the class inside itself
    like..
    public class TestClass
    {

    public static void main(String[] args)

    {
    TestClass firstTest = new TestClass();

    firstTest.id = 5;

    System.out.println(firstTest.id);
    }

    }

  142. How many .class files will be created for the following code snippet?

    abstract class Shape{
    abstract void area();
    public void disp(){
    System.out.println(“Display Area of Shapes”);
    }
    }

    class Circle extends Shape{
    public void area(){
    System.out.println(“Display area of Circle”);
    }
    }
    abstract class Draw{
    abstract void draw();
    }

    class Rectangle extends Draw{
    public void draw(){
    System.out.println(“Draw Rectangle”);
    }
    }

    class Demo{
    public static void main(String args[]){
    Rectangle obj=new Rectangle();
    }
    }

    1. Because Java designers thought some methods are useful for every Java program you write. They put all those methods like toString() etc. in Object class and extended implicitly to your class, so that you can make use of all the methods in your code.

        1. You can start with Java. As Java follows the same syntax rules and principles of using methods, control structures and arrays, these are not taught by Java lecturers. So better have the knowledge of these topics only in C/C++. Other things of C/C++ are not needed to know.

  143. I am also Java programmer , Really sir i am surprise here , This website is really very very beneficial for every java learner .Because this website cover many topics .
    Thank You sir for providing this types of services ..

    Thank’s
    Manish Kumar…

  144. sir
    please tell me which is the best linux for complete java development
    like

    java jdk,oracle,sql,tomcat,weblogic etc…..

    please sir please
    i am very confuse about bcoz i’m not finding even one person whoever give me the proper segetion
    so please help me
    than you

  145. Sir , as we use scanf for input in c .. Can we say tht we r using stream classes to take input from user..

  146. Dear Sir,
    In Casting Operation Section (http://way2java.com/casting-operations/) page 2 to so on (Page 2, Page 3, Next etc)…not working …Error message Page not found… there is only data type conversion is available but object type or class type conversion is not available…Please help me…
    Namaste
    Harish

  147. Sir you dont have any book on advanced java
    i.e jsp servlet
    and on swing framework,
    or any reference book you recommend.

  148. good evening sir, sir i’m very confused in overloaded and override . sir plz tell me with siutable example

  149. Sir,
    I wanted to join in the course of java,where is your institute located can u send me the address of it.

  150. Sir, i am searching any good book of C and C++ like your core java book…i have your core java book…this is best book of core java…can you tell me any good book name..have you written any c or c++ book…one more thing had you plan to write any other book of java i want to know …because i want to purchase your book for learning purpose

    1. just becoz of security reasons becoz in pointer you can access the memory address directly which support hackers to hack or access any data so java encrypt the memory address and then the variable point toward the encrypted address

  151. Last week i was attend one interview he asked to me what’s your project life cycle i told SDLC.. but he was not satisfied … what is means of Project life cycle ?

  152. Dear Sir,
    i was trying to open this site for past 3 days but every-time i got following error….Browser could not find way2java.com
    Ping request could not find host way2java.com. Please check the name and try again. is there any problem ?

  153. Hi sir,
    I’m very new in java.. can you help me to solve a problem? i have to find is there any pair of “g” in a given array.. if so then it will return true otherwise false . if all g’s are in pair only then the return will be true .some of the test cases are given :

    gPair(“gxxxggxx”)—> false
    gPair(“xxggxxggxxx”)—–> true

    1. import java.util.StringTokenizer;
      public class Demo
      {
      public static void main(String[] args)
      {
      String s1 = “xxgxxxggxxxggxx”;
      String s2 = “xxggxxxggxxxggxx”;

      String array1[] = s1.split(“[\\w]gg”);
      String array2[] = s1.split(“[\\w]g”);

      boolean b = false;
      if(array1.length == array2.length)
      b = true;

      System.out.println(“s1 contains only gg: ” + b);
      }
      }
      Repeat the with s2.

  154. sir when u are adding J2ee in this website………. plz sir plz add j2ee also for making this java website complete

  155. Ramesh Kumar (ORAFACT)

    Sir
    How to change System.out.println() as OurClass.oc.display() ??
    I faced this question in interview

    1. You can customize the following code.

      import java.io.*;

      class YYY
      {
      public static PrintStream ps = new PrintStream(System.out);
      }
      public class Demo
      {
      public void display()
      {
      YYY.ps.println(“Hello 1”);
      }
      public static void main(String args[])
      {
      Demo d1 = new Demo();
      d1.display();
      }
      }

    1. The initialization block is nothing but a constructor. A constructor gives properties to an object at the time of object creation itself. For this, constructor is called every time you create an object. If required, I will send a program to you.

  156. I know Java doesn’t support multiple inheritance. But I was asked the following question in an interview
    I have two classes with one method in each
    classA{
    public void x(){}
    }

    classB{
    public void y(){}
    }

    I want to access these two methods in classC

    classC{
    public void x(){}
    public void y(){}
    }

    How to do this Java. Please explan

    Thanks in advance

    1. I came up with the following solution for my earlier question. Please give your feedback on the given solution

      public class ClassA{
      public void flying(){
      System.out.println(“Flying…”);
      }
      }

      public class ClassB{
      public void floating(){
      System.out.println(“Floating…”);
      }
      }

      public class MyClass{
      ClassA ia;
      ClassB ib;
      public MyClass(){
      ia = new ClassA();
      ib = new ClassB();
      }
      public void printMessage(){
      ia.flying();
      ib.floating();
      }
      public static void main(String[] args){
      MyClass mc = new MyClass();
      mc.printMessage();
      }
      }

  157. Could you please explain the reason for ConcurrentModificationException and how to avoid it?

  158. Hello Sir,

    please tell me core java design pattern name which used most in Core Java Project ?

    Creational Patterns
    Singleton
    Factory
    Factory Method
    Abstract Factory
    Builder
    Prototype
    Object Pool
    Behavioral Patterns
    Chain of Responsibility
    Command
    Interpreter
    Iterator
    Mediator
    Memento
    Observer
    Strategy
    Template Method
    Visitor
    Null Object
    Structural Patterns
    Adapter
    Bridge
    Composite
    Decorator
    Flyweight
    Proxy

  159. import java.awt.*;
    import java.awt.event.*;
    public class Radio extends Frame implements ItemListener
    {
    Checkbox c1,c2,c3,c4,c5,c6;
    Panel p1,p2;
    TextField tf;
    CheckboxGroup cbg1,cbg2;
    public Radio()
    {
    p1.setLayout(new GridLayout(1,3,15,10));
    p1=new Panel();
    p2=new Panel();
    cbg1=new CheckboxGroup();
    cbg2=new CheckboxGroup();
    p1.setBackground(Color.pink);
    p2.setBackground(Color.blue);
    c1=new Checkbox(“HeroHonda”,cbg1,true);
    c2=new Checkbox(“Bajaj”,cbg1,false);
    c3=new Checkbox(“Tvs”,cbg1,false);
    c4=new Checkbox(“Black”,cbg2,false);
    c5=new Checkbox(“Maroon”,cbg2,false);
    c6=new Checkbox(“Silver”,cbg2,false);
    p1.add(c1);
    p1.add(c2);
    p1.add(c3);
    p2.add(c4);
    p2.add(c5);
    p2.add(c6);
    add(p1,”north”);
    add(p2,”south”);
    add(tf=new TextField(15),”centre”);
    tf.setBackground(Color.cyan);
    tf.setFont(new Font(“Monospaced”,Font.BOLD,18));
    c1.addItemListener(this);
    c2.addItemListener(this);
    c3.addItemListener(this);
    c4.addItemListener(this);
    c5.addItemListener(this);
    c6.addItemListener(this);
    addWindowListener(new CloseMe());
    setSize(450,350);
    setVisible(true);
    }
    public void ItemStateChanged(ItemEvent e)
    {
    String str1=””, str2=””;
    if(c1.getState()==true)
    {
    str1=”Famous Hero Honda”;
    }
    else if(c2.getState()==true)
    {
    str1=”Hamara Bajaj”;
    }
    else if(c3.getState()==true)
    {
    str1=”The Great TVS”;
    }
    if(c4.getState()==true)
    {
    str2=”Black”;
    }
    else if(c5.getState()==true)
    {
    str2=”Maroom”;
    }
    else if(c6.getState()==true)
    {
    str2=”Silver”;
    }
    tf.setText(“Good Taste, U want “+str1+”in”+str2);
    }
    public static void main(String args[])
    {
    new Radio();
    }
    class CloseMe extends WindowAdapter
    {
    public void WindowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    }
    }

    ERROR:Radio is not abstract and does not override abstract method ItemStateChanged(java.awt.event.ItemEvent) in java.awt.event.ItemListener. could you pls solve ot for me sir…
    regards
    aravind

  160. Which exception is caught first? IOException or FileNotFoundException? Could you please specify reason?

  161. chandan kumar bisoi

    hello sir ..
    I am really glad after knowing about the site . I have heard about u when i was in hyderabad last year searching for a job.Unfortunately i didnt get much oppertunity over there .Its so nice of u that u have mentained such a nice website for java lovers. I want to do my career in java .So I need some guidance from u .Would u like to help in in this regard . I know core java,jdbc,servlet and jsp well .What more i need to know about java so as to become a good java proffessional .Help me sir .

  162. Good Morning sir,
    i have one question… suppose i have two list with duplicate elements i want to print one unique list via these two list…how can i write this program

    1. import java.util.*;
      public class Demo
      {
      public static void main(String args[])
      {
      ArrayList al1 = new ArrayList();
      ArrayList
      al2 = new ArrayList();
      al1.add(10); al1.add(20); al1.add(30); al1.add(20); // 20 repeated
      al2.add(40); al2.add(30); al2.add(40); al2.add(50); // 40 repeated; 30 exists in both lists

      al1.addAll(al2);

      HashSet hs1 = new HashSet(al1); //removes duplicates

      ArrayList al3 = new ArrayList(hs1); // converting HashSet to ArrayList
      System.out.println(al3);
      }
      }

  163. Thanks for sharing your knowledge. I have couple of questions.
    1. String class thread safe or not?
    2. Please explain ENUM with good example

  164. Dear Sir,
    I am confused with Action class in MVC architecture of Struts. Please tell me whether it(Action class) is the part of Model or Controller?

  165. sir plz tell my servlet has not any main method in it than how does it work by jvm?

  166. please sir explain this program
    what will be the output of this program
    thnx..

    class A {
    int ivar = 7;
    void m1() {
    System.out.print(“A’s m1, “);
    }
    void m2() {
    System.out.print(“A’s m2, “);
    }
    void m3() {
    System.out.print(“A’s m3, “);
    }
    }
    c
    l
    ass B extends A {
    void m1() {
    System.out.print(“B’s m1, “);
    }
    }
    c
    l
    ass C extends B {
    void m3() {
    System.out.print(“C’s m3, “+(ivar + 6));
    }
    }
    p
    ublic class Mixed2 {
    public static void main(String [] args) {
    A a = new A();
    B b = new B();
    C c = new C();
    A a2 = new C();
    a2.m1();
    a2.m2();
    a2.m3();
    }
    }

    1. You must know method overriding rules when a subclass object is assigned to super class object.

      1. When a subclass object is assigned to super class object, the super class object will call subclass method.
      2. If the subclass method does not exist, the super class object will call its own method.

      Apply these two rules you will get correct idea of the code.

      A a2 = new C();

      Here anonymous object of C is assigned to super class object A. To get confused, the code put one more class in between A and C. In a2 reference of C is there.

      a2.m1();

      As m1 does not exist in C, C calls its super class m1(). As B contains one, it call B’s m1() method.

      a2.m2()

      C does not have m2(). It looks for B class. It also does not have one. So, the control goes to A. As A have one, it calls A’s m2.

      a2.m3();

      As C has m3(), the A reference calls C’s m3();

      If you understand well, the same program can be converted still more confused one.

      Now apply the rules.

  167. Sir,
    I am developing hotel site using Struts2 framework and Hibernate.
    Please prefer to which JAVA CMS is used develop this project.How to integrate my Project with this CMS.

  168. sir, u have given a program how to send an image to client but here i want to include “text/html” files also i mean including
    image i want to display some other data(eg:- pw.println()) on the same browser
    sir kindly give reply “urgently”.

  169. 1)can we give a print option from a servlet page.
    2)after generating a servlet page can we edit it.
    if possible or not possible how to get the desired output?

  170. Vector v=new Vector();
    try
    {
    Class.forName(“oracle.jdbc.driver.OracleDriver”);
    Connection con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:xe”,”system”,”manager”);
    Statement stmt=con.createStatement();
    ResultSet rs =stmt.executeQuery(“select * from employee_details where employee_id=”+id);
    while(rs.next())
    {
    v.add(rs.getInt(1));
    v.add(rs.getString(2));
    v.add(rs.getString(3));
    v.add(rs.getString(4));
    v.add(rs.getString(5));
    v.add(rs.getString(6));
    v.add(rs.getString(7));
    v.add(rs.getString(8));
    v.add(rs.getString(9));
    v.add(rs.getString(10));
    v.add(rs.getString(11));
    v.add(rs.getInt(12));
    v.add(rs.getString(13));
    v.add(rs.getInt(14));
    v.add(rs.getString(15));
    }
    rs.close();
    stmt.close();
    con.close();

    }
    catch(Exception e)
    {
    out.println(“Exception is ;”+e);
    }

    request.setAttribute(“data”,v);

    //Disptching request

    RequestDispatcher dispatcher = request.getRequestDispatcher(page);

    if (dispatcher != null){

    dispatcher.forward(request, response);

    }

    Sir i retrieved all data from database into VECTOR and send it to JSP page….i am nt getting output while displaying on JSP…
    Here is the JSP code…….

    Vector data= (Vector)request.getAttribute(“data”);
    itr=data.iterator();

    ..while( itr.hasNext() )
    {
    emp_id=(Integer)itr.next();
    emp_name=(String)itr.next();
    . ………………….
    …………………
    …………………..
    ……………………
    }

    As i need to display it into table i need to give specific values at perticular table fields so i need to stor tht in those emp id,name etc….if i use itr.next() it ll retrieve in sequence order bt i need to give to tables in diff positions ….. sir waiting for your reply plz solve my problem………….

  171. Dear Sir

    Please find the attached program where i have tried to bring all the concepts of core java except applet,swing.

    please give your comments and suggestions.

    Thanks

    David
    Java studying student from chennai

    import java.lang.String;
    import java.lang.*;
    import java.util.*;
    import java.io.*;

    class Trial
    {
    public void show()
    {
    String A=”David”;
    String B=”Prabhu”;
    int C=10;
    int D=20;
    int N;
    int O=40;
    double E = 10.5;
    double F = 20.5;
    float G=10f;
    float H=10f;
    final long I = 24L*60L*60L*1000L*1000L;
    final long J = 24L*60L*60L*1000L;

    }
    }
    interface Trialdemo
    {
    public void disp();
    }
    interface Trial1demo
    {
    public void print();
    public void sit();
    }
    class Trial2demo implements Trial1demo
    {
    public void print()
    {
    System.out.println(“Static method”);
    System.out.println(“Static method1”);
    }
    public void sit()
    {
    System.out.println(“Static Method Trial”);
    System.out.println(“Static Method Trial1″);
    }
    }

    class Trial1 extends Trial
    {
    public void show()
    {
    String A=”David”;
    String B=”Prabhu”;
    System.out.println(“Java Programme by”+A);
    }
    }
    class Trial2 extends Trial
    {
    public void show()
    {
    int C=10;
    int D=20;
    int N;
    int O=40;
    double E = 10.5;
    double F = 20.5;
    float G=10f;
    float H=10f;
    final long I = 24L*60L*60L*1000L*1000L;
    final long J = 24L*60L*60L*1000L;
    System.out.println(“Adding”);
    System.out.println(” C + D = ” + (C + D));
    System.out.println(“Subtracting”);
    System.out.println(” E – F = ” + (E – F));
    System.out.println(“Multiplying”);
    System.out.println(” C * G = ” + (C * G));
    System.out.println(“Dividing”);
    System.out.println(” I / J = ” + (I / J));
    }
    }
    class Trial3 extends Trial
    {
    public void dast()
    {
    int C=10;
    int D=20;
    int N;
    int O=40;
    System.out.println(“conditional”);
    System.out.println(“if else”);
    try
    {
    if(D>C)
    {
    System.out.println(“D is Greater”);
    throw new Exception(“confused”);
    }
    else if(O>D)
    {
    System.out.println(“O is Greater”);
    }
    else
    {
    System.out.println(“D is Greater”);
    }
    }
    catch (Exception e)
    {
    System.out.println(“only throw,try,catch”);

    }
    }
    }
    class Trial4 extends Trial
    {
    public void show()
    {
    int C=10;
    int D=20;
    int N;
    int O=40;
    System.out.println(“While”);
    do
    {
    System.out.println(“B is Even Number”);
    }

    while(C%2==1);

    }
    }
    class Trial5 extends Trial
    {
    public void show()
    {
    int C=10;
    int D=20;
    switch (C=10)
    {
    case 10:
    System.out.println(“Another Try”);
    break;
    default:
    System.out.println(“Invalid Entry!”);

    }
    }
    }
    class Trial6 implements Trialdemo
    {
    int K[][]=new int[3][3];
    public void disp()
    {
    K[0][0]=1;
    K[0][1]=1;
    K[0][2]=1;
    K[1][0]=1;
    K[1][1]=1;
    K[1][2]=1;
    K[2][0]=1;
    K[2][1]=1;
    K[2][2]=1;
    }
    public void stsi()
    {
    System.out.print(“Matrix is”);
    for(int L=0;L<3;L++)
    {
    for(int M=0;M<3;M++)
    {
    System.out.print(K[L][M]+"/t");
    }
    System.out.println("/n");
    }
    }
    }
    class Trial7 extends Trial
    {
    public void show()
    {
    int B1 = 1 & 1;
    int C1 = 1 ^ 0;
    int D1 = 0 | 0;
    float E1 = 0;
    int F1=0;
    F1=C1>> 2));
    System.out.println(” left shift” +( 9 <> 2 right shift= ” +( 24 >> 2));
    System.out.println(“Operator Precedence” + E1);
    System.out.println(” Ternary ” +F1);
    }
    }

    class Trial9 extends Trial
    {
    public void show()
    {
    int O=40;
    System.out.println(“private” +O);
    }
    }

    class Trial11 extends Trial
    {
    final int H1=12;
    public void show()
    {
    System.out.println(“final keyword”+H1);
    }
    }
    class Trial12 extends Trial
    {
    public void show()
    {
    try
    {
    int C=10;
    int I1=C/0;
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    finally
    {
    System.out.println(“confused”);
    }
    }
    }
    class Trial13 extends Trial
    {
    public void show()
    {
    System.out.println(“confused”);
    System.out.println(“confused”);
    }
    public void dive()
    {
    System.out.println(“Starting String”);
    }
    }
    class Trial14 extends Trial
    {
    char[]J1=new char[3];
    String A=”David”;
    String B=”Prabhu”;
    int i=10;
    public void show()
    {

    System.out.println(+A.length());
    System.out.println(A.replace(“i”,”oo”));
    System.out.println(A.toUpperCase());
    System.out.println(A.toLowerCase());
    System.out.println(A.concat(“B”));
    System.out.println(A+B);
    System.out.println(A.charAt(2));
    System.out.println(A.compareTo(“Dav”));
    System.out.println(A.contentEquals(“Dav”));
    System.out.println(A.endsWith(“d”));
    System.out.println(A.startsWith(“D”));
    System.out.println(A.isEmpty());
    System.out.println(A.equals (B));
    System.out.println(A.toString ());
    System.out.println(A.getBytes ());
    System.out.println(A.intern());
    System.out.println(+A.hashCode());
    for(String K1:A.split(“a”,0))
    {
    System.out.println(K1);
    }
    System.out.println(+A.indexOf(“i”,2));
    System.out.println(+A.lastIndexOf(“i”,2));
    System.out.println(A.regionMatches(1,B,2,2));
    System.out.println(A.regionMatches(true,1,B,2,2));
    System.out.println(A.replaceAll(“D”,”T”));
    System.out.println(A.substring(1,3));
    System.out.println(A.valueOf(i));
    System.out.println(A.toCharArray());
    System.out.println(A.toString());
    System.out.println(A.equalsIgnoreCase(B));
    }
    }

    class Trial15 extends Trial
    {
    public void show()
    {
    String A=”David”;
    String B=”Prabhu”;
    StringBuffer L1=new StringBuffer();
    L1.append(A);
    System.out.println(” “+L1);
    L1.insert(0,A);
    System.out.println(” “+L1);
    L1.length();
    System.out.println(” “+L1);
    L1.capacity ();
    System.out.println(” “+L1);
    L1.delete(0,3);
    System.out.println(” “+L1);
    L1.setLength(2);
    System.out.println(” “+L1);
    L1.reverse().toString();
    System.out.println(” “+L1);
    }
    }
    class tdemo extends Trial implements Runnable
    {
    public void run()
    {
    int g11=123;
    int f11=456;

    String a11=”david”;

    try
    {

    System.out.println(“Student name=”+a11);
    Thread.sleep(1000);
    System.out.println(” “+f11);
    Thread.sleep(1000);
    System.out.println(” “+g11);
    Thread.sleep(1000);
    System.out.println(“java”);

    synchronized(this)
    {
    for(int k11=1;k11<2;k11++)
    {
    k11++;
    k11–;
    System.out.println(k11);
    }
    }

    }
    catch(Exception e)
    {
    System.out.println(" "+e);
    }
    }
    }
    class finaltrial extends Trial
    {
    public static void main(String args[])
    {
    ThreadGroup tg=new ThreadGroup("Threading Group");
    System.out.println(" "+tg.getName());
    System.out.println(" "+tg.getParent());

    tdemo z11= new tdemo();
    tdemo y11= new tdemo();
    tdemo w11= new tdemo();
    tdemo v11= new tdemo();
    tdemo U11= new tdemo();
    tdemo T11= new tdemo();

    Thread t11=new Thread(z11);
    System.out.println("t is daemon by default: " + t11.isDaemon());
    t11.setDaemon(true);
    System.out.println("After making daemon, t is daemon: " + t11.isDaemon()); System.out.println("t is alive: " + t11.isAlive());
    System.out.println("t is interrupted: " + t11.isInterrupted());
    Thread t111=new Thread(y11);
    for(int k11=1;k11<4;k11++)
    {
    k11++;
    k11–;
    System.out.println(k11);
    }
    Thread t211=new Thread(w11);
    Thread t311=new Thread(tg,"New Threading Group");
    System.out.println(" "+t311.getName());
    System.out.println(" "+t311.getThreadGroup());
    Thread t411=new Thread(v11);
    Thread t511=new Thread(U11);
    Thread t611=new Thread(T11);
    t11.start();
    t111.start();
    t211.start();
    t311.start();
    t411.start();
    t511.start();
    t611.start();
    t511.setPriority(Thread.MAX_PRIORITY-1);
    t611.setPriority(Thread.MIN_PRIORITY+1);
    t511.setName("High");
    t611.setName("less");

    try
    {

    System.out.println("java lang pack");
    Thread.sleep(1000);
    z11.wait();
    System.out.println("java lang 2");
    Thread.sleep(1000);
    z11.notify();
    System.out.println("java lang pack 2");
    }
    catch(Exception e)
    {
    System.out.println(" "+e);
    }
    Trial2demo Z=new Trial2demo();
    Z.print();
    Z.sit();
    Trial1 Y=new Trial1();
    Y. show();
    Trial2 X=new Trial2();
    X. show();
    Trial3 W=new Trial3();
    W. dast();
    W. show();
    Trial4 V=new Trial4();
    V. show();
    Trial5 U=new Trial5();
    U. show();
    Trial6 T=new Trial6();
    T.stsi();

    Trial7 S=new Trial7();
    S.show();

    Trial9 Q=new Trial9();
    Q.show();

    Trial11 Y1=new Trial11();
    Y1.show();
    Trial12 X1=new Trial12();
    X1.show();
    Trial13 W1=new Trial13();
    Trial V1=new Trial();
    V1.show();
    Trial14 U1=new Trial14();
    U1.show();
    Trial15 T1=new Trial15();
    T1.show();
    String A8="David";
    String B8="Prabhu";
    String Z8="123";
    int C8=10;
    int D8=20;
    int N8=50;
    int O8=40;
    double E8 = 10.5;
    double F8 = 20.5;
    float G8=10f;
    float H8=10f;
    final long I8 = 24L*60L*60L*1000L*1000L;
    final long J8 = 24L*60L*60L*1000L;
    char[]J1=new char[3];

    System.out.println(" ");

    System.out.println("Lang Package ");

    System.out.println(" ");

    System.out.println("Starting Math Class");

    System.out.println(" ");

    System.out.println(Math.min(C8,D8));
    System.out.println(Math.max(E8,F8));
    System.out.println(Math.max(I8,J8));
    System.out.println(Math.sqrt(F8));
    System.out.println(Math.pow(G8,H8));
    System.out.println(Math.sin(F8));
    System.out.println(Math.cos(I8));
    System.out.println(Math.tan(H8));
    System.out.println(Math.abs(E8));
    System.out.println(Math.acos(E8));
    System.out.println(Math.exp(E8));
    System.out.println(Math.ceil(E8));
    System.out.println(Math.floor(E8));
    System.out.println(Math.log(E8));
    System.out.println(Math.rint(E8));
    System.out.println(Math.round(E8));
    System.out.println(Math.random());

    System.out.println(" ");

    System.out.println("Starting String class");

    System.out.println(" ");

    System.out.println(+A8.length());
    System.out.println(A8.replace("i","oo"));
    System.out.println(A8.toUpperCase());
    System.out.println(A8.toLowerCase());
    System.out.println(A8.concat("B8"));
    System.out.println(A8+B8);
    System.out.println(A8.charAt(2));
    System.out.println(A8.compareTo("Dav"));
    System.out.println(A8.contentEquals("Dav"));
    System.out.println(A8.endsWith("d"));
    System.out.println(A8.startsWith("D"));
    System.out.println(A8.isEmpty());
    System.out.println(A8.equals (B8));
    System.out.println(A8.toString ());
    System.out.println(A8.getBytes ());
    System.out.println(A8.intern());
    System.out.println(+A8.hashCode());
    for(String K18:A8.split("a",0))
    {
    System.out.println(K18);
    }
    System.out.println(+A8.indexOf("i",2));
    System.out.println(+A8.lastIndexOf("i",2));
    System.out.println(A8.regionMatches(1,B8,2,2));
    System.out.println(A8.regionMatches(true,1,B8,2,2));
    System.out.println(A8.replaceAll("D","T"));
    System.out.println(A8.substring(1,3));
    System.out.println(A8.valueOf(D8));
    System.out.println(A8.toCharArray());
    System.out.println(A8.toString());
    System.out.println(A8.equalsIgnoreCase(B8));

    System.out.println(" ");

    System.out.println("Starting String Buffer class");

    System.out.println(" ");

    StringBuffer L18=new StringBuffer();
    L18.append(A8);
    System.out.println(L18);
    L18.insert(0,A8);
    System.out.println(L18);
    L18.length();
    System.out.println(L18);
    L18.capacity ();
    System.out.println(L18);
    L18.delete(0,3);
    System.out.println(L18);
    L18.setLength(2);
    System.out.println(L18);
    L18.reverse().toString();
    System.out.println(L18);

    System.out.println(" ");

    System.out.println("Starting Object class");

    System.out.println(" ");

    System.out.println(L18.getClass());

    System.out.println(" ");

    System.out.println("Starting Wrapper class");

    System.out.println(" ");

    System.out.println(Integer.toBinaryString(4));
    System.out.println(Integer.toHexString(16));
    Integer i8 = new Integer(C8);
    String s8 = i8.toString();
    System.out.println(s8);
    int j=Integer.parseInt(Z8);
    System.out.println(Z8);

    System.out.println(" ");

    System.out.println("Utility Package ");

    System.out.println(" ");

    System.out.println("Starting Class Date");

    System.out.println(" ");

    Date o8 = new Date();
    System.out.println(o8);
    System.out.println(o8.getHours());
    System.out.println(o8.getMinutes());
    System.out.println(o8.getSeconds());
    System.out.println("month count starts from Zero =" +o8.getMonth() );
    System.out.println("date count starts from One =" +o8.getDate() );
    System.out.println("day count starts from Zero =" +o8.getDay() );
    System.out.println("Year after 2000 is represented as 1year that is 2010 is represented as 110 =" +o8.getYear() );
    System.out.println("This time count starts from 1.1.1900 =" +o8.getTime() );

    System.out.println(" ");

    System.out.println("Starting Class Calender");

    System.out.println(" ");

    Calendar p8 = Calendar.getInstance();

    System.out.println("Calendar class cannot be instantiated. Its object can be obtained from its static method getInstance()");

    System.out.println(" ");

    Calendar q8 = Calendar.getInstance();
    q8.set(2012, Calendar.MARCH, 20);
    System.out.println(p8.get(Calendar.YEAR));
    System.out.println(p8.get(Calendar.HOUR));
    System.out.println(p8.get(Calendar.MINUTE ));
    System.out.println(p8.get(Calendar.DAY_OF_MONTH));

    System.out.println(" ");

    System.out.println("Date Comparision ");

    System.out.println(" ");

    if(p8.before(q8))
    System.out.println("Yes, before");
    else if(p8.after(q8))
    System.out.println("Yes, after");
    else if(p8.equals(q8))
    System.out.println("Yes, equals");

    System.out.println(" ");

    System.out.println(p8.get(Calendar.ZONE_OFFSET ));

    System.out.println(" ");

    System.out.println("what is zone offset? ");

    System.out.println(" ");

    System.out.println(p8.get(Calendar.WEEK_OF_YEAR ));
    System.out.println(p8.get(Calendar.WEEK_OF_MONTH ));
    System.out.println(p8.get(Calendar.DAY_OF_WEEK ));
    System.out.println(p8.get(Calendar.DAY_OF_YEAR));

    System.out.println(" ");

    System.out.println("Starting class GregorianCalendar");

    System.out.println(" ");

    GregorianCalendar GC8 = new GregorianCalendar( );
    System.out.println(GC8.get(Calendar.YEAR));
    System.out.println("Era info: " + GC8.get(Calendar.ERA));
    System.out.println("Hour info: " + GC8.get(Calendar.HOUR));
    System.out.println("Minute info: " + GC8.get(Calendar.MINUTE));
    System.out.println("Second info: " + GC8.get(Calendar.SECOND));
    System.out.println("Millisecond info: " + GC8.get(Calendar.MILLISECOND));
    System.out.println("Month info: " + GC8.get(Calendar.MONTH));
    System.out.println("Week info of month: " + GC8.get( Calendar.WEEK_OF_MONTH));
    System.out.println("Week in the year: " + GC8.get(Calendar.WEEK_OF_YEAR));
    System.out.println("Date info: " + GC8.get(Calendar.DATE));
    System.out.println("Day of month info: " + GC8.get(Calendar.DAY_OF_MONTH));
    System.out.println("Day of year info: " + GC8.get(Calendar.DAY_OF_YEAR));
    System.out.println("Day of week info: " + GC8.get(Calendar.DAY_OF_WEEK));
    System.out.println("Day of week in the month: " + GC8.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("AM or PM info: " + GC8.get(Calendar.AM_PM));
    System.out.println("Hour of the day info: " + GC8.get(Calendar.HOUR_OF_DAY));

    System.out.println(" ");

    System.out.println("Starting String Tokenizer");

    System.out.println(" ");

    String w8 = "David is";
    StringTokenizer t8 = new StringTokenizer(w8);
    System.out.println("Number of tokens " + t8.countTokens());
    System.out.println(" ");
    System.out.println("Starting String Tokenizer");
    System.out.println(" ");
    while(t8.hasMoreTokens())
    {
    System.out.println(t8.nextToken());
    }
    String r8 = "[email protected]*stop/[email protected]*reach";
    StringTokenizer u8 = new StringTokenizer(r8, "@,m,*,/");
    System.out.println("Number of tokens " + u8.countTokens());
    while(u8.hasMoreTokens())
    {
    System.out.println(u8.nextToken());
    }

    System.out.println(" ");

    System.out.println(" ");

    System.out.println("Starting System Class");

    System.out.println(" ");

    System.out.println(System.getProperties ());

    System.out.println(" ");

    System.out.println("get Properties need both lang and util package to be imported since it involves date also");

    System.out.println(" ");

    System.gc( );

    File f;
    f=new File("David.txt");
    try
    {
    if(!f.exists())
    {
    f.createNewFile();
    System.out.println("New file \"David.txt\" has been created to the current directory");
    }
    else
    System.out.println("The specified file is already exist");
    }
    catch (Exception e3)
    {
    System.out.println("Error: " + e3.getMessage());
    }
    try
    {
    FileInputStream fis = new FileInputStream("David.txt");
    DataInputStream Din = new DataInputStream(fis);
    InputStreamReader Isr=new InputStreamReader(Din);
    BufferedReader br1 = new BufferedReader(Isr);
    String strLine;

    while ((strLine = br1.readLine()) != null)
    {

    System.out.println (strLine);

    FileOutputStream fos = new FileOutputStream("Prabhu.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    OutputStreamWriter Osr=new OutputStreamWriter(dos);
    BufferedWriter br2 = new BufferedWriter(Osr);
    br2.write("yes");
    br2.newLine();
    br2.write("No");
    br2.flush();
    br2.close();
    }
    }
    catch (Exception e)
    {
    System.err.println("Error: " + e.getMessage());
    }

    System.out.println("The absolute path of the file is: " +f.getAbsolutePath());
    File f1;
    f1=new File("Prabhu.txt");
    try
    {
    if(!f1.exists())
    {
    f1.createNewFile();
    System.out.println("New file \"Prabhu.txt\" has been created to the current directory");
    }
    else
    System.out.println("The specified file is already exist");
    }
    catch (Exception e2)
    {
    System.out.println("Error: " + e2.getMessage());
    }

    System.out.println("The absolute path of the file is: " +f1.getAbsolutePath());

    }
    }

  172. Hi sir,

    what is the use of the POJO classes , we cant write any thing with out pojo classes ?

  173. Hi sir,

    What are helper classes used in core java, and what is the use of those classes

    1. If we want an object of a class very often in day-to-day programming, instead of writing a lengthy code, we write all the code in a method and return the object. These are known as helper methods or helper classes (some people, in a different mood, also call as factory classes and factory methods).

  174. Is it possible to access data from super-package to sub-package?
    Suppose p1 is a package & the classes are available in p1.* and another sub-package p2 to p1 such that the classes of p2 are available in p1.p2.* . If I want to access the data of p1 package in p2 package so what is the real code I need to write?

    Please explain briefly…

  175. Sir,
    On 6th April we are having interview with NBOS Technologies .

    Regards,
    Orafact student.

  176. Bharani Kumar

    Hi sir,

    can you please explain what is marker interface with example and what is the difference between normal interface and marker interface

    1. import javax.servlet.http.HttpServlet; import avax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import javax.servlet.ServletException; import java.io.OutputStream;
      import java.io.IOException; import java.io.FileInputStream;
      import java.io.DataInputStream; import java.io.File;

      public class SendImage extends HttpServlet
      {
      public void service (HttpServletRequest req, HttpServletResponse res) throws
      ServletException, IOException
      {
      res.setContentType(“image/gif”);

      OutputStream ostream = res.getOutputStream( ); // for binary stream

      File f = new File(“c:\\bird3.gif”);
      DataInputStream dis = new DataInputStream(new FileInputStream( f ));
      byte[] barray = new byte[(int) f.length( )];
      try { dis.readFully(barray); }
      catch (Exception e) { barray = null; }
      finally { dis.close( ); }
      ostream.write(barray);
      ostream.close( );
      }
      }

      1. sir, here i want to include “text/html” files also i mean including
        image i want to display some other data(eg:- pw.println()) on the same browser
        sir kindly give reply “urgently”.

  177. Hi sir,

    String s1=”abc”;
    String s2=”ab”+”c”;

    if(s1==s2)

    what will be the out put sir can u please explain the internal logic of this

  178. Hi sir,

    How to make a class immutable, i thought it can make by using final key word but in a interview it was said
    as wrong ,

    if it is wrong can you please tell me how to make a class as immutable

  179. Sir
    what is the use of DeflaterOutputStream & InflaterInputStream in java.util package???

  180. sir,
    Can u please explain me what exactly the Encapsulation is and how it is worked with a simple example .

    1. public class Employee
      {
      in salary;
      public static void main(String args[])
      {
      Employee emp1 = new Employee();
      emp1.salary = 5000;
      System.out.println(emp1.salary);
      }
      }

      We say, emp1 is encapsulated with salary. Means, both becomes one unit so that other cannot read or modify or delete.

  181. sir,i want to ask one question from adv.java(servlets) what is the diff between sendRedirect()
    and requestDispatcher() methods

    1. Programmer uses sendRedirect(String file) to send a file to the client. With this method, control is returned to the client.

      getRequestDispatcher(String otherServlet) returns an object of RequestDispatcher. This method is used to connect to the other servlet. Control is within the server only.

      1. sir, can we pass conroll from one servlet to another servlet with sendRedirect() .
        If yes why requestDispatcher() again.

  182. Hello sir

    i want program for for this scenario

    need to have one main server which communicates with 3 sub servers and client should communicate with main server and need main server should get the data from 3 servers and need to return response to client program

    1. Once you understand the TCP/IP and UDP protocols and the programs from way2java.com, you must develop this kind of programs by yourselves. It will be a very good practice as the task is very good. I will not find time to write such big code. Sorry.

    2. But here the problem is how to communicate between the two servers that i am not able to understand

  183. Hello Sir,

    What is the use of String intern() method and what is the difference between String s1=”hello” ,
    String s2=new String(“Hello”) and String intern methods

  184. Hello Sir,

    How to Print ArrayList Values in Formated Way Just Like

    1 Bharani 20000 Malakpet Hyderabad
    2 Sravan 30000 Malakpet Hyderabad

    1. See this code:

      ArrayList al = new ArrayList();
      al.add(1); al.add(“Bharani”); al.add(20000); al.add(“Malakpet”); al.add(“Hyderabad”);
      al.add(2); al.add(“Sravan”); al.add(30000); al.add(“Malakpet”); al.add(“Hyderabad”);

      Iterator it = al.iterator();
      int counter = 0;
      while(it.hasNext())
      {
      System.out.print(it.next() + ” “);
      if(counter++ ==4)
      {
      counter = 0;
      System.out.println();
      }
      }

      For the alignment of output, go for GUI (java.awt package)

    1. I think you can understand by seeing the following code.

      class Test { int x = 10; }
      public class Demo
      {
      public static void main(String [] args) throws ClassNotFoundException
      {
      Class c = Class.forName(“Test”);
      System.out.println(c.getClass());
      System.out.println(c.getName());

      Test t1 = new Test();
      if(t1 instanceof Test)
      {
      System.out.println(t1.x);
      }
      }
      }

  185. sir iam unable to remove Ds elements with iterator method i.e it.remove() when i added
    non homogeneous objects like double ,int, String to Ds . Then how to remove Ds elements with iterater
    in case of diff. objects.

    1. No, it removes. See this code:

      import java.util.*;
      public class Demo
      {
      public static void main(String [] args)
      {
      LinkedList list = new LinkedList();
      list.add(10);
      list.add(10.5);
      list.add(“hello”);

      System.out.println(“Before removal: ” + list);

      Iterator it = list.iterator();
      while(it.hasNext())
      {
      it.next();
      it.remove();
      }
      System.out.println(“After removal: ” + list);
      }
      }

    1. You know “super class method is a subclass method” and this is known as “is-a” relationship. Extends gets super class (here, it is interface) abstract methods in another interface which is accepted. For the same reason, we cannot extend a concrete class to an interface.

  186. Vector v=new Vector();
    //here i have added some elements
    Enumeration e=v.elements();
    while(e.hasMoreElements())
    {
    sop(e.nextelement());
    }

    in the above code we know Enumeration is an interface which is not provided impl for thier methods.
    But when we call e.hasMoreElements() and e.nextElement() how they return boolean value and
    Object respectually .here i mean where the implementation provided for those methods (even Vector class
    also not consist those methods )

      1. then what is the use here by declaring Enumeration as interface why we cnt provide impln there.

        1. We know elements() method of Vector returns an object of Enumeration interface. If Enumeration is not an interface if implementation exists, they you will create object of it and try to override it, which of course much not useful to you. For this reason, Enumeration is declared as interface. If you require further information, it you are at Hyderabad, meet me personally.

  187. sir,
    i have very excited while going trough this site to learn java becoz i have never seen this type of persistent notes in any other sites.
    thanx for giving this.is WAY2JAVA books available in the market?

    1. public class Demo
      {
      public static void main(String [] args)
      {
      String str1 = “hello”;
      String str2 = “world”;
      String str3 = “hello”;

      if(str1 == str2)
      System.out.println(“str1 and str2 are same”);
      else
      System.out.println(“str1 and str2 are not same”);

      if(str1 == str3)
      System.out.println(“str1 and str3 are same”);
      else
      System.out.println(“str1 and str3 are not same”);
      }
      }

      Above type of logical equal to comparison fails in the following case.

      String str1 = new String(“hello”);
      String str2 = new String(“hello”);

  188. sir i want program for below concept: awt
    create 10 buttons using arrays if i press first button 1 has been displayed in textField same for upto ten buttons ple help me

    1. // create 10 buttons using arrays if i press first button 1 has been displayed in textField same for upto ten buttons.

      import java.awt.*;
      import java.awt.event.*;

      public class Display extends Frame implements ActionListener
      {
      TextField tf;
      public Display()
      {
      setLayout(new FlowLayout());
      Button btn[] = new Button[10];
      for(int i = 0; i < btn.length; i++) { btn[i] = new Button(""+(i+1)); btn[i].addActionListener(this); add(btn[i]); } add(tf = new TextField(10)); setSize(300, 300); setVisible(true); } public void actionPerformed(ActionEvent e) { tf.setText(e.getActionCommand()); } public static void main(String args[]) { new Display(); } }

  189. Hai sir,

    I am very new to programming languages but I know some concepts in C. So I want to learn Android apps development. My question is to learn apps development it is necessary to learn Java technologies or I can go directly to apps development tutorials. Please sir, give me your advise so I can make decision. Thanks in advance.

  190. Sir
    I am getting provlem like this. Pls suggest me

    C:\sara\Jdbc>javac Jdbc.java

    C:\sara\Jdbc>java Jdbc
    Exception in thread “main” java.sql.SQLException: Io exception: Connection refus
    ed(DESCRIPTION=(TMP=)(VSNNUM=186647040)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=1250
    5)(EMFI=4))))
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:323)
    at oracle.jdbc.driver.OracleConnection.(OracleConnection.java:260)

    at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
    va:365)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at Jdbc.main(Jdbc.java:7)

  191. Sir,
    I have installed jdk 1.3 & 1.7 versions and set the classpath for both versions. It is using only jdk 1.7 version in commnad prompt. I need to use jdk1.3 in some times. How can i switch between two java versions in command prompt

  192. Sir
    What is the differenece b/w
    System.exit(0); and System.exit(1);
    Both are working same……

    1. 0 indicates normal shutdown. Other than zero indicates abnormal shutdown like terminating the OS with some problems or switching off the power supply directly. Abnormal can be noticed with scan disk (if you do not have a backup power supply (like UPS) and if the power goes abruptly)

  193. sir,
    I have learnt Core JAVA through the excellent site (way2java.com) . I want to learn now Advanced JAVA but i couldn’t find the link for that in this site ,, can you please send me the link through which i can learn the Advance JAVA too .
    Thanks & Regards ,
    khan.

  194. Sir,
    I Learnt Core JAVA from this site but i couldn’t find the advanced java in this site can u please send me a link through where i can learn the advance java .
    Thanks& Regards .
    Khan .

  195. sir i have purchased ur book and its really good for beginers

    dear sir can you tell me good book for servlet and jsp ??

  196. sir, what are the concepts we need to take into consideration if we want to create a simple client networking application?

  197. Sir can u help in sorting this program according to emp.deptid

    /**
    *
    */
    //package com.sirocore.temp;

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

    /**
    * @author Asim Hafeez
    */
    public class SortModified {

    protected static int getRandomNum(int lastNum) {
    Random rand = new Random();
    return (int) rand.nextInt(lastNum);
    }

    class Employee {
    private String employeeName;
    private int employeeId;
    private int deptId;
    }

    public static void main(String[] args) {
    List empList = new ArrayList();
    SortModified sm = new SortModified();
    System.out.println(“Before Sorting ***”);
    for (int i = 1; i < 100; i++) {
    Employee emp = sm.new Employee();
    emp.deptId = getRandomNum(10);

    emp.employeeId = i;
    emp.employeeName = "Mah" + i;
    System.out.println(emp.employeeId + "\t" + emp.employeeName + "\t" + emp.deptId);
    empList.add(emp);

    }
    System.out.println("After Sorting ***");

    }
    }