Home


// ]]>

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
                A D V A N C E     J A V A
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 (Development in progress)
Servlets Introduction, Architecture
First Servlet Step-by-Step Explanation – Login Screen Validation
7 Steps – Servlets Tomcat Execution
View All

580 Responses

Page 6 of 6
  1. Naveen N.P
    April 16, 2014 at 3:01 pm | | Reply

    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.

      1. Naveen N.P
        April 16, 2014 at 5:48 pm | | Reply

        Ok. Thank you.

  2. Naveen N.P
    April 16, 2014 at 12:42 pm | | Reply

    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. Naveen N.P
        April 16, 2014 at 5:45 pm | | Reply

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

  3. April 15, 2014 at 6:17 pm | | Reply

    hai sir
    i want features for java1.5 and java1.6 ,and 1.7

    1. JDK 1.5 added feature are very significant to Programmer:

      http://way2java.com/java-versions-2/jdk-1-5-java-se-5-version/

      JDK 1.6 is not much significant to programmer in real coding as it much deal with memory management and JVM architecture etc:

      http://way2java.com/java-versions-2/jdk-1-6-java-se-6-jdk-1-7-versions/

      For JDK 1.7:

      http://way2java.com/java-versions-2/jdk-1-7-features/

  4. sampath kumar
    April 9, 2014 at 6:20 pm | | Reply

    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. Very nice observation and good work while learning Java. In non-final, a+b is evaluated as int value and assigned to byte (requires casting). In final variables, a+b is evaluated as byte and assigned byte.

      1. sampath kumar
        April 9, 2014 at 7:01 pm | | Reply

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

        1. If it is the case, how Java compiler knows which object is garbage collected in the process? JVM keeps vigil on the process? There are three algorithms here.

          1. sampath kumar
            April 11, 2014 at 12:14 pm |

            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?

          2. April 11, 2014 at 3:59 pm |

            a += b and a++ make an atomic operation.

            a++;

  5. Sam
    April 5, 2014 at 10:02 am | | Reply

    Do we need to write wrapper classes if we use generics?

    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.

  6. anbazhagan
    March 31, 2014 at 7:55 pm | | Reply

    sir ,
    i want all tutoriel in the form of pdf .

    1. Sorry, not possible.

  7. Yacoub Seyni
    March 27, 2014 at 8:53 am | | Reply

    Thank you really for all your help. May God bless you more.

  8. Chaitanya Krishna
    March 25, 2014 at 3:53 pm | | Reply

    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.

      1. Chaitanya Krishna
        March 30, 2014 at 12:09 pm | | Reply

        Thank you very much sir..

  9. Rovin
    March 21, 2014 at 11:19 am | | Reply

    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.

    1. In Test class mian() method, create an object of a and call a class methods.

  10. March 18, 2014 at 10:17 am | | Reply

    Good blog for learning Core Java.

    Thanks:)

  11. Sri Ram
    March 15, 2014 at 8:30 am | | Reply

    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.

  12. abhishek
    March 11, 2014 at 4:28 pm | | Reply

    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

    1. I am unable to understand your question.

  13. Siddu
    March 6, 2014 at 12:47 pm | | Reply

    Could you please one example for abstract class & interface usage?With real time examples!

  14. Siddu
    March 6, 2014 at 12:46 pm | | Reply

    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,

    1. This is how C-lang manages without exception handling.

  15. Siddu
    March 6, 2014 at 12:44 pm | | Reply

    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. 1. Because execution starts from public class only.

      2. It is the modification did by the designers while implementing HashMap.

  16. Siddu
    March 6, 2014 at 12:18 pm | | Reply

    Why Constructor name be should be same as class name? Could you explain.

    1. sanjay
      March 6, 2014 at 12:50 pm | | Reply

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

      Student s=new Student();

    2. The method is differentiated from constructor in two respects – by class name and with no return type. Either of these two, anyone misses, it is not constructor. If you want, I will send a program.

  17. sanjay
    March 4, 2014 at 11:23 pm | | Reply

    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

  18. Aniket
    March 4, 2014 at 2:15 pm | | Reply

    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

  19. Aniket
    March 4, 2014 at 10:41 am | | Reply

    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. Call with class name being static. Non-static, call with subclass object.

      1. Aniket
        March 4, 2014 at 12:07 pm | | Reply

        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

        1. Better call MainMethodOverloadDemo.main(10);

  20. February 25, 2014 at 3:33 pm | | Reply

    i like this post intersting

  21. February 24, 2014 at 1:23 pm | | Reply

    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.

Leave a Reply