☕️JAVA Language Community
2.91K subscribers
144 photos
7 videos
31 files
42 links
☕️ Software, IT, Java, news
💻 IT highlights
🎯 AI update
🖥⌨️🖱
Download Telegram
#Java_Interview_Question

More Details:

👉Usage of java this keyword

Here is given the 6 usage of java this keyword.

1️⃣this can be used to refer current class instance variable

2️⃣this can be used to invoke current class method (implicitly)

3️⃣this() can be used to invoke current class constructor.

4️⃣this can be passed as an argument in the method call.

5️⃣this can be passed as argument in the constructor call.

6️⃣this can be used to return the current class instance from the method.

▪️Suggestion: If you are beginner to java, lookup only three usage of this keyword.

@javaCode☕️
#Design_Patterns

#Builder_Design_Pattern

👉Discussion

Separate the algorithm for interpreting (i.e. reading and parsing) a stored persistence mechanism (e.g. RTF files) from the algorithm for building and representing one of many target products (e.g. ASCII, TeX, text widget). The focus/distinction is on creating complex aggregates.

The "director" invokes "builder" services as it interprets the external format. The "builder" creates part of the complex object each time it is called and maintains all intermediate state. When the product is finished, the client retrieves the result from the "builder".

Affords finer control over the construction process. Unlike creational patterns that construct products in one shot, the Builder pattern constructs the product step by step under the control of the "director".

@javaCode☕️
#Java_Interview_Question

28)What is Inheritance?

Inheritance is a mechanism in which one object acquires all the properties and behaviour of another object of another class. It represents IS-A relationship. It is used for Code Resusability and Method Overriding.

@javaCode☕️
👍1
#Java_Interview_Question

More Details:
👉Inheritance in Java

▪️Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object.

▪️The idea behind inheritance in java is that you can create new classes that are built upon existing classes.

▪️When you inherit from an existing class, you can reuse methods and fields of parent class, and you can add new methods and fields also.

▪️Inheritance represents the IS-A relationship, also known as parent-child relationship.

👉Why use inheritance in java

▪️For Method Overriding (so runtime polymorphism can be achieved).

▪️For Code Reusability.

@javaCode☕️
👍1
#Java_Interview_Question

29) Which class is the superclass for every class.

Object class.

@javaCode☕️
#Java_Interview_Question

30) Why multiple inheritance is not supported in java?

To reduce the complexity and simplify the language, multiple inheritance is not supported in java in case of class.

@javaCode☕️
#Java_Interview_Question

31) What is composition?

Holding the reference of the other class within some other class is known as composition.

@javaCode☕️
#Java_Interview_Question

32) What is difference between aggregation and composition?

Aggregation represents weak relationship whereas composition represents strong relationship. For example: bike has an indicator (aggregation) but bike has an engine (compostion).

@javaCode☕️
#Design_Patterns
#Builder_Design_Pattern

👉Structure

The Reader encapsulates the parsing of the common input. The Builder hierarchy makes possible the polymorphic creation of many peculiar representations or targets.

@javaCode☕️
#Java_Interview_Question

33) Why Java does not support pointers?

Pointer is a variable that refers to the memory address. They are not used in java because they are unsafe(unsecured) and complex to understand.

@javaCode☕️
#Java_Interview_Question

34) What is super in java?

It is a keyword that refers to the immediate parent class object.

@javaCode☕️
☕️JAVA Language Community
#Java_Interview_Question 34) What is super in java? It is a keyword that refers to the immediate parent class object. @javaCode☕️
▪️More details:

👉super keyword in java

The super keyword in java is a reference variable which is used to refer immediate parent class object.

Whenever you create the instance of subclass, an instance of parent class is created implicitly which is referred by super reference variable.

👉Usage of java super Keyword

1️⃣super can be used to refer immediate parent class instance variable.

2️⃣super can be used to invoke immediate parent class method.

3️⃣super() can be used to invoke immediate parent class constructor.

@javaCode☕️
#Design_Patterns

#Builder_Design_Pattern

👉Example

The Builder pattern separates the construction of a complex object from its representation so that the same construction process can create different representations. This pattern is used by fast food restaurants to construct children's meals. Children's meals typically consist of a main item, a side item, a drink, and a toy (e.g., a hamburger, fries, Coke, and toy dinosaur). Note that there can be variation in the content of the children's meal, but the construction process is the same. Whether a customer orders a hamburger, cheeseburger, or chicken, the process is the same. The employee at the counter directs the crew to assemble a main item, side item, and toy. These items are then placed in a bag. The drink is placed in a cup and remains outside of the bag. This same process is used at competing restaurants.

@javaCode☕️
This media is not supported in your browser
VIEW IN TELEGRAM
#Java_Interview_Question

35) Can you use this() and super() both in a constructor?

No. Because super() or this() must be the first statement.

@javaCode☕️
#Java_Interview_Question

36)What is object cloning?

The object cloning is used to create the exact copy of an object.

@javaCode☕️
#Java_Interview_Question

More Details:

👉Object Cloning in Java

▪️The object cloning is a way to create exact copy of an object. For this purpose, 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 CloneNotSupportedException.

The clone() method is defined in the Object class. Syntax of the clone() method is as follows:

✏️protected Object clone() throws CloneNotSupportedException

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 to be performed that is why we use object cloning.

❗️Advantage of Object cloning

Less processing task.

@javaCode☕️
☕️JAVA Language Community
Photo
🔴C++ vs Java

There are many differences and similarities between C++ programming language and Java. A list of top differences between C++ and Java are given below:

▪️Platform-independent
C++ is platform-dependent.
Java is platform-independent.

▪️Mainly used for
C++ is mainly used for system programming.
Java is mainly used for application programming. It is widely used in window, web-based, enterprise and mobile applications.

▪️Goto
C++ supports goto statement.
Java doesn't support goto statement.

▪️Multiple inheritance
C++ supports multiple inheritance.
Java doesn't support multiple inheritance through class. It can be achieved by interfaces in java.

▪️Operator Overloading
C++ supports operator overloading.
Java doesn't support operator overloading.

▪️Pointers
C++ supports pointers. You can write pointer program in C++. Java supports pointer internally. But you can't write the pointer program in java. It means java has restricted pointer support in java.

▪️Compiler and Interpreter
C++ uses compiler only.
Java uses compiler and interpreter both.

▪️Call by Value and Call by reference
C++ supports both call by value and call by reference.
Java supports call by value only. There is no call by reference in java.

▪️Structure and Union
C++ supports structures and unions.
Java doesn't support structures and unions.

▪️Thread Support
C++ doesn't have built-in support for threads. It relies on third-party libraries for thread support. Java has built-in thread support.

▪️Documentation comment
C++ doesn't support documentation comment.
Java supports documentation comment (/** ... */) to create documentation for java source code.

▪️Virtual Keyword
C++ supports virtual keyword so that we can decide whether or not override a function.
Java has no virtual keyword. We can override all non-static methods by default. In other words, non-static methods are virtual by default.

▪️unsigned right shift >>>
C++ doesn't support >>> operator.
Java supports unsigned right shift >>> operator that fills zero at the top for the negative numbers. For positive numbers, it works same like >> operator.

▪️Inheritance Tree
C++ creates a new inheritance tree always.
Java uses single inheritance tree always because all classes are the child of Object class in java. Object class is the root of inheritance tree in java.

@javaCode☕️