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 makes for a good or bad variable name in C plus plus programming languages?

A good variable name is one that is clear, related to the data it stores. Also, you should try to avoid confusions with other variables.

What is an empty constructor?

An empty constructor takes no arguments and calls the default constructor

Why are public instance variable dangerous?

Public instance variables are not dangerous, but can put your program at risk of being hacked. For instance, say the variable bacon is an integer that represents your health in a game, and its value is 50. Someone could change its value to 1,000,000 by using a program called a decompiler, then change the code, and recompile it.

What is the difference between Char a equals string and char a equals String?

Well, if you write like char a=string; it is wrong. You have to declare the size of the array or else put the brackets immediately after the variable declaration. You also have to put the string in quotes, or provide a comma-separated list of characters. E.g.,

char a[]={'s','t','r','i','n','g'};

Or more simply:


char a[] = "string";

Remember that C/C++ is case-sensitive and that all keywords are lower case. Thus Char would be regarded as an invalid keyword.


How can I write a method that returns true if the number passed can be divided by all its digits?

Write a loop, in which you divide by each of the digits; if it's NOT divisible, set the variable "result", which you initiall set to "true", equal to "false".

The tricky part is extracting the digits; one way to do this is to convert the number to a string, and use string functions. You can also repeatedly divide by 10, and use the remainder. That is, first take the remainder and test it; then divide the remaining number by 10.

How to use threads simultaneously?

Threads are meant to be used simultaneously. If you have 3 threads, you can run them simultaneously by starting them together.

Ex:

t1.start();

t2.start();

t3.start();

Assuming the three threads t1, t2 and t3 are already created.

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.

What is an arg?

An arg is a term used in computing for an argument.

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.");

}

}

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.

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.

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.