What did Victorian teachers show a class during an object lesson?
During an object lesson, Victorian teachers would often use real objects to illustrate concepts and engage students' senses. For example, they might show a plant or animal specimen to teach about biology, or use everyday items to explain mathematical principles. This hands-on approach aimed to enhance understanding and retention by connecting abstract ideas to tangible examples, making learning more interactive and relevant for students.
What are the problems that can occur if you do not implement locking properly?
The main - and most important - problem that can come from buggy locking code is that the data you're trying to establish a lock on may end up being accessed and edited by multiple threads/processes at the same time. This would, of course, defeat the purpose of trying to lock out data.
Other problems could include things like two threads trying to access some data at the same time, but each thinks the other has a lock on it. Which would give us a nice little deadlock to deal with.
Who inherits if the child that was to inherit dies before the inheritor?
The inheritance of any deceased person is divided amoongst the remaining heirs.
Write a java program to input a string and find the total number of uppercase letters in the string?
The code is given at the bottom. This code requires JAVA 1.5+ version to be compiled.
This is very simple program. We ask user to input string and later we just iterate through all the character in the string. We use Character.isUpperCase() static method to check is the character we are checking is upper case if so we increase count variable by one. After iteration is done we print count variable and application quits.
Note: for statement was introduced in 1.5 JAVA version.
Example of usage:
david-mac:~ david$ java Test
Enter string: This is A Test String.
Your string has 4 upper case letters.
-------------------------
import java.io.*;
import java.lang.*;
public class Test
{
public static void main(String[] args)
throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter string: ");
String userString = in.readLine();
int count = 0;
for (char ch : userString.toCharArray())
{
if (Character.isUpperCase(ch))
{
count++;
}
}
System.out.println("Your string has " + count + " upper case letters.");
}
}
How do you make a java program return a random number between two numbers inputed by the user?
Here is the final code for a program that RETURNS the number (from another method to the main method):
import java.util.*;
public class Example
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Please enter two numbers to generate a number between (inclusive) those two numbers");
System.out.println("Please enter the first:");
int d = in.nextInt();
System.out.println("Please enter the second:");
int e = in.nextInt();
int g = randomBetween(d, e);
}
public static int randomBetween(int d, int e)
{
Random random = new Random();
int f = random.nextInt(e-d+1)+d;
return f;
}
}
We are not allowed to put links in the answer to a question, so I have now put the link to a video explaining this code in the related links area.
What is the need of constructor overloading?
To have options wherein we can create objects of a class with different sets of parameter (initial) values
Differentiate between applet application and standalone application?
An applet runs in a browser; a standalone application works like a traditional application, which you launch directly from your operating system.
An applet runs in a browser; a standalone application works like a traditional application, which you launch directly from your operating system.
An applet runs in a browser; a standalone application works like a traditional application, which you launch directly from your operating system.
An applet runs in a browser; a standalone application works like a traditional application, which you launch directly from your operating system.
Sorting an array of objects through in built function?
Object[] arrayToBeSorted;
Arrays.sort(arrayToBeSorted);
What is the difference between honor classes and regular classes?
Honor classes give you college credit, if you are stating from a High School standpoint. If not, honor classes give you more credits than regular classes.
What is a consecutive numbering method?
consecutive numbering method - A method in which consecutively numbered records are arranged in ascending number order - from the lowest number to the highest number.
import java.util.Scanner;
class NoMatchException extends Exception {
static void method() throws Exception{
String s = "India";
String s2 = " ";
try {
if (!s.equals(s2)){
throw new NoMatchException();
//System.out.println("Strings are equal");
}
else {
System.out.println("Strings are equal");
//throw new NoMatchException();
}
}
catch(NoMatchException ne){
System.out.println("Exception Found For String");
}
finally {
System.out.println("In Finally Block");
}
}
}
public class BasicException {
static void myMethod(int x, int y) throws Exception{
try {
if(x < y ) {
System.out.println("Y is greater then X");
throw new Exception();
}
else
System.out.println("Y is smaller");
}
catch(Exception ex) {
System.out.println("exception found");
//System.out.println(ex.toString());
}
finally {
System.out.println("FINALLY block");
}
}
public static void main(String args[]) throws Exception{
Scanner s = new Scanner(System.in);
int d, a, x, y;
System.out.println("Enter the value of x and y");
x = s.nextInt();
y = s.nextInt();
try {
BasicException.myMethod(x , y);
}catch(Exception e) {
System.out.println("main method exception");
System.out.println(e.toString());
}
try {
NoMatchException.method();
}
catch(NoMatchException e) {
System.out.println("Exception Caught");
}
try{
d=0;
a=42/d;
System.out.println("This will not be printed.");
}
catch(ArithmeticException e){
System.out.println("Division by zero.");
}
}
}
What are the different types of variables?
The exogenous ones, which are set by an outside agent, and the endogenous ones, which occur inside a problem.
So if you look at this formula for a wave in one dimension:
y = exp(-jkx), where k = 2pi / lambda
lambda and x are exogenous while k is endogenous (j and pi are constants).
What is method overriding in java?
Method overriding is when a child class redefines the same method as a parent class, with the same parameters.
For example, the standard Java class java.util.LinkedHashSet extends java.util.HashSet. The method add() is overridden in LinkedHashSet. If you have a variable that is of type HashSet, and you call its add() method, it will call the appropriate implementation of add(), based on whether it is a HashSet or a LinkedHashSet. This is called polymorphism.
Method overloading is defining several methods in the same class, that accept different numbers and types of parameters. In this case, the actual method called is decided at compile-time, based on the number and types of arguments. For instance, the method System.out.println() is overloaded, so that you can pass ints as well as Strings, and it will call a different version of the method.
Overriding is an example of run time polymorphism. The JVM does not know which version of method would be called until the type of reference will be passed to the reference variable. It is also called Dynamic Method Dispatch.
Overloading is an example of compile time polymorphism.
Is memory allocated for instance methods for each instance method call?
No! Instance methods are allocated memory at first time only.
C program to generate parkside's triangle numbers?
this program is to generate pascal's triangle #include<stdio.h> #include<conio.h> main() { int n,i,j; clrscr(); printf("enter the number"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=i;j++) printf("%d",j); printf("\n"); } getch(); }