What is it called when java allows you to declare methods with the same name in a class?
Yes perfectly Legal
Reason:
The scope of a variable declared inside a method is only till the method's end. So by defining another variable of the same name inside a different method does not create any issues.
Why do you need runnable interface?
A Runnable Interface is one that is used to create a Java Thread...
A Thread can be created in two ways and using the Runnable Interface is one of them.
Example:
public class Test implements Runnable {
public void run(){
....
}
}
The Runnable interface would have an abstract instance of the method run() which needs to be implemented in the class which wants to create a Thread.
What is the difference between a constant and a variable in java programming language?
A constant in Java is defined using the "final" modifier. For instance:
final double Density_Of_Water = 1.000;
would set Density_Of_Water to 1.000. This value can not be modified throughout the program because "final" told the compiler that this value would not change. A variable however, can be changed by the user throughout the program.
How do you find the greatest of two numbers without using the if-else comparison operators?
By subtracting any two of the numbers A-B , if the output number is negative , B IS GREAT and if its positive A is great
Why you use API rather than System Calls?
System calls are much slower than APIs (library calls) since for each system call, a context switch has to occur to load the OS (which then serves the system call).
How develop java calculator using awt?
import java.io.*;
import java.util.*;
public class Calculator
{
public static void main(String args[])
{
System.out.println("Make your arithmetic selection from the choices below:\n");
System.out.println(" 1. Addition");
System.out.println(" 2. Subtraction");
System.out.println(" 3. Multiplication");
System.out.println(" 4. Division\n");
System.out.print(" Your choice? ");
Scanner kbReader = new Scanner(System.in);
int choice = kbReader.nextInt();
if((choice<=4) && (choice>0))
{
System.out.print("\nEnter first operand. ");
double op1 = kbReader.nextDouble();
System.out.print("\nEnter second operand.");
double op2 = kbReader.nextDouble();
System.out.println("");
switch (choice)
{
case 1: //addition
System.out.println(op1 + " plus " + op2 + " = " + (op1 + op2) );
break;
case 2: //subtraction
System.out.println(op1 + " minus " + op2 + " = " + (op1 - op2) );
break;
case 3: //multiplication
System.out.println(op1 + " times " + op2 + " = " + (op1 * op2) );
break;
case 4: //division
System.out.println(op1 + " divided by " + op2 + " = " + (op1 / op2) );
}
}
else
{
System.out.println("Please enter a 1, 2, 3, or 4.");
}
}
}
Define java virtual machine in java?
A Java Virtual Machine (JVM) is a set of computer software programs that use a virtual machine model for the execution of Java computer programs and scripts.
The JVM accepts data in a form commonly referred to as Java bytecode. This language conceptually represents the instruction set of a stack-oriented, capability architecture.
Why is multiple inheritance implemened through interfaces?
Interfaces have only methods declared and not defined. So that these various methods can be altered or customized or written according to the need. Hence Multiple inheritance is implemented through Interfaces.
Interface is a progam which just declares various methods or functions, so that any user can write the contents of that method declaration.
AnswerTrue Multiple Inheritance refers to the ability to inherit from multiple CLASSES. Thus, a true multiple inheritance language does not use interfaces. However, many single-inheritance languages provide most of the benefits of the multiple inheritance concept by using interfaces (Java, for example).The problem with true Multiple Inheritance is twofold:
(a) at the compiler and runtime level, it is often difficult to determine which method is being referred to, as M.I. can lead to very convoluted (and sometimes conflicting) namespaces
(b) there is no specific superclass, which can lead to problems with determining relationships between classes
Using a S.I. model with interfaces avoids these two problems.
When do you give preference to abstract classs and interface?
Abstract class provides a way of "being a [something like me]", or inheritance
interface provides a set of functionality (contract) as "behaving".
Abstract class provides the single inheritance and perhaps some default implementation, while interface may be implemented by different classes that have nothing to do one and other except the common interface implementation.
The preference I would start with:
Ask yourself that an object should be "Is a something or behave like something". If your answer is "Is a", then abstract class is more likely your good choice. But if your answer is behave like, does not need to Is a, then the interface is the way to go.
When using a For loop what happens when the loop variable is equal to the final value?
That would depend on how exactly you define the three parts of the for loop. A typical for loop, equivalent to "for i = 1 to 10" in other languages, would look like this:
for (int i = 1; i <= 10; i++)
{
...
}
If you change this to:
for (int i = 1; i <= 1; i++)
then the code would still execute once.
How many values can a method return in Java?
A method in java can declare only one return value and type at a time. For ex: a single method cannot have a code that returns a string in some cases and an integer in other cases. Java compiler does not let you do that. You can only have one return type for every method in java.
What is program documentation?
Program documentation is an essential part of any computer program or application. The documentation specifies what each part of the code does, what events will be triggered during the course of the program, and makes sure that no part of the program is accidentally left off the interface or code.
What is the format specifier use with the data type double in c language?
double would be %e, %f or %g (depending on the format you want), long int would be %ld or %lu (signed or unsigned), long double would be %Le, %Lf or %Lg.
What is the importance of thread?
thread is a light weight program . concurrent execution of code can be done by usin threads.thread is a part of the program.
Does your ex have claim to your inheritance?
In general, an ex-spouse does not have a claim to your inheritance, as inheritances are typically considered separate property. However, if the inheritance was co-mingled with marital assets or if it was received during the marriage and not kept separate, there might be exceptions. It's important to consult with a legal professional to understand the specifics of your situation and the laws in your jurisdiction.
Can a Java application have memory leak?
Java has a fairly sophisticated garbage collection system, and in general you don't worry about memory leaks, as they only happen in a few very specific circumstances (notably, when adding listeners to Swing GUI objects and not removing them).
If you need more sophistcated memory management, java provides the clases in the java.lang.ref package.
Write a Java program to accept name and password?
String username=jTextField1.getText();
char[] pw=jPasswordField1.getPassword();
if ((username.equals("muja"))&& (check(pw)))
{
JOptionPane.showMessageDialog(null, "Username and Password is Correct","User Login",JOptionPane.INFORMATION_MESSAGE);
}
else if ((username.equals(""))&& (check(pw)))
{ JOptionPane.showMessageDialog(null, "Enter the UserName","User Login",JOptionPane.WARNING_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null, "Username and Password Wrong","User Login",JOptionPane.ERROR_MESSAGE);
}
}
Write a program in c to print characters from A to z and Z to A?
Use this code:
#include <iostream>
using namespace std;
int main()
{int x;
for(x=0; x<27; x++)
if(x 26) cout<< "z" << endl;
return (0);
}
What do you mean by extending classes in java?
That's the name used in Java for inheritance. It means that one class has all the behavior of another class; additional functionality can be added to the derived class.
Is PHP a compiler or interpreter?
It is normally interpreted by another computer program. However subsets of the language can be compiled.
How do you add a class or an interface to a package in java?
Well, the process differs whether you are using either an IDE or the command line binaries.
If you are using an IDE, then it is most likely that your IDE comes with extensive functionality for both managing and creating packages. Look under the "Packages" menu, or, when you are using Eclipse, just right click on the package name in the Package Explorer window and a flood of possibilities will come right up.
If you are using the command line binaries, then there are 2 steps to putting your classes in a package. First, you have to put your class or interface in the appropriate folder structure. For example, if you are using the package com.foo.bar.beebop, then you have to put your class in a folder named beebop, which is in a folder named bar, which is in a folder named foo, which is in a folder named com, which is in your class directory. Then, you have to add a package statement, which is only allowed to be at the top of your class file. For example, if you're using the package com.foo.bar.beebop, then put the following statement at the top of your class:
package com.foo.bar.beebop;
Then skip a line, then come your import statements (if you have any), then stick in another line (if you have inport statements), then your class.
Enjoy!
Give 10 example of close loop control system?
1. lightswitch --> light
2. Toaster --> toast (For timer-based toasters, only -- see below)
3. Water faucet --> water flow amount
4. Water faucets (hot/cold) --> water temperature in the sink or shower.
5. Temperature setting for the stovetop --> heat to cook food
6. TV remote control
7. Clothes dryer (timer based)
8. Volume on a stereo / home entertainment system
9. shades / blinds on a window --> 'regulating' the amount of light coming in from the outside.
10.
Closed loop:
1. Thermostat --> furnace (constant temperature)
2. Toaster setting (light/dark) --> toast (IF the toaster has heat sensors)
3. Refrigerator cold/hot setting --> refrigerator inside temperature (constant)
4. Temperatue setting for oven (not stovetop) --> oven temperature constant
5. Clothes dryer with moisture sensor
6. Washing machine water level
What is mean by method invoking in java?
method invoking refers to the action in which we call a Java method from within another java method or class.
Method invocation is analogous to a function call in procedural programming.