answersLogoWhite

0

📱

Java Programming

The Java programming language was released in 1995 as a core component of the Java platform of Sun Microsystems. It is a general-purpose, class-based, object-oriented language that is widely used in application software and web applications.

5,203 Questions

What is a canonical view for object oriented analysis and design?

canonical view

Common parlance loosely defines canonical views as the "front", "side", and "top" views of an object.

http://www.bmva.ac.uk/bmvc/2005/papers/264/paper.pdf

The term "canonical views" was first used by Palmer, Rosch, and Chase (1981). For more information on their experiements see:

http://www.kyb.tuebingen.mpg.de/publications/pdfs/pdf1507.pdf (its worth reading the section about the experiments to get a fuller understanding of their meaning) Given these facts, my best guess is that "canonical view" in the context of OOAD is what the application "looks like" from various points of view... UI, application layers and so on.

Is it ever necessary to add extends Object to a class declaration?

No; that is the default. In other words, if you don't add "extends", the class will automatically inherit from the "Object" class.

No; that is the default. In other words, if you don't add "extends", the class will automatically inherit from the "Object" class.

No; that is the default. In other words, if you don't add "extends", the class will automatically inherit from the "Object" class.

No; that is the default. In other words, if you don't add "extends", the class will automatically inherit from the "Object" class.

What is classes in java?

class is a blueprint which does not have its own existence but it can pass all of its feature to its child classes.

Does exception always signal an error?

It depends on exactly how you define an error. If an exception is thrown, then it means something has gone wrong.

Some Exceptions, such as a NullPointerException, will almost certainly signal an error in your code or data. Others, such as IOExceptions, can be caused by things outside your control, and would probably not be considered errors.

Does the pseudo random noise and the pseudo random signal the same?

both are same as both will repeat after some period distinguishing it from random noise/signal which will never repeat

What Difference between exception and assertion?

Exception means not included in general sense. Any subject an ve connotaion in general with few exeption. Assertion means asserting one's authority

What is virtual inheritance?

Virtual inheritance is used in multiple inheritance hierarchies whenever two or more classes inherit from the same base class. For example, consider the following minimal example:

struct A {int x;};

struct B : A {};

struct C : A {};

struct D : B, C {};

Here, A is a common base class of both B and C, thus B::A and C::A are independent instances of A. However, D inherits from both B and C thus indirectly inherits both B::A and C::A. This introduces an ambiguity when implicitly referring to A from D, as in the following example:

D d; d.x = 42; // error: ambiguous

When the compiler sees this it won't know whether we are referring to B::A.x or C::A.x, thus we must be explicit when referring to A via D:

d.B::x = 42; // ok

The problem with this is that we still have two separate instances of x so unless we are extremely careful about which x we are referring to we can easily end up with two different values for x with no way of knowing which was the correct value with respect to D.

What we really need is for B and C to share the same instance of A and we achieve that through virtual inheritance:

struct A {int x;};

struct B : virtual A {};

struct C : virtual A {};

struct D : B, C {};

D d;

d.x = 42; // ok

Note that d.x can be referred to as d::A.x, d::B::A.x or d::C::A.x because they all refer to the same instance of x, thus the ambiguity is eliminated. In effect, the most-derived class in the hierarchy (D) is now a direct descendant of A rather than an indirect descendant of both B::A and C::A.

Note also that the virtual keyword has no effect on independent instances of either B or C because they then become the most-derived classes within their own hierarchy and therefore behave exactly as they would had the virtual keyword been omitted. The virtual keyword only comes into play when we derive from a class with a virtual base.

It is also possible to have a base class that is both virtual and non-virtual in the same hierarchy:

struct A {int x;};

struct B : virtual A {};

struct C : virtual A {};

struct D: A {}

struct E : B, C, D {};

Here, A is a virtual base of both B and C, as before, but not of D. Thus E::A implicitly refers to the virtual A while E::D::A must be explicitly referred to as E::D::A because it is a separate instance. Such classes are best avoided, but if we don't have access to the source code we sometimes don't have a choice in the matter.

However, if a base class holds no data it really doesn't matter whether it is declared virtual or not because a class that has no data consumes just one byte regardless of how many instances there are.

Write a algorithm to print even number in C programming language?

#include<stdio.h>

#include<conio.h>

void main()

{

int n;

clrscr();

printf("\n enter the number:");

scanf("%d",&n);

if(n%2==0)

printf("\n the number is even");

getch();

}

How to link to external url in javadoc?

Here's an example:

@see <a href="http://www.google.com">Google</a>

Describe the JAVA throwable class hierarchy and types of exceptions?

In Java there are two main types of Exceptions.

* Checked Exceptions - The ones that can be checked & handled in our code. Ex: I/O Exception, SQL Exception etc. In most cases, the compiler itself forces us to catch & handle these exceptions

* Un-checked Exceptions - The ones that we cannot & should not handle in our code. Ex. Null Pointer Exception

The java.lang.Throwable is the super class of all errors and exceptions in Java. Only objects of this class can be thrown & caught and handled by try-catch blocks.

Ex:

try {

.....

.....

} catch (Exception e){

...

} finally {

...

}

How can you search an array element in a file?

Logic to search element in array

Input size and elements in array from user. ...

Input number to search from user in some variable say toSearch .

Define a flag variable as found = 0 . ...

Run loop from 0 to size . ...

Inside loop check if current array element is equal to searched number or not.

To learn more about data science please visit- Learnbay.co

Explain the usage of JPanel with example?

JPanel, a part of Java Swing package, is a container that can store a group of components. The main task of JPanel is to organize components, various layouts can be set in JPanel which provide better organization of components, and however it does not have a title bar.

For Example:

Program to create a JPanel with a Border layout and add components to it .

// java Program to create a JPanel with a Border layout and add components to it . import java.awt.event.; import java.awt.; import javax.swing.*; class solution extends JFrame { // JFrame static JFrame f; // JButton static JButton b, b1, b2, b3; // label to diaplay text static JLabel l; // main class public static void main(String[] args) { // create a new frame to stor text field and button f = new JFrame("panel"); // create a label to display text l = new JLabel("panel label"); // create a new buttons b = new JButton("button1"); b1 = new JButton("button2"); b2 = new JButton("button3"); b3 = new JButton("button4"); // create a panel to add buttons and a specific layout JPanel p = new JPanel(new BorderLayout()); // add buttons and textfield to panel p.add(b, BorderLayout.NORTH); p.add(b1, BorderLayout.SOUTH); p.add(b2, BorderLayout.EAST); p.add(b3, BorderLayout.WEST); p.add(l, BorderLayout.CENTER); // setbackground of panel p.setBackground(Color.red); // add panel to frame f.add(p); // set the size of frame f.setSize(300, 300); f.show(); } }

What variables of a class are created when the class is loaded and continues to exist as long as the class is loaded?

Static Variables are created when the class is loaded and continue to exist as long as the class is loaded/present in the JVM

What is progeraming language?

A Language (ie.Java) That Deals with every command in a program

What is difference between for loop and do-while loop?

The do loop is similar to the forloop, except that the expression is not evaluated until after the do loop's code is executed. Therefore the code in a do loop is guaranteed to execute at least once. The following shows a do loop in action:

do {

System.out.println("Inside do while loop");

} while(false);

The System.out.println() statement will print once, even though the expression evaluates to false. Remember, the do loop will always run the code in the loop body at least once. Be sure to note the use of the semicolon at the end of the while expression.

How can access an interface from another interface and how to access from a class?

Interfaces are designed to do exactly that: to interface or to interact. In object-oriented programming languages such as C++, you can incorporate up to three different interfaces per class. The private interface is accessible only to the class itself and to friends of the class. The protected interface is the same as the private interface but is also accessible to derivatives of the class. The public interface is accessible to any code.

For one interface to interact with another interface, the first must have access to the second. If the first is a friend of the second or both are members of the same class, the first has unrestricted access to the private, protected and public interfaces of the second. If the first is derived from the second but is not a friend, the first only has access to the protected and public interfaces of the second. If the first is completely separate from the second, the first only has access to the public interfaces of the second.

What is the J2EE Value Object Pattern?

The Value Object pattern provides the best way to exchange data across tiers or system boundaries, especially when there is network communication involved. This is a pattern that solves performance issues around network latency

This pattern is an object that encapsulates a set of values that is moved across the boundary so that attempts to get the values of those attributes are local calls.

Insert an element after an element in an array?

  1. To begin, obtain the element to be added, such as x

  2. Then, say pos, get the position where this element will be put.

  3. Then shift the array items one position ahead, then do the same for all the other elements next to pos.

  4. Because the location pos is now empty, insert the element x there.

To learn more about data science please visit- Learnbay.co

What are attributes and methods in class?

Attributes are the class member variables, the data, fields or other properties that define the class state. Methods are the functions of a class, the operations that define its behaviour, typically working in conjunction with the class member attributes to either alter the class state (mutators) or query the class state (accessors). Special methods such as the class constructors, its destructor and conversion operators are invoked indirectly through compiler-generated code while all others are called directly via programmer-generated code.