16 Feb
16Feb

TB-1: How to create an Object in Java ?

public class student {
    
     String student_id;
     String student_name;

     public void studentDetails() {
        System.out.println("Student ID is : " + student_id);
        System.out.println("Student Name is : " + student_name);  
     }
}

// To Create student object

   student s1 = new student();

TB-2: How to define a method and call the method in Java?

import java.util.Scanner;

public class Calculator {

   // add method implementation
     public void add(int a, int b) {
           int sum = a+b;
           System.out.println("Sum of a+b is : " + sum);
     }
    
     public static void main(String[] args) { 
           int num1, num2;
           Scanner input = new Scanner(System.in);

           // Reading A and B from user console
           System.out.println("Enter A : ");
           num1 = input.nextInt();
           System.out.println("Enter B : ");
           num2 = input.nextInt();

           //calling add method
           add(num1, num2);
     }

TB-3: What is Encapsulation?

Encapsulation

TB-4: What is an Abstraction in Java?

Abstraction

TB-5: What is Inheritance in Java?

Inheritance

TB-6: What is Polymorphism in Java?

Polymorphism
Polymorphism

TB-7: What is Constructor in Java and sample code? 

A Constructor in Java is a special method that is used to initialize the objects. The Constructor is called when an object of a class is created, It can be used to set the initial values for an object attributes.

Constructor name must match the class name, and it can not have return type (like void).

Constructor is called when the object is created.

All classes will have constructors by default: if you don’t create a class constructor yourself, Java creates one for you.

Constructors

TB-8: What is an Interface in Java, and sample code?

Interfaces are class templates. Interfaces define methods for classes by specifying the method name, the return type (or void) and the method arguments (by type and name). These methods are called signatures.

Because this is a template, the method signature contain no code. The code will be part of an  implementation of an interface. Interfaces are used in the discipline of polymorphism.

  1. If a class implements an interface, all of the interface’s methods must appear in the class.
  2. The implement keyword is used when creating a class that is modeled after an interface.
Interface

TB-9: What is a Program in Software Applications?

Computer Program

TB-10: Why interface variables are public, static and final?

Interface does not have a direct object, the only way to access them is by using a class/interface. That is why if interface variable exists, it should be static otherwise it wont be accessible at all to outside world. 

Now since it is static, it can hold only one value and any class that extends it can change the value, so to ensure that it holds a constant value, it has been made final. These are the reasons interface variables are static and final and obviously public.

TB-11: Why interface methods are public and abstract?

Interfaces are meant to define the public API of a type – and only that, not its implementation. 

So any method you define in an interface is by definition public and abstract.

TB-12: What is Collections in Java?

The Collection in Java is a framework that provides an architecture to store and manipulate the group of objects.

Java Collections can achieve all the operations that you perform on a data such as 

  1. searching, 
  2. sorting,
  3. insertion, 
  4. manipulation, and deletion.

Java Collection means a single unit of objects. Java Collection framework provides many interfaces (Set, List, Queue, Deque)

and classes (ArrayList , Vector, LinkedList , PriorityQueue , HashSet, LinkedHashSet, & TreeSet).

Collections

TB-13: Some basic programs in Java

TB-14: Some basic programs on Java Strings

TB-15: Some programs on Java Methods

TB-16: What JDK (Java Development Kit) Contains?

JDK

TB-17: What is an Identifier in Java?

Identifier

TB-18: What is Data Type in Java?

Data Type

TB-19: Type Conversion in Java

Type Conversion
Type Conversion

TB-20: How Logical Operators work in Java?

Logical Operators

TB-21: How Relational Operators work in Java?

Relational Operators

TB-22: Notes on User Input and Types of Errors in Java?

Comments
* The email will not be published on the website.