Question stringlengths 1 113 | Answer stringlengths 22 6.98k |
|---|---|
What is Interface in Java? | An interface in Java is a blueprint of a class. It has static constants and abstract methods.
The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not method body. It is used to achieve abstraction and multiple inheritance in Java.
In other words, you ... |
Why use Java interface? | There are mainly three reasons to use interface. They are given below.
-It is used to achieve abstraction.
-By interface, we can support the functionality of multiple inheritance.
-It can be used to achieve loose coupling. |
How to declare an interface? | An interface is declared by using the interface keyword. It provides total abstraction; means all the methods in an interface are declared with the empty body, and all the fields are public, static and final by default. A class that implements an interface must implement all the methods declared in the interface. |
Can you provide Java Interface Example? | In this example, the Printable interface has only one method, and its implementation is provided in the A6 class.
interface printable{
void print();
}
class A6 implements printable{
public void print(){System.out.println("Hello");}
public static void main(String args[]){
A6 obj = new A6();
o... |
Can you provide Java Interface Example: Drawable? | In this example, the Drawable interface has only one method. Its implementation is provided by Rectangle and Circle classes. In a real scenario, an interface is defined by someone else, but its implementation is provided by different implementation providers. Moreover, it is used by someone else. The implementation par... |
Can you provide Java Interface Example: Bank? | Let's see another example of java interface which provides the implementation of Bank interface.
File: TestInterface2.java
interface Bank{
float rateOfInterest();
}
class SBI implements Bank{
public float rateOfInterest(){return 9.15f;}
}
class PNB implements Bank{
public float rateOfInterest(){return 9... |
Multiple inheritance is not supported through class in java, but it is possible by an interface, why? | As we have explained in the inheritance chapter, multiple inheritance is not supported in the case of class because of ambiguity. However, it is supported in case of an interface because there is no ambiguity. It is because its implementation is provided by the implementation class. For example:
interface Printable{ ... |
What is Interface inheritance? | A class implements an interface, but one interface extends another interface. |
Can you provide Java 8 Default Method in Interface? | Since Java 8, we can have method body in interface. But we need to make it default method. Let's see an example:
interface Drawable{
void draw();
default void msg(){System.out.println("default method");}
}
class Rectangle implements Drawable{
public void draw(){System.out.println("drawing rectangle");} ... |
Can you provide Java 8 Static Method in Interface? | ince Java 8, we can have static method in interface. Let's see an example:
interface Drawable{
void draw();
static int cube(int x){return x*x*x;}
}
class Rectangle implements Drawable{
public void draw(){System.out.println("drawing rectangle");}
}
class TestInterfaceStatic{
public static voi... |
What is marker or tagged interface? | An interface which has no member is known as a marker or tagged interface, for example, Serializable, Cloneable, Remote, etc. They are used to provide some essential information to the JVM so that JVM may perform some useful operation.
//How Serializable interface is written?
public interface Serializable{
} |
What is Nested Interface in Java? | Note: An interface can have another interface which is known as a nested interface. We will learn it in detail in the nested classes chapter. For example:
interface printable{
void print();
interface MessagePrintable{
void msg();
}
} |
Can you provide an Example of abstract class and interface in Java? | Let's see a simple example where we are using interface and abstract class both.
//Creating interface that has 4 methods
interface A{
void a();//bydefault, public and abstract
void b();
void c();
void d();
}
//Creating abstract class that provides the implementation of one method of A interface... |
What is Java Package? | A java package is a group of similar types of classes, interfaces and sub-packages.
Package in java can be categorized in two form, built-in package and user-defined package.
There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
|
What is the Advantage of Java Package? | 1) Java package is used to categorize the classes and interfaces so that they can be easily maintained.
2) Java package provides access protection.
3) Java package removes naming collision.
|
Can you provide Simple example of java package? | The package keyword is used to create a package in java.
//save as Simple.java
package mypack;
public class Simple{
public static void main(String args[]){
System.out.println("Welcome to package");
}
} |
How to access package from another package? | There are three ways to access the package from outside the package.
1.import package.*;
2.import package.classname;
3.fully qualified name. |
What is Using packagename? | If you use package.* then all the classes and interfaces of this package will be accessible but not subpackages.
The import keyword is used to make the classes and interface of another package accessible to the current package. |
Can you provide an Example of package that import the packagename? | //save by A.java
package pack;
public class A{
public void msg(){System.out.println("Hello");}
}
//save by B.java
package mypack;
import pack.*;
class B{
public static void main(String args[]){
A obj = new A();
obj.msg();
}
}
Output:Hello |
What is Using packagename.classname? | If you import package.classname then only declared class of this package will be accessible. |
Can you provide an Example of package by import package.classname? | //save by A.java
package pack;
public class A{
public void msg(){System.out.println("Hello");}
}
//save by B.java
package mypack;
import pack.A;
class B{
public static void main(String args[]){
A obj = new A();
obj.msg();
}
}
Output:Hello |
How the Using fully qualified name work? | If you use fully qualified name then only declared class of this package will be accessible. Now there is no need to import. But you need to use fully qualified name every time when you are accessing the class or interface.
It is generally used when two packages have same class name e.g. java.util and java.sql packa... |
Can you provide an Example of package by import fully qualified name? | //save by A.java
package pack;
public class A{
public void msg(){System.out.println("Hello");}
}
//save by B.java
package mypack;
class B{
public static void main(String args[]){
pack.A obj = new pack.A();//using fully qualified name
obj.msg();
}
}
Output:Hello |
What is Subpackage in java? | Package inside the package is called the subpackage. It should be created to categorize the package further. |
Can you provide an Example of Subpackage? | package com.javatpoint.core;
class Simple{
public static void main(String args[]){
System.out.println("Hello subpackage");
}
}
To Compile: javac -d . Simple.java
To Run: java com.javatpoint.core.Simple
Output:Hello subpackage |
What are the Ways to load the class files or jar files? | There are two ways to load the class files temporary and permanent.
-Temporary
By setting the classpath in the command prompt
By -classpath switch
-Permanent
By setting the classpath in the environment variables
By creating the jar file, that contains all the class files, and copying the jar file in the jre/lib/e... |
How to put two public classes in a package? | If you want to put two public classes in a package, have two java source files containing one public class, but keep the package name same. For example:
//save as A.java
package javatpoint;
public class A{}
//save as B.java
package javatpoint;
public class B{} |
What is Access Modifiers in Java? | There are two types of modifiers in Java: access modifiers and non-access modifiers.
The access modifiers in Java specifies the accessibility or scope of a field, method, constructor, or class. We can change the access level of fields, constructors, methods, and class by applying the access modifier on it.
There are f... |
What is Private? | The private access modifier is accessible only within the class.
Simple example of private access modifier
In this example, we have created two classes A and Simple. A class contains private data member and private method. We are accessing these private members from outside the class, so there is a compile-time e... |
What is Default? | If you don't use any modifier, it is treated as default by default. The default modifier is accessible only within package. It cannot be accessed from outside the package. It provides more accessibility than private. But, it is more restrictive than protected, and public.
Example of default access modifier
In thi... |
What is Protected? | The protected access modifier is accessible within package and outside the package but through inheritance only.
The protected access modifier can be applied on the data member, method and constructor. It can't be applied on the class.
It provides more accessibility than the default modifer.
Example of protect... |
What is Public? | The public access modifier is accessible everywhere. It has the widest scope among all other modifiers.
Example of public access modifier
//save by A.java
package pack;
public class A{
public void msg(){System.out.println("Hello");}
}
//save by B.java
package mypack;
import pack.*;
... |
Can you provide an example of Java Access Modifiers with Method Overriding? | If you are overriding any method, overridden method (i.e. declared in subclass) must not be more restrictive.
class A{
protected void msg(){System.out.println("Hello java");}
}
public class Simple extends A{
void msg(){System.out.println("Hello java");}//C.T.Error
public static void main(String a... |
What is Encapsulation in Java? | Encapsulation in Java is a process of wrapping code and data together into a single unit, for example, a capsule which is mixed of several medicines.
encapsulation in java
We can create a fully encapsulated class in Java by making all the data members of the class private. Now we can use setter and getter methods t... |
What is the Advantage of Encapsulation in Java? | By providing only a setter or getter method, you can make the class read-only or write-only. In other words, you can skip the getter or setter methods.
It provides you the control over the data. Suppose you want to set the value of id which should be greater than 100 only, you can write the logic inside the setter meth... |
Can you provide Simple Example of Encapsulation in Java? | Let's see the simple example of encapsulation that has only one field with its setter and getter methods.
//A Java class which is a fully encapsulated class.
//It has a private data member and getter and setter methods.
package com.javatpoint;
public class Student{
//private data member
private String na... |
What is Read-Only class? | //A Java class which has only getter methods.
public class Student{
//private data member
private String college="AKG";
//getter method for college
public String getCollege(){
return college;
}
} |
What is Write-Only class? | //A Java class which has only setter methods.
public class Student{
//private data member
private String college;
//getter method for college
public void setCollege(String college){
this.college=college;
}
} |
Can you provide Another Example of Encapsulation in Java? | Let's see another example of encapsulation that has only four fields with its setter and getter methods.
//A Account class which is a fully encapsulated class.
//It has a private data member and getter and setter methods.
class Account {
//private data members
private long acc_no;
private String name,email; ... |
What is Java Arrays? | Normally, an array is a collection of similar type of elements which has contiguous memory location.
Java array is an object which contains elements of a similar data type. Additionally, The elements of an array are stored in a contiguous memory location. It is a data structure where we store similar elements. We ca... |
What are the Types of Array in java? | There are two types of array.
-Single Dimensional Array
-Multidimensional Array
|
WHat is Single Dimensional Array in Java? |
Syntax to Declare an Array in Java
dataType[] arr; (or)
dataType []arr; (or)
dataType arr[];
Instantiation of an Array in Java
arrayRefVar=new datatype[size];
|
Can you provide an Example of Java Array? | Let's see the simple example of java array, where we are going to declare, instantiate, initialize and traverse an array.
//Java Program to illustrate how to declare, instantiate, initialize
//and traverse the Java array.
class Testarray{
public static void main(String args[]){
int a[]=new int[5];//decla... |
Can you provide an example of Declaration, Instantiation and Initialization of Java Array? | We can declare, instantiate and initialize the java array together by:
int a[]={33,3,4,5};//declaration, instantiation and initialization
Let's see the simple example to print this array.
//Java Program to illustrate the use of declaration, instantiation
//and initialization of Java array in a single lin... |
Can you provide the For-each Loop for Java Array? | We can also print the Java array using for-each loop. The Java for-each loop prints the array elements one by one. It holds an array element in a variable, then executes the body of the loop.
The syntax of the for-each loop is given below:
for(data_type variable:array){
//body of the loop
}
Let us see ... |
Can you provide the Passing Array to a Method in Java? | We can pass the java array to method so that we can reuse the same logic on any array.
Let's see the simple example to get the minimum number of an array using a method.
//Java Program to demonstrate the way of passing an array
//to method.
class Testarray2{
//creating a method which receives an array as... |
Can you provide the Anonymous Array in Java? | Java supports the feature of an anonymous array, so you don't need to declare the array while passing an array to the method.
//Java Program to demonstrate the way of passing an anonymous array
//to method.
public class TestAnonymousArray{
//creating a method which receives an array as a parameter
static... |
Can you provide the Returning Array from the Method? | We can also return an array from the method in Java.
//Java Program to return an array from the method
class TestReturnArray{
//creating method which returns an array
static int[] get(){
return new int[]{10,30,50,90,60};
}
public static void main(String args[]){
//calling method which return... |
Can you provide the ArrayIndexOutOfBoundsException? | The Java Virtual Machine (JVM) throws an ArrayIndexOutOfBoundsException if length of the array in negative, equal to the array size or greater than the array size while traversing the array.
//Java Program to demonstrate the case of
//ArrayIndexOutOfBoundsException in a Java Array.
public class TestArrayException... |
What is Multidimensional Array in Java? | In such case, data is stored in row and column based index (also known as matrix form).
Syntax to Declare Multidimensional Array in Java
dataType[][] arrayRefVar; (or)
dataType [][]arrayRefVar; (or)
dataType arrayRefVar[][]; (or)
dataType []arrayRefVar[];
Example to instantiate Multidimensional Array in Java... |
Can you provide an Example of Multidimensional Java Array? | arr[0][0]=1;
arr[0][1]=2;
arr[0][2]=3;
arr[1][0]=4;
arr[1][1]=5;
arr[1][2]=6;
arr[2][0]=7;
arr[2][1]=8;
arr[2][2]=9;
|
What is Jagged Array in Java? | Let's see the simple example to declare, instantiate, initialize and print the 2Dimensional array.
//Java Program to illustrate the use of multidimensional array
class Testarray3{
public static void main(String args[]){
//declaring and initializing 2D array
int arr[][]={{1,2,3},{2,4,5},{4,4,5}};
//printing 2... |
What is the class name of Java array? | In Java, an array is an object. For array object, a proxy class is created whose name can be obtained by getClass().getName() method on the object.
//Java Program to get the class name of array in Java
class Testarray4{
public static void main(String args[]){
//declaration and initialization of array
int... |
Can you provide the Copying a Java Array? | We can copy an array to another by the arraycopy() method of System class.
Syntax of arraycopy method
public static void arraycopy(
Object src, int srcPos,Object dest, int destPos, int length
)
|
What is the Example of Copying an Array in Java? | //Java Program to copy a source array into a destination array in Java
class TestArrayCopyDemo {
public static void main(String[] args) {
//declaring a source array
char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e',
'i', 'n', 'a', 't', 'e', 'd' };
//decl... |
Can you provide the Cloning an Array in Java? | Since, Java array implements the Cloneable interface, we can create the clone of the Java array. If we create the clone of a single-dimensional array, it creates the deep copy of the Java array. It means, it will copy the actual value. But, if we create the clone of a multidimensional array, it creates the shallow copy... |
What is Addition of 2 Matrices in Java? | Let's see a simple example that adds two matrices.
//Java Program to demonstrate the addition of two matrices in Java
class Testarray5{
public static void main(String args[]){
//creating two matrices
int a[][]={{1,3,4},{3,4,5}};
int b[][]={{1,3,4},{3,4,5}};
//creating another matrix to store the sum of ... |
Can you provide the Multiplication of 2 Matrices in Java? | In the case of matrix multiplication, a one-row element of the first matrix is multiplied by all the columns of the second matrix.
Let's see a simple example to multiply two matrices of 3 rows and 3 columns.
//Java Program to multiply two matrices
public class MatrixMultiplicationExample{
public static void m... |
What is Object class in Java? | The Object class is the parent class of all the classes in java by default. In other words, it is the topmost class of java.
The Object class is beneficial if you want to refer any object whose type you don't know. Notice that parent class reference variable can refer the child class object, know as upcasting.
Le... |
What are the Methods of Object class? | Methods of Object class
The Object class provides many methods. They are as follows:
Method: public final Class getClass()
Description: returns the Class class object of this object. The Class class can further be used to get the metadata of this class.
Method: public int hashCode()
Description: returns the ha... |
What is Object Cloning in Java? | The object cloning is a way to create exact copy of an object. The clone() method of Object class is used to clone an object.
The java.lang.Cloneable interface must be implemented by the class whose object clone we want to create. If we don't implement Cloneable interface, clone() method generates CloneNotSupportedE... |
Why use clone() method ? | The clone() method saves the extra processing task for creating the exact copy of an object. If we perform it by using the new keyword, it will take a lot of processing time to be performed that is why we use object cloning. |
What is the Advantage of Object cloning? | Although Object.clone() has some design issues but it is still a popular and easy way of copying objects
. Following is a list of advantages of using clone() method:
-You don't need to write lengthy and repetitive codes. Just use an abstract class with a 4- or 5-line long clone() method.
-It is the easiest and most ef... |
What is the Disadvantage of Object cloning? | Following is a list of some disadvantages of clone() method:
-To use the Object.clone() method, we have to change a lot of syntaxes to our code, like implementing a Cloneable interface, defining the clone() method and handling CloneNotSupportedException, and finally, calling Object.clone() etc.
-We have to implement c... |
Can you provide an Example of clone() method (Object cloning)? | Let's see the simple example of object cloning
class Student18 implements Cloneable{
int rollno;
String name;
Student18(int rollno,String name){
this.rollno=rollno;
this.name=name;
}
public Object clone()throws CloneNotSupportedException{
return super.clone();
}
public static ... |
What is Java Math class? | Java Math class provides several methods to work on math calculations like min(), max(), avg(), sin(), cos(), tan(), round(), ceil(), floor(), abs() etc.
Unlike some of the StrictMath class numeric methods, all implementations of the equivalent function of Math class can't define to return the bit-for-bit same resul... |
Can you provide the Java Math Methods? | The java.lang.Math class contains various methods for performing basic numeric operations such as the logarithm, cube root, and trigonometric functions etc. |
Can you provide the Basic Math methods? | Basic Math methods
Method: Math.abs()
Description: It will return the Absolute value of the given value.
Method:Math.max()
Description: It returns the Largest of two values.
Method:Math.min()
Description: It is used to return the Smallest of two values.
Method:Math.round()
Description: It is used to... |
Can you provide the Logarithmic Math Methods? | Logarithmic Math Methods
Method: Math.log()
Description: It returns the natural logarithm of a double value.
Method: Math.log10()
Description: It is used to return the base 10 logarithm of a double value.
Method: Math.log1p()
Description: It returns the natural logarithm of the sum of the argument and... |
Can you provide the Trigonometric Math Methods? | Trigonometric Math Methods
Method: Math.sin()
Description: It is used to return the trigonometric Sine value of a Given double value.
Method: Math.cos()
Description: It is used to return the trigonometric Cosine value of a Given double value.
Method: Math.tan()
Description: It is used to return the trig... |
Can you provide the Hyperbolic Math Methods? | Hyperbolic Math Methods
Method: Math.sinh()
Description: It is used to return the trigonometric Hyperbolic Cosine value of a Given double value.
Method: Math.cosh()
Description: It is used to return the trigonometric Hyperbolic Sine value of a Given double value.
Method: Math.tanh()
Description: It is use... |
Can you provide the Angular Math Methods? | Method: Math.toDegrees
Description: It is used to convert the specified Radians angle to equivalent angle measured in Degrees.
Method: Math.toRadians
Description: It is used to convert the specified Degrees angle to equivalent angle measured in Radians.
|
What is Wrapper classes in Java? | The wrapper class in Java provides the mechanism to convert primitive into object and object into primitive.
Since J2SE 5.0, autoboxing and unboxing feature convert primitives into objects and objects into primitives automatically. The automatic conversion of primitive into an object is known as autoboxing and vice-... |
What is the Use of Wrapper classes in Java? | Java is an object-oriented programming language, so we need to deal with objects many times like in Collections, Serialization, Synchronization, etc. Let us see the different scenarios, where we need to use the wrapper classes.
-Change the value in Method: Java supports only call by value. So, if we pass a primitive va... |
What is Autoboxing? | The automatic conversion of primitive data type into its corresponding wrapper class is known as autoboxing, for example, byte to Byte, char to Character, int to Integer, long to Long, float to Float, boolean to Boolean, double to Double, and short to Short.
Since Java 5, we do not need to use the valueOf() method of w... |
Can you provide the Wrapper class Example: Primitive to Wrapper? | //Java program to convert primitive into objects
//Autoboxing example of int to Integer
public class WrapperExample1{
public static void main(String args[]){
//Converting int into Integer
int a=20;
Integer i=Integer.valueOf(a);//converting int into Integer explicitly
Integer j=a;//autoboxing, now c... |
What is Unboxing? | The automatic conversion of wrapper type into its corresponding primitive type is known as unboxing. It is the reverse process of autoboxing. Since Java 5, we do not need to use the intValue() method of wrapper classes to convert the wrapper type into primitives |
Can you Wrapper class Example: Wrapper to Primitive? | //Java program to convert object into primitives
//Unboxing example of Integer to int
public class WrapperExample2{
public static void main(String args[]){
//Converting Integer to int
Integer a=new Integer(3);
int i=a.intValue();//converting Integer to int explicitly
int j=a;//unboxing, now... |
Can you provide the Java Wrapper classes Example?
| //Java Program to convert all primitives into its corresponding
//wrapper objects and vice-versa
public class WrapperExample3{
public static void main(String args[]){
byte b=10;
short s=20;
int i=30;
long l=40;
float f=50.0F;
double d=60.0D;
char c='a';
boolean b2=true;
//Autobo... |
Can you provide the Custom Wrapper class in Java? | Java Wrapper classes wrap the primitive data types, that is why it is known as wrapper classes. We can also create a class which wraps a primitive data type. So, we can create a custom wrapper class in Java.
//Creating the custom wrapper class
class Javatpoint{
private int i;
Javatpoint(){}
Javatpoint(int i){ ... |
What is Recursion in Java? | Recursion in java is a process in which a method calls itself continuously. A method in java that calls itself is called recursive method.
It makes the code compact but complex to understand.
Syntax:
returntype methodname(){
//code to be executed
methodname();//calling same method
} |
Can you provide the Java Recursion Example 1: Infinite times? | public class RecursionExample1 {
static void p(){
System.out.println("hello");
p();
}
public static void main(String[] args) {
p();
}
} Output:hello
hello
...
java.lang.StackOverflowError |
Can you provide the Java Recursion Example 2: Finite times? | public class RecursionExample2 {
static int count=0;
static void p(){
count++;
if(count<=5){
System.out.println("hello "+count);
p();
}
}
public static void main(String[] args) {
p();
}
}
Output:
hello 1
hello 2
hello 3
hello 4
hello 5 |
Can you provide the Java Recursion Example 3: Factorial Number? | public class RecursionExample3 {
static int factorial(int n){
if (n == 1)
return 1;
else
return(n * factorial(n-1));
}
public static void main(String[] args) {
System.out.println("Factorial of 5 is: "+factorial(5)); ... |
Can you provide the Java Recursion Example 4: Fibonacci Series? | public class RecursionExample4 {
static int n1=0,n2=1,n3=0;
static void printFibo(int count){
if(count>0){
n3 = n1 + n2;
n1 = n2;
n2 = n3;
System.out.print(" "+n3);
printFibo(count-1); ... |
What is Call by Value and Call by Reference in Java? | There is only call by value in java, not call by reference. If we call a method passing a value, it is known as call by value. The changes being done in the called method, is not affected in the calling method. |
Can you provide an Example of call by value in java? | class Operation{
int data=50;
void change(int data){
data=data+100;//changes will be in the local variable only
}
public static void main(String args[]){
Operation op=new Operation();
System.out.println("before change "+op.data);
op.change(500);
System.out.prin... |
What is Java Strictfp Keyword? | Java strictfp keyword ensures that you will get the same result on every platform if you perform operations in the floating-point variable. The precision may differ from platform to platform that is why java programming language have provided the strictfp keyword, so that you get same result on every platform. So, now ... |
What is Legal code for strictfp keyword? | The strictfp keyword can be applied on methods, classes and interfaces.
strictfp class A{}//strictfp applied on class
strictfp interface M{}//strictfp applied on interface
class A{
strictfp void m(){}//strictfp applied on method
} |
What is Illegal code for strictfp keyword? | The strictfp keyword cannot be applied on abstract methods, variables or constructors.
class B{
strictfp abstract void m();//Illegal combination of modifiers
}
class B{
strictfp int data=10;//modifier strictfp not allowed here
}
class B{
strictfp B(){}//modifier strictfp not allowed here
} |
What is Creating API Document | javadoc tool? | We can create document api in java by the help of javadoc tool. In the java file, we must use the documentation comment /**... */ to post information for the class, method, constructor, fields etc.
Let's see the simple class that contains documentation comment.
package com.abc;
/** This class is a user-defined cl... |
What is Java Command Line Arguments? | The java command-line argument is an argument i.e. passed at the time of running the java program.
The arguments passed from the console can be received in the java program and it can be used as an input.
So, it provides a convenient way to check the behavior of the program for the different values. You can pass ... |
Can you provide Simple example of command-line argument in java? | In this example, we are receiving only one argument and printing it. To run this java program, you must pass at least one argument from the command prompt.
class CommandLineExample{
public static void main(String args[]){
System.out.println("Your first argument is: "+args[0]);
}
}
compile by > javac Com... |
Can you provide an Example of command-line argument that prints all the values? | In this example, we are printing all the arguments passed from the command-line. For this purpose, we have traversed the array using for loop.
class A{
public static void main(String args[]){
for(int i=0;i<args.length;i++)
System.out.println(args[i]);
}
}
compile by > javac A.java
run by >... |
What are the Difference between object and class? | There are many differences between object and class. A list of differences between object and class are given below:
1) Object is an instance of a class while Class is a blueprint or template from which objects are created
2) Object is a real world entity such as pen, laptop, mobile, bed, keyboard, mouse, chair et... |
Can you provide Java Method Overloading example? | class OverloadingExample{
static int add(int a,int b){return a+b;}
static int add(int a,int b,int c){return a+b+c;}
} |
Can you provide Java Method Overriding example? | class Animal{
void eat(){System.out.println("eating...");}
}
class Dog extends Animal{
void eat(){System.out.println("eating bread...");}
} |
What is Java String? | n Java, string is basically an object that represents sequence of char values. An array of characters works same as Java string. For example:
char[] ch={'j','a','v','a','t','p','o','i','n','t'};
String s=new String(ch);
is same as:
String s="javatpoint";
Java String class provides a lot of methods to per... |
CharSequence Interface | The CharSequence interface is used to represent the sequence of characters. String, StringBuffer and StringBuilder classes implement it. It means, we can create strings in Java by using these three classes.
The Java String is immutable which means it cannot be changed. Whenever we change any string, a new instance is c... |
What is String in Java? | Generally, String is a sequence of characters. But in Java, string is an object that represents a sequence of characters. The java.lang.String class is used to create a string object. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.