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 do you normally create when you want to run a function in the background while processing other things?

You normally create a thread when you want to run a function in the background while processing other things.

Define the java terms of accessor?

Accessors are methods defined inside classes to access the private variables of the class. It is always a good practice to have instance variables as private so that, other classes cannot access them directly. This would avoid unwanted modification of data. These variables can be accessed only via their respective accessor methods. Ex: public class Test { private String name = ""; public String getName(){ return this.name; } Public void setName(String val){ this.name = val; } } Here getName and setName are the accessor methods for the variable name.

Describe a simple scheme in which there are as many lightweight processes as there are runnable threads?

Start with only a single LWP and let it select a runnable thread. When a
runnable thread has been found, the LWP creates another LWP to look for a
next thread to execute. If no runnable thread is found, the LWP destroys itself.

What is declaration syntax of an array?

In what language?

c and c++

a 5 x 5 array of Int

int nMultiIntArray[5][5];

Answer:

in java

int array[][]=new int[5][5];

in vb

dim array(5,5) as Integer

How do you calculate execution time of an exe file?

Use a high-resolution timer such as the HPET (high performance event timer).

What is an adequate measure of the size of input for a program that requires two integer numbers n?

Not sure what you mean; if you want to measure the "input size" in bytes, that would probably be 8 bytes, since integers typically use 4 bytes.

A method that is automatically called when an instance of a class is created?

The constructor of a class is automatically called when an instance of the class is created (using new in C++). The constructor method has the same name as the class that it is a part of. Constructors have no type and do not return anything.

Similarly, the destructor is automatically called when the instance of the class is destroyed. The destructor is the same name as the class and is preceded by a tilde (~)

For example:

class Example

{

public:

Example() // Constructor

{

printf("Object created\n");

}

~Example() // Destructor

{

printf("Object destroyed\n")

} };

int main()

{

Example* x = new Example(); // Creates object, calls constructor

delete x; // Calls destructor, deletes object

return 0;

}

What is stringtokenizor in java?

StringTokenizer is a class in Java that allows you to iterate through a String's tokens, or parts that resemble a defined pattern. By default, StringTokenizer uses "\t\n\r\f" (whitespace) to break up a String. You can override this in the constructor for your own pattern. These days, the split method of String is used instead of StringTokenizer.

2 examples below:

StringTokenizer st = new StringTokenizer("Hello World");

System.out.println(st.countTokens()); //2

System.out.println(st.nextElement()); //Hello

System.out.println(st.nextElement()); //World

StringTokenizer st = new StringTokenizer("Hello,World","[aeiou]");

System.out.println(st.countTokens()); //4

while(st.hasMoreElements())

System.out.print(st.nextElement()); //Hll,Wrld

Can structured techniques and object-oriented techniques be mixed?

Yes, in fact, they are always mixed. You always write structured procedures (the main function, at least), that will control your objects. Objects can't work just by themselves. At least, that's how it is in C++.

What is type 4 jdbc driver?

JDBC is short for java database connectivity. There are 4 type of JDBC drivers : 1) JDBC-ODBC 2) Native-API 3) JDBC-Net 4) Native-Protocol.

What does a signed data type mean?

signed: its value can be less than zero

unsigned: its value cannot be less than zero

example:

16 bit signed: -32768 .. 32767

16 bit unsigned: 0 .. 65535

When do you declare a method or class abstract in java?

when overriding of a class or a method is necessary, they can be declared as abstract

Write a program that accepts two stringsThe program should determine whether the first string occurs at the end of the second string?

In C, there will be a part like this:

char s1[] = "END";
char s2[] = "REVEREND";
size_t l1, l2;

l1= strlen (s1);
l2 = strlen (s2);

if (l1>=l2 && strcmp (s1, s2+(l2-l1))==0) puts ("Yeah");

How do you determine if two primitives are equal in computer programming?

All programming languages provide 6 built-in comparison operators:

< less than

<= less than or equal

== equal (denoted = in some languages)

!= not equal (denoted <> in some languages)

> greater than

>= greater than or equal

In C programming, to compare any two primitive data types (X and Y) for equality, we would use the equality operator as per the following expression:

X==Y

This expression evaluates true whenever X and Y hold the same logical value, otherwise it evaluates false. We can use this expression within any statement where the expression true or false would be expected. For example:

if (X==Y) {

// do something when X and Y are equal (where X==Y evaluates true)

} else {

// do something when X and Y are not equal (where X==Y evaluates false)

}

Note that the built-in == operator can also be applied to any combination of primitive data types that can be implicitly promoted or converted to a common type. For example, comparing an int with a double will implicitly convert the int to a double, thus we are actually comparing two doubles, as per the following "named operator":

bool is_equal (int X, double Y) {

return X==Y; // implicitly the same as: return (double) X==Y;

}

If we interchange public static and void main then what happens?

Making main static is probably not a good idea; it may keep the linker from recognizing the program entry point. main is not a method, so it cannot be anything but public, for all intents and purposes. Declaring main to have a void return and/or with a void argument list is usually harmless, although it limits how your program can interact with the OS.

Java program that prompts the user for an integer and then prints out all prime numbers upto that number?

import java.io.*;

class PrimeNumber

{

public static void main(String[] args) throws Exception

{

int i;

BufferedReader bf = new BufferedReader(

new InputStreamReader(System.in));

System.out.println("Enter number:");

int num = Integer.parseInt(bf.readLine());

System.out.println("Prime number: ");

for (i=1; i < num; i++ ){

int j;

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

int n = i%j;

if (n==0){

break;

}

}

if(i == j){

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

}

}

}

}

output:

Enter number:

50

Prime number:

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47BUILD SUCCESSFUL (total time: 3 seconds)

How do you get boolean value from string in java?

Here is some sample code to convert a string into a boolean:

String word = "true";

boolean boo;

if (word.equalsIgnoreCase("true"))

boo=true;

else

boo=false;

Java program that converts a decimal number to Roman number?

There is a very good article on performing conversions from integers to roman numerals here: http://www.faqs.org/docs/javap/c9/ex-9-3-answer.html The article includes the full source code necessary to implement this solution on your own.

Sample college examination program using SQL?

can you please send me a sample program of college examination using sql?thanks...God bless...

What is a constructor method?

Constructors and the main method serve two different purposes. Constructors allow creation of instances of a given Class, whereas the main method merely allows for a potential entry point for starting your program.

To learn more about data science please visit- Learnbay.co