core java interview questions
// Java program to Reverse a String by
// converting string to characters one
// by one
import java.lang.*;
import java.io.*;
import java.util.*;
// Class of ReverseString
class ReverseString
{
public static void main(String[] args)
{
String input = "java";
// convert String to character array
// by using toCharArray
char[] try1 = input.toCharArray();
for (int i = try1.length-1; i>=0; i--)
System.out.print(try1[i]);
}
}
Output: avaj for more questions visit👉👉👉👉👉👉👉👉👉👉👉👉👉 https://cjavapoint.blogspot.com/
// Java program to Reverse a String by
// converting string to characters one
// by one
import java.lang.*;
import java.io.*;
import java.util.*;
// Class of ReverseString
class ReverseString
{
public static void main(String[] args)
{
String input = "java";
// convert String to character array
// by using toCharArray
char[] try1 = input.toCharArray();
for (int i = try1.length-1; i>=0; i--)
System.out.print(try1[i]);
}
}
Output: avaj for more questions visit👉👉👉👉👉👉👉👉👉👉👉👉👉 https://cjavapoint.blogspot.com/
HAS-A Relationship
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.
Example:-
class Engine
{
// engine functionality
}
class Car
{
Engine e=new Engine();
//------------------------------;
//------------------------------;
//------------------------------;
}
NOTE:-
class car has-a engine reference.
The main dis-advantage of has-a relationship increases dependency between the
components and creates maintains problems. 👌👌👌👌👌👌 More java interview Questions Visit: -https://cjavapoint.blogspot.com/👈👈👈👈👈
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.
Example:-
class Engine
{
// engine functionality
}
class Car
{
Engine e=new Engine();
//------------------------------;
//------------------------------;
//------------------------------;
}
NOTE:-
class car has-a engine reference.
The main dis-advantage of has-a relationship increases dependency between the
components and creates maintains problems. 👌👌👌👌👌👌 More java interview Questions Visit: -https://cjavapoint.blogspot.com/👈👈👈👈👈
Core Java Inetrview Questions java Opps Concept What is method overloading in OOP or Java? (answer)
It's one of the oldest OOPS concept questions, I have seen it 10 years ago and still sees it now. When we have multiple methods with the same name but different functionality then it's called method overloading. For example. System.out.println() is overloaded as we have 6 or 7 println() method each accepting a different type of parameter.
What is method overriding in OOP or Java? (answer)
It's one of the magic of object oriented programming where the method is chose based upon an object at runtime. In order for method overriding, we need Inheritance and Polymorphism, as we need a method with the same signature in both superclass and subclass. A call to such method is resolved at runtime depending upon the actual object and not the type o variable. See the answer for more detailed discussion. more Questions Visit https://cjavapoint.blogspot.com/👌👌👌👈👈👈👈
It's one of the oldest OOPS concept questions, I have seen it 10 years ago and still sees it now. When we have multiple methods with the same name but different functionality then it's called method overloading. For example. System.out.println() is overloaded as we have 6 or 7 println() method each accepting a different type of parameter.
What is method overriding in OOP or Java? (answer)
It's one of the magic of object oriented programming where the method is chose based upon an object at runtime. In order for method overriding, we need Inheritance and Polymorphism, as we need a method with the same signature in both superclass and subclass. A call to such method is resolved at runtime depending upon the actual object and not the type o variable. See the answer for more detailed discussion. more Questions Visit https://cjavapoint.blogspot.com/👌👌👌👈👈👈👈
👍1
HAS-A relationship in Java - Learn java
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.
Example:-
class Engine
{
// engine functionality
}
class Car
{
Engine e=new Engine();
//------------------------------;
//------------------------------;
//------------------------------;
}
NOTE:-
class car has-a engine reference.
The main dis-advantage of has-a relationship increases dependency between the
components and creates maintains problems.
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.
Example:-
class Engine
{
// engine functionality
}
class Car
{
Engine e=new Engine();
//------------------------------;
//------------------------------;
//------------------------------;
}
NOTE:-
class car has-a engine reference.
The main dis-advantage of has-a relationship increases dependency between the
components and creates maintains problems.
👍1
mpre java interview Questions visit https://cjavapoint.blogspot.com/
What is method overloading?
Method overloading is a programming technique that allows developers to use the same method name multiple times in the same class, but with different parameters. In this case, we say that the method is overloaded. Listing 1 shows a single method whose parameters differ in number, type, and order.
Listing 1. Three types of method overloading
Number of parameters:
public class Calculator {
void calculate(int number1, int number2) { }
void calculate(int number1, int number2, int number3) { }
}
Type of parameters:
public class Calculator {
void calculate(int number1, int number2) { }
void calculate(double number1, double number2) { }
}
Order of parameters:
public class Calculator {
void calculate(double number1, int number2) { }
void calculate(int number1, double number2) { }
} more java interview Questions visit https://cjavapoint.blogspot.com/ join my me on https://t.me/javaQuestions4u 👌👌👌👌👍👍👍👍
Method overloading is a programming technique that allows developers to use the same method name multiple times in the same class, but with different parameters. In this case, we say that the method is overloaded. Listing 1 shows a single method whose parameters differ in number, type, and order.
Listing 1. Three types of method overloading
Number of parameters:
public class Calculator {
void calculate(int number1, int number2) { }
void calculate(int number1, int number2, int number3) { }
}
Type of parameters:
public class Calculator {
void calculate(int number1, int number2) { }
void calculate(double number1, double number2) { }
}
Order of parameters:
public class Calculator {
void calculate(double number1, int number2) { }
void calculate(int number1, double number2) { }
} more java interview Questions visit https://cjavapoint.blogspot.com/ join my me on https://t.me/javaQuestions4u 👌👌👌👌👍👍👍👍
❤1
Core Java Interview Question Visit 👉👉👉👉👉👉👉https://cjavapoint.blogspot.com/2019/12/composition.html
Encapsulation in Java - Learn Java Interview Questions https://cjavapoint.blogspot.com/2019/09/encapsulation.html👍👍👍👍👍
core java has-A relationship interview questions https://cjavapoint.blogspot.com/2019/12/has-relationship.html
Strings in Java
Strings in Java are Objects that are backed internally by a char array. Since arrays are immutable(cannot grow), Strings are immutable as well. Whenever a change to a String is made, an entirely new String is created.
Below is the basic syntax for declaring a string in Java programming language.
Syntax: String str = "learnJava";
More java Interview Questions Visit:- https://cjavapoint.blogspot.com/ 👌👌👌👌👌👌
Strings in Java are Objects that are backed internally by a char array. Since arrays are immutable(cannot grow), Strings are immutable as well. Whenever a change to a String is made, an entirely new String is created.
Below is the basic syntax for declaring a string in Java programming language.
Syntax: String str = "learnJava";
More java Interview Questions Visit:- https://cjavapoint.blogspot.com/ 👌👌👌👌👌👌
Without existing container object if there is a chance of existing contained objects
such type of relationship is called aggregation .
in aggregation objects have weak association. https://cjavapoint.blogspot.com/2019/12/aggregation.html👈👈👈👌👌👌
such type of relationship is called aggregation .
in aggregation objects have weak association. https://cjavapoint.blogspot.com/2019/12/aggregation.html👈👈👈👌👌👌
Within a department there may be a chance of several professors will work whenever
we are closing department still there may be a chance of existing department object the
relationship between department and professor is called aggregation where the objects
having weak association.
https://cjavapoint.blogspot.com/2019/12/aggregation.html👈👈👈👌👌👌👌
we are closing department still there may be a chance of existing department object the
relationship between department and professor is called aggregation where the objects
having weak association.
https://cjavapoint.blogspot.com/2019/12/aggregation.html👈👈👈👌👌👌👌
What are the various access specifiers in Java? In Java, access specifiers are the keywords which are used to define the access scope of the method, class, or a variable. In Java, there are four access specifiers given below.
Public The classes, methods, or variables which are defined as public, can be accessed by any class or method.
Protected Protected can be accessed by the class of the same package, or by the sub-class of this class, or within the same class.
Default Default are accessible within the package only. By default, all the classes, methods, and variables are of default scope.
Private The private class, methods, or variables defined as private can be accessed within the class only. For More Questions Visit :- 👉👉👉👉👉 https://cjavapoint.blogspot.com/
Public The classes, methods, or variables which are defined as public, can be accessed by any class or method.
Protected Protected can be accessed by the class of the same package, or by the sub-class of this class, or within the same class.
Default Default are accessible within the package only. By default, all the classes, methods, and variables are of default scope.
Private The private class, methods, or variables defined as private can be accessed within the class only. For More Questions Visit :- 👉👉👉👉👉 https://cjavapoint.blogspot.com/
What are the restrictions that are applied to the Java static methods? Two main restrictions are applied to the static methods.
1. The static method can not use non-static data member or call the non-static method directly.
2. this and super cannot be used in static context as they are non-static. For More Questions Visit :- 👉👉 https://cjavapoint.blogspot.com/
1. The static method can not use non-static data member or call the non-static method directly.
2. this and super cannot be used in static context as they are non-static. For More Questions Visit :- 👉👉 https://cjavapoint.blogspot.com/
👍1
Can we make constructors static? As we know that the static context (method, block, or variable) belongs to the class, not the object. Since Constructors are invoked only when the object is created, there is no sense to make the constructors static. However, if you try to do so, the compiler will show the compiler error.
For More Questions Visit :- https://cjavapoint.blogspot.com/ 👈👈👈👈
For More Questions Visit :- https://cjavapoint.blogspot.com/ 👈👈👈👈
What is this keyword in java? The this keyword is a reference variable that refers to the current object. There are the various uses of this keyword in Java. It can be used to refer to current class properties such as instance methods, variable, constructors, etc. It can also be passed as an argument into the methods or constructors. It can also be returned from the method as the current class instance. For More Questions Visit :- https://cjavapoint.blogspot.com/