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

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 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

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.

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

What is problem oriented language?

a program generation activity aims at automatic generation of a program.The source language is a specification language of an application doamain and the target language is typically a procedure oriented programming language.A program execution activity organized the execution of a program return in a programming language on a computer system.Its source language could be a procedure oriented language or a problem oriented language

Real time example for interface vs abstract class in java?

w.frnds........

I am just trying to an example of abstract class and interface class in real life . As these two

["interface class" is not a term in Java programming - just "interface"]

classes [sic] are a concept of objest orientation so easy we can easily compare thhese with our real life .

Suppose we have an abstract class called clark and an abstract method behabour of this abstract class ,which has no definition in abstract class.

two other class security and receptionist inherits these clark class.

So in thses two derived class there must has to be a defonation of behabour method,which depends on the derived class which types of behabour they will show........

So that is a real life example of Abstract class .Interface is also same as abstract class only the difference is it can't contain any implementation of any method in base class or super class.

I think this is a sufficient example to understand abstract class and interface.

[No, it is not sufficient.]

If u have any doubt then u can contact me with this email id-rkmahanta26@gmail.com

[Interfaces support multiple inheritance; classes do not. Interfaces contain only public members; classes do not have to. Interfaces do not have superclasses, except the implicit 'Object' supertype; they have superinterfaces. Nested interfaces are always static, never inner, unlike classes which can be inner classes. "u" is not an English pronoun.

Use the tutorial and the JLS to understand interfaces and abstract classes, not this garbage answer.]

What are temporary object in java programming?

A temporary object is also known as an automatic object. These are objects that are created automatically during a compound computation according to operator precedence. For instance, a = b + c * 42 is composed of several operations each of which must be evaluated separately. Multiplication takes precedence over addition which takes precedence over assignment, thus the complete operation is evaluated as follows:

a = (b + (c * 42))

c * 42 is evaluated first as it has the highest precedence. This creates a temporary object storing the result of that operation. The object has no name (it is anonymous), but let's refer to it by the name t1. This leads us to the second part of the evaluation:

b + t1

This creates another temporary object, which we'll refer to as t2. At this point t1 immediately falls from scope (because it was temporary). Finally, we perform the last part of the evaluation:

a = t2

At this point, the variable named a holds the final result of the operation and t2 falls from scope.

What is the function of catch Exception E?

In Java, if there is a run-time error then it allows the user to explicitly handle it by catching it in the catch block. If there is any error in the try block of code, automatically the flow control will be transferred to the catch block. Here Exception e indicates any exception. The same is true in both Visual Basic and C#. This is seen in the

try {}

catch (Exception e) {}

blocks. Which then function as the previous poster said.

== == == ==

What is the purpose of claiming exceptions?

it informs compiler about its possible exceptions.

For example,The purpose of Java exception is to tell the Java runtime system what can go wrong