Submit Your Site To The Web's Top 50 Search Engines for Free! Java Tutorial: Learn Java Basics For Free | Learn Java

Thursday, September 14, 2023

Java Inheritance Update 2023 With Program And Example

 Java Inheritance Update 2023 With Program And Example 


nheritance is one of the essential concepts in object-orientated programming 
(OOP) that lets in you to create a new magnificence this is based on an current elegance. 
Inheritance allows you to define a brand new elegance (known as a subclass or derived magnificence) via inheriting 
The homes and behaviors (fields and strategies) of an existing class (called a superclass or base magnificence). 
This allows for code reuse and the introduction of a hierarchy of instructions.
Here's a simple Java program that demonstrates inheritance:


// Superclass (Base class)
class Animal {
    String name;

    Animal(String name) {
        this.name = name;
    }

    void eat() {
        System.out.println(name + " is eating.");
    }

    void sleep() {
        System.out.println(name + " is sleeping.");
    }
}

// Subclass (Derived class)
class Dog extends Animal {
    Dog(String name) {
        super(name); // Call the constructor of the superclass
    }

    void bark() {
        System.out.println(name + " is barking.");
    }
}

// Subclass (Derived class)
class Cat extends Animal {
    Cat(String name) {
        super(name); // Call the constructor of the superclass
    }

    void meow() {
        System.out.println(name + " is meowing.");
    }
}

public class InheritanceExample {
    public static void main(String[] args) {
        Dog dog = new Dog("Buddy");
        Cat cat = new Cat("Whiskers");

        dog.eat();
        dog.sleep();
        dog.bark();

        cat.eat();
        cat.sleep();
        cat.meow();
    }
}


In this program:

We define a Animal superclass with fields call and methods devour() and sleep().
We create  subclasses, dog and Cat, which inherit from the Animal superclass.
Both canine and Cat training have their constructors, and they name the constructor of 
The superclass using awesome(name) to initialize the call discipline.
Every subclass has extra strategies (bark() for canine and meow() 
For Cat) further to the inherited techniques.
Within the essential approach, we create instances of dog and Cat and show how inheritance 
Works by means of calling each inherited and subclass-unique methods.
That is a fundamental example of inheritance in Java, wherein subclasses inherit the houses 
And behaviors of the superclass, taking into consideration code reuse and 
Company of associated lessons in a hierarchy.

Tuesday, June 13, 2023

A Basic Java Program For Beginners 2023

 A Basic Java Program For Beginners 2023

                 Static Nested Class


1) Static Nested ClassIn java static nested class is a class which is defined in a class with static keyword.

static nested class cannot access non-static data member and methods of outer class. It can access only static data member of outer class including private.

 Java Static Nested Class Example

class Simple
{
static int a = 700;
static class SimpleInner
{
void show()
{
System.out.println("value is"+a);
}
}
public static void main(String args[])
{
Simple.SimpleInner s = new Simple.SimpleInner();
s.show();
}
}

https://cjavapoint.blogspot.com/?m=1
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples

Non-Static Nested Class(inner class)


*1) Member Inner Class* 
 
In java member inner class is a class which is defined in class but outside of a method is called member inner class.

*Java Member Inner Class Example* 

Java member inner class defined in a class but outside of method of that class.

In this example we will create outer class(MemberOuter) and inner class(MemberInner) and declare a private data member in outer class and access this private data member in inner class because inner class can access all the data members and methods in inner class, including private data member and methods.

class MemberOuter
{
private int salary = 4000;//private data member of outer class
class MemberInner
{
void get()
{
System.out.println("salary is "+salary);//access in inner class
}
}
public static void main(String args[])
{
MemberOuter mo = new MemberOuter();
MemberOuter.MemberInner mi = mo.new MemberInner();
mi.get();
}

output : salary is 4000 

Note :

(1)  In case of java outer and inner class, Here the java compiler creates two .class files the first is MemberOuter.class and MemberOuter$MemberInner.class.


(2) If you want to instantiate inner class, you must have to create the instance of outer class and instance of inner class is created inside the instance of outer class.

*2) Anonymous Inner Class* 

In java anonymous inner class is a class that have no name is called anonymous inner class. This class can be instantiated only once. It is usually declared inside a method or block.


Anonymous inner class can be created by two ways in java 

Using class(abstract or concrete)
Using interface


*Java Anonymous Inner Class Example* 

 abstract class AIExample
{
abstract void show();
}
class Test
{
public static void main(String args[])
{
AIExample a = new AIExample()
{
void show()
{
System.out.println("Method of anonymous class");
}
};
a.show();
}
}


output : Method of anonymous class 
 
The above example is performing anonymous by using abstract class.

*Java Anonymous Inner Class Example - Using Interface* 


This is simple example of anonymous inner class using interface.
 
interface AnonymousExmple
{
void show();
}
 
class Test
{
public static void main(String args[])
{
AnonymousExmple ae = new AnonymousExmple()
{
public void show()
{
System.out.println("hello java ");
}
};
ae.show();
}
}
output : hello java

*3) Java Local Inner Class* 

In java local inner class is a class which is created inside a method is called local inner class in java. If you want to invokes the method of local inner class, you must instantiate this class inside the method.


*Java Local Inner Class Example* 

class LICExample
{
private int a = 40;
void show()
{
class LICExample1
{
void get()
{
System.out.println("value is "+a);
}
}
LICExample1 l = new LICExample1();
l.get();
}
public static void main(String args[])
{
LICExample ll = new LICExample();
ll.show();
}
}

output : value is 40

Thursday, August 11, 2022

Explain Collection Framework Hierarchy in Java 2022 Update.

 Explain Collection Framework Hierarchy in Java 2022 Update. 

All the interfaces and classes for the collection framework are located in java.util package.
The basic interface of the collections framework is the Collection interface which is the root interface of all collections in the API and placed at the top of the collection hierarchy.Collection interface extends the Iterable interface. 
Collection Framework Hierarchy in Java core-java-interview-questions for freshers 



1. List

It handles sequential list of objects. ArrayList, Vector and LinkedList classes implement this interface.

2. Queue

It handles the special group of objects in which elements are removed only from the head. 
Linked List and Priority Queue classes implement this interface.

3. Set

It handles the group of objects which must contain only unique elements. 
This interface is implemented by HashSet and LinkedHashSet classes and extended by 
SortedSet interface which in turn, is implemented by TreeSet.

4. Map

This is the one interface in Collection Framework which is not inherited from Collection interface. 
It handles the group of objects as Key/Value pairs. It is implemented by 
HashMap and HashTable classes and extended by SortedMap interface which in turn is implemented by TreeMap.
Three of above interfaces (List, Queue and Set) inherit from Collection interface.
Although, Map is included in collection framework it does not inherit from Collection interface.





Sunday, July 24, 2022

What are Major Features of java New Update Varsion 2022 ?

         Q: What are the major features of Java ?

             Answer:
             A list of most important features of Java language is given below

1. Simple

Java is easy to learn and its syntax is quite simple, clean and easy to understand. The confusing and ambiguous concepts of C++ are either left out in Java or they have been re-implemented in a cleaner way.
Eg : Pointers and Operator Overloading are not there in java but were an important part of C++.

2. Object Oriented

Java is an object-oriented programming language. Everything in Java is an object. Object-oriented means we organize our software as a combination of different types of objects that incorporates both data and behavior. Object-oriented programming (OOPs) is a methodology that simplifies software development and maintenance by providing some rules.

3. Robust

Robust simply means strong. Java is designed to eliminate certain types of programming errors. Java is strongly typed, which allows extensive compile-time error checking. It does not support memory pointers, which eliminates the possibility of overwriting memory and corrupting data. In addition, its automatic memory management (garbage collection) eliminates memory leaks and other problems associated with dynamic memory allocation/de-allocation.

4. Platform Independent

Unlike other programming languages such as C, C++ etc which are compiled into platform specific machines. Java is guaranteed to be write-once, run-anywhere language.On compilation Java program is compiled into bytecode. This bytecode is platform independent and can be run on any machine, plus this bytecode format also provide security. Any machine with Java Runtime Environment can run Java Programs.Java is platform Independent Language

5. Secure

When it comes to security, Java is always the first choice. With java secure features it enable us to develop virus free, temper free system. Java program always runs in Java runtime environment with almost null interaction with system OS, hence it is more secure. Java is designed to be secure in a networked environment too. The Java runtime environment uses a bytecode verification process to ensure that code loaded over the network does not violate Java security constraints.

6. Multi Threading

Java multithreading feature makes it possible to write program that can do many tasks simultaneously. Benefit of multithreading is that it utilizes same memory and other resources to execute multiple threads at the same time, like While typing, grammatical errors are checked along.

7. Architectural Neutral

Compiler generates bytecodes, which have nothing to do with a particular computer architecture, hence a Java program is easy to intrepret on any machine.

Sunday, September 13, 2020

Xpanxion Mumbai Interview Questions latest 2020

 Interview Questions and Answers for Xpanxion 2020 Letest Questions & Answers 

All The question of  Xpanxion Round 1st Clear. All type of core Java Question Asking in Xpanxion Company. Interview Questions in Mumbai Xpanxion

Interview Question for Xpanxion Mumbai.




Que 1. What is dot operator ?

Ans:-    The dot operator(.) is used to access the
              instance varibles and methods of class
     objects.it is also used to access classes and
     sub-packages from a package.
===================================================================

Que 2. List any five features of Java ?

Ans:-    Some features include Object Oriented, platform 
             Independent, Robust,interpreted,Multi-threaded.
===================================================================

Que 3. Why deletion in LinkList is fast than ArrayList ?

Ans:-     Deletion in linked list is fast because it involves only
               updating the next pointer in the node before the 
      deleted node and updating the previous pointer in 
              the node after the deleted node.
===================================================================

Que 4. How do you decide when to use ArrayList and LinkList ?

Ans:-     if you need to frequently add and remove elements 
              from the middle of the list and only access the list
             elements sequentially, then LinkList should be used.
             if you need to support random access, without 
             inserting or removing elements from any place 
            other than the end, than ArrayList should be used.
===================================================================

Que 5. What are synchronized methods and synchronized statements ?

Ans:-     synchronized methods are methods that are used to control 
               access to an object.A thread only executes a synchronized method
              after has acquired the lock of the methods object or class. 
              Synchronized Statements are similar to synchronized methods.
             A synchronized statements can only be executed after a thread has 
             acquired the lock of the object or class referenced 
            in the synchronized statement.
===================================================================

Que 6.  What is Polymorphism in Java ? 

Ans:-      Polymorphism is the ability to of an object to take 
       on many forms.The most common use of polymorphism 
               in OOP occur when a parent class reference is used
       to refer to a child class object.
===================================================================

Que 7.  What are native methods? How do you use them ?

Ans:-     Native methods are methods whose implementation is provided 
              in another programming language  such as C.The main objective of native
             method are to improve th performance of the system.
===================================================================

Que 8. What is HAS-A relationship in Java ?

Ans:-     1. HAS-A Relationship is also knows as composition(or) aggregation.
               2. There is no specific keyword to implement HAS-A relationship but mostly 
                   we can use new operator.
              3. The main advantage of  reusability.
===================================================================

Que 9. What is Encapsulation ?

Ans:-     Binding a data and corresponding method in a single 
              unit is called encapsulation.If any class follows data 
      hiding and abstraction such type of class is called encapsulated class.
             ENCAPSULATION= ABSTRACTION+DATA HIDING
===================================================================

 learn java Is for All The java Lover and java beginners.
 Learn java provide java interview preparations Questions And Answers .
 we will do over best for all the java devlopers.
 As a Java professional, it is essential to know the right things
 learn the java technologies and prepare the right answers to commonly 
 asked Java Interview Questions. 
 Here’s a definitive list of top Java Interview Questions that will 
 guarantee a breeze-through to the next level. 

Saturday, September 12, 2020

Interview Questions and Answers for Xpanxion 2020 Letest Questions & Answers 2020

 Interview Questions and Answers for Xpanxion 2020 Letest Questions & Ans

All The question of  Xpanxion Round 1st Clear. All type of core Java Question Asking in Xpanxion Company.


Que 1.   Give a few reasons for using java ?   

Ans:-           Built-in support for multi-threading ,socket communications,                                                                             and memory management. object oriented ,better portability                                                                             then other languages across operating system.support web based                                                                  applications,distributed applications.etc

              

              

Que 2. Tell Me Somthing About OOP'S Concept ?

Ans:-      OOP'S is called object oriented programming.
                  It is a programming  model in java.                                                                                                    OOP'S provide some concept to programming they are.
               1.      Abstraction.
              2.     Data Hiding.
              3.     Encapsulation.
              4.    Tightly encapsulation class.
              5.    IS-A Relationship(Inheritance).
              6    .HAS-A Relationship.
              7.    Method Singnature
              8    .Polymorphism
              9.   Static Control Flow.
            10.   Singleton Class.
            11.   Fectory Method.


Que 3. What is Polymorphism in Java ? 

Ans:-   Polymorphism is the ability to of an object to take 

on many forms.The most common use of polymorphism 

             in OOP occur when a parent class reference is used

to refer to a child class object.



Que 4. How many methods in Externalizable interface ?

Ans:-  There are two method in Externalizable interface.You have to implement these
            two methods in order to make your class externalizable. These two methods are
           1. readExternal().
           2. writeExternal().



Que 5. What is Iterator interface ?

Ans:-    The Iterator interface is used to step through the element of a Collection.



Que 6. What are native methods? How do you use them ?

Ans:-    Native methods are methods whose implementation is provided 
             in another programming language  such as C.The main objective of native
             method are to improve th performance of the system.



Que 7. What is HAS-A relationship in Java ?

Ans:-   1. HAS-A Relationship is also knows as composition(or) aggregation.
            2. There is no specific keyword to implement HAS-A relationship but mostly 
                 we can use new operator.
           3. The main advantage of  reusability.




All the MNC Company Interview Questions here  for java Devloper
xpanxion java interview questions for All the java devloper 
xebia gurgaon java interview questions,xerago java interview questions
xavient java interview questions,java interview questions for vyom labs
java interview questions zycus.

Xpanxion All Over the India branch(Company) Questions And Ans. they are locate in anywhere in india
xpanxion (pune coding questions),xpanxion (delhi coding questions),xpanxion (noida coding questions),xpanxion (channai coding questions).


Tuesday, December 17, 2019

What is a method signature in Java? -Learn Java

What is a method signature in Java? -Learn Java


In java, method signature consists of name of the method followed by argument types.

Example:


https://cjavapoint.blogspot.com/
in java return type is not part of the method signature .Compiler will use method signature 
while resolving method calls.

   class Demo
  {
      public void m1(double d){ }
      public void m2(int i)    { }
      public static void main(String args[]){
         Demo d=new Demo();
         d.m1(11.2);
         d.m2(10);
         d.m3();  //CE
    }
  }

CE:cannot find symbol
symbol:method m3(double)
location:class Demo


Within  the same class we cant't take 2 method with the same signature otherwise we will 
get compile time error.

Example:

   public void methodOne() { }
   public int methodOne() { 
    
     return 10;
   }

Output:

Compile time error
methodOne() is already defined in Demo.










             

Java Inheritance Update 2023 With Program And Example

  Java Inheritance Update 2023 With Program And Example  nheritance is one of the essential concepts in object-orientated programming  (OOP)...