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

In Java what operator is used to determine if an object is of a particular class type?

The instanceof keyword is used to determine if an object is of a particular class type.

Example:

Object obj = new String();

if(obj instanceof String) {

System.out.println("obj is a String!");

}

Does separation of interface from implementation within classes provide advantage?

Yes, it helps both the users and the maintainers of your class. Users are generally only interested the class interface (how to interact with the class), so by separating the implementation you do not distract the user with any unnecessary implementation details. Conversely, maintainers are more concerned with the implementation than the interface. By keeping the two separate, maintainers are much less likely to break any code that uses the class.

Java code to print prime numbers from 1 to 100?

import java.io.*;

class prmNo

{

public static void main(String[] args)

{

Console con = System.console();

System.out.println("Enter length of list :");

int n = con.readLine();

boolean flag;

System.out.print("1 ");

for (int i=2;i<=n;i++)

{

for (int j=2;j<i;j++)

{

if (i%j==0)

flag=true;

}

if(!flag)

System.out.print(i+ " ");

flag=false;

}

}

}

You cannot throw an exception from a destructor?

Sure you can, but it's never a good idea. You must never allow an exception to escape from a destructor. To do so would terminate the destructor prematurely, unwinding the call stack in search of an exception handler. This means that any remaining resources consumed by the instance, including its base classes, would be left in an invalid state with no possible way to recover those resources besides terminating the program. Any object that has the potential to throw an exception during its own destruction should always be treated with suspicion; it is a major design flaw.

What is a sum?

The result of addition.
The answer of all your numbers added up.

If then else statements and case statements essentially perform the same function when would you use one over the other?

I would recommend an If - then - else statement over a switch statement because:

1. It is simpler/easier

2. You do not get unexpected output because of missing break statements

A missed break statement in one of the conditions in a switch case statement means that all the conditions that come after the success condition are executed. In case of if else this is not the case and hence it is much safer for novice programmers.

> essentially perform the same function

No, they don't. Here is an example to prove this:

if (sin (alpha) > cos (alpha)) {

...

} else if (alpha / M_PI * 180 > 180) {

...

} else {

...

}

If the length of a piece of string... is any length of string cut from a spool... 'what is the maximum length of a piece of a piece of string' or 'how much string is on a spool'?

100 metres seems to be the length of a spool of gardeners cotton Discuss:How_long_is_a_piece_of_string...we are not talking about jute twine here!So the maximum length of a piece of string would be 999.99mm!So the real answer to 'how long is a piece of string?' would be...anything between 0.01mm to 999.99mm.

What are the steps to add a menu to a frame in advance java?

step 1:

create menubar object and set it

step 2:

create menu objects with parameterized constructor

step 3:

add menus to menubar

How many bytes in an address of an int variable?

32 bits or 4 bytes and an int is not an address, it is a primitive so it directly access the data without a reference.

What are the two types of variables?

The two types of variables are the CONSTANT and CONTROL.

What programming languages are used in programming an EEPROM?

In one sense, since EEPROM is memory, you don't program memory. You store things in memory, and the thing you are programming in this case would likely be a micro-processor or micro-controller that is on the same circuit as the EEPROM.

In theory, an EEPROM is just memory, so any language that would be able to produce machine language output for the CPU type connected to the EEPROM in any instance could be used.

In practice, many programs written to EEPROM would be for embedded systems. In this case, a lower level language like C could be used, or a higher level language that output C or the right kind of assembly.

A higher level language like C# or Java would likely not be used, as the overhead of the virtual machine might be considered to be too heavy for a micro-controller, or small micro-processor.

That being said, in practice, you could use anything. But it is likely you would have some libraries in C or C++ that you might want to use, so you would likely use a language that was compatible with any libraries you might use.

yah it's correct.

Why does it say java.io.ioException Connection reset by peer when I try to connect to minecraft central at mc-central.net?

The error "Connection reset by peer" is a TCP error that occurs when a server sends your application a RST (i.e. reset) packet which terminates the TCP connection between you and the server.

You can retry manually and maybe the server will not reset you, but if you keep getting this there is not much you can do. It is the equivalent of slamming the phone back on the hook abruptly instead of politely saying goodby and gently hanging up.

Which comma is used for characters in switch case statements?

There is only one comma, but it is not used in switch-case. Character literals are between apostrophes: 'x'

What is the difference between Java bean and bean?

JAVA beans and coffee beans are two very different things . JAVA beans are used to generate getters and setters. while coffee beans are use to make coffee.

Why is cyclic inheritance not in any programming language?

Cyclic inheritance is physically impossible. A base class cannot inherit from one of its own derivatives any more than you could inherit some generic trait from one of your own descendants. Inheritance is strictly a one-way street.

How should you design a scientific calculator using C plus plus?

The easiest way to implement a calculator is an RPN calculator (enter the numbers first, perform the operation last). You need a last-in-first-out stack (there's a "stack" class in C++, but you can also implement your own using an array or a linked list), and a set of functions that pop the last elements from the stack and push the result (e.g. Add() pops the last 2 values and pushes their addition).
You'll need the math.h library for scientific operations.

How do you remove a column from JTable?

ColumnModel columnModel = table.getColumnModel();

for(Column: columnModel.getColumns()) {

Column column = <FIND COLUMN YOU NEED>;

}

columnModel.removeColumn(column);

Is it necessary to read or display the elements of an array in order of its subscripts?

By no means; you can access any random array element. If you have ever seen examples which process them in order, it is because of the following: when the order doesn't matter (for example, you want to calculate the sum of all the array elements), it is easiest to process them in order.

What translates a Java program into Bytecode?

The Java Runtime Environment (JRE) converts the byte code to machine language.

What is the purpose of the black code?

the main purpose of the legislation was to stabilize the black workforce by compelling African Americans to work and by limiting their economic options … The laws aimed to replace the social controls of slavery, which had been legally swept away by the Emancipation Proclamation and the Thirteenth Amendment, and to reinstate the substance of the slave system without the legal form.

Can a derived class call the static constructor of a base class in .Net?

No. not directly.

The static constructor is called by .net framework, not by your code.

I always treat static constructor is the class initializer (not the instance one). The initialization routine is only called when the class definition being loaded.

When the derived class is loaded, since this class derived from the base, it makes to go up the chain (of the hierarchy) to call those static constuctors.

So, when a derived class is loaded, the static constructors of the hierarchy is called up. (any one of them had been loaded, the calling sequence stops).

You cannot call those static constructor directly, nor you can skip "not to execute" them.

Can a method be declared in any order in a class?

Yes. There is no specific order in which the compiler expects methods to be present. As long as the method is inside the class it is perfectly fine.

Can you compare NaN values?

Yes using the equals method.

Example:

Double a = new Double(Double.NaN);

Double b = new Double(Double.NaN);

if( a.equals(b) )

System.out.println("True");

else

System.out.println("False");

If you execute the above code snippet you will see "True" in the console. If you try the "==" operator to compare the 2 values a and b you will get only false