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

How does multithreading improve the performance of java program?

When you have only one processor and run a java program that does everything in memory eg., loops , calculations without looking up external datasources like Database, Socket, MQ , Web Service there wont be any performance benefit out of multithreading.

But when you have multiple processors on the host and you are doing to a large algorithm completely in memory it will definitely help to split your process into threads so different threads can be handled by different processorts

Event if you have on processor and if your java class (or program) does in memory calculations, algorithms + some external lookup like JDBC calls multithreading can greatly help the performance of your process. Your CPU would be free to do other tasks when your code waits for the database to return results.

What is operator overloading?

I think you mean operation overlord??? It is the American, Canadian and British offensive on Europe in World War 2. They landed in Normandy on 6th June 1944 (Commonly called D-Day, Day of Days or Deliverance Day) and progressed throughout France liberating Paris on the 25th August. This allowed the allies a foothold in Europe.

What are literals in java?

In Java, a literal is the source code representation of a fixed value and are represented without requiring computation. The various types are Integer, Floating-Point, Character and String literals.

Where string is stored on Heap or Stack in java?

A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.

A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.

A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.

A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.

Program to concatenate the two strings without using build in functions?

#include<iostream>

#include<string>

int main()

{

using std::string;

string a = "hand";

string b = "bag";

string c = a + b; // concatenation

}

What is the disadvantage of circular queue?

A linear queue is a FIFO structure (first in, first out) akin to a queue of people waiting in line to be served on a first-come, first-served basis. There are no disadvantages provided you use it for the purpose intended.

You probably meant to ask what are the disadvantages of implementing a queue using a linear list. A linear list is a LIFO structure (last in, first out), which is akin to a stack of plates. The last plate on the stack is the first to be removed from the stack. In order to transform a linear list into a queue we must modify the behaviour slightly.

A linear list is typically implemented using a forward list (a singly-linked list) where every node points to the next node. Insertions and extractions always occur at the head node since the head node is the only node maintained by the list, and is therefore the only node with constant-time access. To locate the tail node, we must recursively traverse from the head node through each node's next node, until there is no next node. This traversal has linear complexity; the time taken to locate the tail node is directly proportionate to the number of nodes. Thus for a list of n nodes, it will take O(n) time to locate the tail node, but O(1) time to locate the head node.

To turn a linear list into a queue we must maintain a secondary pointer to the tail node. Extractions will still occur at the head but now insertions will occur at the tail. While this resolves the immediate problem, we're now using additional memory simply to maintain the tail pointer. Although the additional memory is minimal, there is a better way. If we point the tail node at the head node we create a circular list. This then means we can access both the head and tail nodes in constant-time through the tail node alone. Thus we no longer need to maintain a pointer to the head node.

To summarise, linear lists are disadvantageous when implementing queues because of the need to maintain two node pointers to achieve constant-time access to the head and tail nodes. Circular lists resolve the problem by utilising just one pointer to the tail.

Why do you think you would be exceptional for this position?

My strengths that I can bring to the company are pretty clear. I love finance and accounting, corporate governance and corporate finance. I like to get an in-depth understanding of business and finance, I am good at it, I like to work hard and get results.

Don't say anything about money.... That's why everyone needs a job or else you wouldn't be looking for one. Just tell them that you would love the experience and hope to do whatever your job is for the rest of your life. Or you can give them a resume.

How do you compiling a source code in java?

The javac command is used to invoke Java's compiler and compile a Java source file.

A typical invocation of the javac command would look like below:

javac [options] [source files]

Both the [options] and the [source files] are optional parts of the command, and both allow multiple entries. The following are both legal javac commands:

javac -help

javac ClassName.java OneMoreClassName.java

The first invocation doesn't compile any files, but prints a summary of valid options. The second invocation passes the compiler two .java files to compile (ClassName.java and OneMoreClassName.java). Whenever you specify multiple options and/or files they should be separated by spaces.

This command would create the .class files that would be require to run the java progam.

Write a java program to check a number is Armstrong number?

import java.io.*;

public class Jerry

{

public static void main(String as[]) throws IOException

{

int k=Integer.parseInt(as[0]);

int n=k;

int d=0,s=0;

while(n>0)

{

d=n%10;

s=s+(d*d*d);

n=n/10;

}

if(k==s)

System.out.println("Armstrong number");

else

System.out.println("not Armstrong number");

}

}

What is a variable in the Java?

A variable is something that can store data, such as numbers and words. One of the common types of variables is called "int", which can store numbers.

Creating a variable is simple:

int myVar;

"int" is the data type of the variable, and "myVar" is the name of the variable, you can choose almost any name you want for your variables.

Then you can assign a number to this variable, you can even use negative numbers:

myVar = 5;

Notice how you do not need to type "int" again, you only need to do it once when you create the variable.

Here's how to add numbers to variables:

myVar = myVar + 4;

OR

myVar += 4;

When you do either of these it will add 4 to the value of myVar, which means myVar now equals 9. (5 + 4 = 9)

You can also use subtraction: -

Multiplication: *

Division: /

and Modulus: %

Another imortant data type is the String, a String can store words and letters, and behaves much like an int.

String myVar;

myVar = "Hello";

myVar += " there, Sir.";

Now, like we did with the int earlier, myVar equals "Hello there, Sir."

One last thing, you can add different variables together, but they must be the same data type:

myVar += anotherVar;

What is oops?

When you delete a file from your computer the file is not really deleted, it is merely left there & the space it occupies is made available to be written over.

'Oops' is a program that allows you to call up deleted files & by restoring the name of the file to the original name (by the addition of the first character of the original name) rewrites them to disc.

e.g. Original file name was backup.exe. when file is deleted it becomes _ackup.exe

when using 'oops' you simply put the 'b' on to the deleted & it is restored. Object Oriented Programming System

What is abstract base class?

An abstract class is a class that cannot be directly instantiated. The purpose of such a class is to put some logic in a base class and force derived classes to implement the remaining functionality. Since the full functionality is only available in the derived class, the base class is declared as abstract so that it cannot be instantiated directly.

Difference between connectionless and connection oriented communication?

Different from a connectionless protocol, a connection-oriented protocol guaranties the delivery of the information. An example of connection-oriented protocol is (TCP) and a connectionless protocol is (UDP). page/926 A+

Why use catch keyword in java?

no, because catch is used to handle exceptions which are generated from try block

What happens if you download java?

Then I am asked to install Junit,JDK.Thank you.

How do you access nembers of a class?

Use the class member access operators. For object references, use the . operator, for pointers, use the -> operator.

class obj

{

public:

void foo(){}

};

void main()

{

obj o, *p=&o;

o.foo(); // Access member via reference.

p->foo(); // Access member via pointer.

return( 0 );

}

The sum of a number and ten?

import java.io.*;

public class sum{

public static void main(String[] args) {

try{

System.out.print("Enter 10 numbers: ");

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int[] input=new int[10];

int a,total=0;

for(a=0;a<10;a++) {

System.out.println();

input[a]=Integer.parseInt(br.readLine());

}

for(a=0;a<10;a++) {

total+=input[a];

}

System.out.println("The sum of the numbers is "+total);

}catch(Exception e) {

e.printStackTrace();

}

}

}

What is the similarity between 'if' statement ans 'switch' statement?

A Switch statement can be considered as a series of if. else if. else statements. whatever condition is satisfied, the code block would get executed.

if (cond 1) {

} else if (cond 2) {

} else if (cond 3) {

} ......

} else if (cond N) {

} else {

}

switch {

case 1: ....

case 2: ....

....

case N: ...

default: ...

}

Difference:

In the if else blocks, if one condition is satisfied, all other blocks are ignored

In Switch blocks, unless you have break statements inside each condition block, the subsequent blocks would not be ignored.

What is primitive and non primitive cell?

Primitive unit cells use every lattice point as a unit cell vertex.

Non-primitive unit cells, however, contain extra lattice points not at the corners.

What is the difference between j2sdk and jdk?

JDK is java development kit whereas J2SDK is the newer one and is called as Java 2 software development kit.

How do you swap two variables in java with GUI?

/*Program to swap 2 values without using the temporary variable and Arithmetic operators*/

class Swap

{

public static void main(String args[])

{

int a=1;

int b=2;

System.out.println("Before swap: a="+a+"b="+b);

a=a^b;

b=a^b;

a=a^b;

System.out.println(" After swap: a="+a+"b="+b);

}

}

Another Method

class Swap

{

  • public static void Swap()

  • {

  • int num1 = 10;

  • int num2 = 20;

  • System.out.println("Before Swapping");

  • System.out.println("Value of num1 is :" + num1);

  • System.out.println("Value of num2 is :" +num2);

  • //add both the numbers and assign it to first

  • num1 = num1 + num2;

  • num2 = num1 - num2;

  • num1 = num1 - num2;

  • System.out.println("Before Swapping");

  • System.out.println("Value of num1 is :" + num1);

  • System.out.println("Value of num2 is :" +num2);

  • }
  • }

Time complexity of selection sort?

Merge sort (or mergesort) is an algorithm. Algorithms do not have running times since running times are determined by the algorithm's performance/complexity, the programming language used to implement the algorithm and the hardware the implementation is executed upon. When we speak of algorithm running times we are actually referring to the algorithm's performance/complexity, which is typically notated using Big O notation.

Mergesort has a worst, best and average case performance of O(n log n). The natural variant which exploits already-sorted runs has a best case performance of O(n). The worst case space complexity is O(n) auxiliary.

What operating system was java developed?

Java was developed to be run on any OS. The existence of the Java Virtual Machine means that only the JVM has to be ported to different platforms, so Java source code can be run on any of those platforms without any change.

(If the question was asking what system Java was developed on, then I don't know for sure. But since it was developed at Sun Microsystems, one could safely assume it was written in some version of Solaris.)