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 {
...
}
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
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.
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.
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 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.
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.
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.
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.
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 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.
Given an int array length 2 return true if it contains a 2 or a 3.?
public boolean has2or3(int[] nums) {
if ( nums[0] 3 )
return true;
return false;
}
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
How do you create an object for anonymous class?
public class Class1 {
protected InnerClass1 ic;
public Class1() {
ic = new InnerClass1();
}
public void displayStrings() {
System.out.println(ic.getString() + ".");
System.out.println(ic.getAnotherString() + ".");
}
static public void main(String[] args) {
Class1 c1 = new Class1();
c1.displayStrings();
}
protected class InnerClass1 {
public String getString() {
return "InnerClass1: getString invoked";
}
public String getAnotherString() {
return "InnerClass1: getAnotherString invoked";
}
}
}
we can do like . crieate inner class instanve in side of main class defalut consiter . use the object we do the our bz logic
WAP to initilize a character and print whether it is a vowel or not?
// short version
char c = 'a';
System.out.println((c=='a'c=='e'c=='i'c=='o'c=='u')?"VOWEL":"CONSONANT");
// easy to read version
char c = 'a';
switch (c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("VOWEL");
break;
default:
System.out.println("CONSONANT");
}
What is the difference between classes and objects?
Class
Defines the abstract characteristics of a thing (object), including the thing's characteristics (its attributes, fields or properties) and the thing's behaviors (the things it can do, or methods, operations or features). One might say that a class is a blueprint or factory that describes the nature of something. For example, the class Dog would consist of traits shared by all dogs, such as breed and fur color (characteristics), and the ability to bark and sit (behaviors). Classes provide modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, meaning that the characteristics of the class should make sense in context. Also, the code for a class should be relatively self-contained (generally using encapsulation). Collectively, the properties and methods defined by a class are called members.
Object
A pattern (exemplar) of a class. The class of Dog defines all possible dogs by listing the characteristics and behaviors they can have; the object Lassie is one particular dog, with particular versions of the characteristics. A Dog has fur; Lassie has brown-and-white fur.
A class is the type definition of an object. An object is an actual instance of a class type.