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

Write a program that reads in five integer and then determines and prints the largest and the smallest integers in the group?

#include ; using namespace std; int main () { int number1 = 0; int number2 = 0; int number3 = 0; int number4 = 0; int number5 = 0; coutnumber2>>number3>>number4>>number5; {if (number1 > number2) if (number1 > number3) if (number1 > number4) if (number1 > number5) cout

Control statements in java?

A programming language uses control statements to cause the flow of execution to advance and branch based on changes to the state of a program.

control statements are mainly three types in java. they are

selection, iteration, and jump.

What is a strut?

Struts is an open source Web application framework developed as Apache Jakarta project

Struts is based on MVC (Model View Controller) framework. It is used to build Web applications based on Servlet and JSP. So Struts application is a genuine Web application.

Struts leverages J2EE design patterns that people find quite useful in building J2EE applications. Because Struts follows these patterns including MVC, Struts is relatively simple to use and learn.

A Composite View is a view built using other reusable subviews. A single change to a sub-view is automatically reflected in every composite view that uses it. Furthermore, the composite view manages the layout of its sub-views and can provide a template, making consistent look and feel feel easier to achieve and modify across the entire application. Struts has its own set of custom tag libraries. Struts also support

utility classes.

What is multidimensional arrays?

A two-dimensional array is the simplest multi-dimensional array and is implemented as a one-dimensional array where every element is itself a one-dimensional array. We can imagine a two-dimensional array as being a table of rows and columns where every row is an array in its own right.

A three-dimensional array is simply a one-dimensional array of two-dimensional arrays, which can be imagined as being an array of tables. Extending the concept, a four-dimensional array is a table of tables.

Multi-dimensional arrays may be jagged. That is, a two-dimensional array may have rows of unequal length. Unlike regular arrays, jagged arrays cannot be allocated in contiguous memory. Instead, we use the outer array (the first dimension) to store pointers to the inner arrays. An array of strings (character arrays) is an example of a two-dimensional jagged array.

What are access specifires in java?

An Access Modifier is a key word in java that determines what level of access or visibility a particular java variable/method or class has. There are 4 basic access modifiers in java. They are:

1. Public

2. Protected

3. Default and

4. Private

Private is the most restrictive access modifier whereas public is the least restrictive. Default is the access protection you get when you do not specifically mention an access modifier to be used for a java object.

Java programming does not run by just a single piece of class that has the whole functionality. You have hundreds of classes that interact with one another, passing data between them and returning output to the user of the system. So it is very important for members of one class to access members of another. Here members may refer to variables, methods and even classes. So, this is where the access modifiers come into picture. The modifier associated with every member of the class determines what level of visibility that member has.

Postfix to Infix java?

A postfix incrementation or decrementation is handled by the ++ and -- operators. Postfix specifically refers to adding the operator after the variable name (eg. i++). This will attempt to increase/decrease the data type by 1. It differs from prefix in that it will return the variable before the calculation.

Example:

int i = 1;

System.out.print(i++); //1

System.out.print(i); //2

What is the use of the instanceof keyword in Java?

That is used to verify whether an object is based on the specified class (or a subclass).

What are math functions in java?

Math is a pre-defined class in the package java.lang. It contain various predefined functions in it that help the users to carry out various mathematical operations in their programs.

Various Math Functions are::

Math.pow(x,y) => x^y

Math.sqrt(x) => Square root of 'x'

Math.tan(x),sin(x),cos(x) => tan, sin, cos of 'x' respectively

there are also other functions like Math.ceil,Math.floor,Math.mod,etc.

What are events and methods in programming?

There are two major categories of programs which utilize event-driven method of their implementation: device drivers and GUI programs. Both spend most of their life cycle in waiting loop and perform any action only upon an incoming event, such as hardware interrupt, or an user's action. Internally, an incoming event may be processed by receiving code or dispatched to further code layers.

What is the difference between a class method and an instance method?

Instance methods can be called by the object of a Class whereas static method are called by the Class. When objects of a Class are created, they have their own copy of instance methods and variables, stored in different memory locations. Static Methods and variables are shared among all the objects of the Class, stored in one fixed location in memory.Static methods cannotaccess instance variables or instance methods directly-they must use an object reference. Also, class methods cannot use the this keyword as there is no instance for this to refer to.

How to read string from user in java?

There are many ways to input data from the keyboard, but the most convenient is the use of the Scanner class. By declaring the Scanner class's input as System.in, it pulls data from the keyboard (default system input). A simple example of taking data from the keyboard:

For instance if I had typed ( Hello my name is William, I like cheese. )

The following code would process it.

Scanner scan = new Scanner(System.in);

String mySentence = scan.nextLine();

System.out.println(mySentence); // it would display what I had typed in.

Other methods of the Scanner include:

next(); // gets the next token from input using a delimiter (the default is white space)

nextInt(); // returns the integer value of a number inputed

nextDouble(); // returns the double inputed

What is the document Getelementbyid used for?

The document Getelementbyid is used for Java programming. Java programming is a computer language that allows people to build applications for creative uses everyday.

Can you provide a solution to the diamond-square algorithm using Java and recursion?

Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.

What are the benefits of using a method in java?

Static members/methods are used as in helper classes say like Math. classes which helps other objects to utilize Strings or useful functions for which you do not need to create object but invoked using Class name. Example -> singleton objects are invoked using a static function.

Disadvantage -> Static members are part of class and thus remain in memory till application terminates and can't be ever garbage collected. Using excess of static members sometime predicts that you fail to design your product and trying to cop of with static / procedural programming. It denotes that object oriented design is compromised. This can result in memory over flow.

What is cacique class?

Cacique Systems is a website and web application development Company,Located at Asansol,West Bengal,India.

We work on different technology,such as the CDN network,GEOIP tracking,jquery,json,Ajax,etc

http://www.caciquesystems.com

What is the importance of recursion in computer programming?

Recursion is important because many algorithms are naturally recursive, particularly those that involve a divide-and-conquer technique. That is, we divide a complex problem into smaller instances of the same problem. Each division divides and reduces the problem further until the divisions are small enough to be resolved. We then aggregate those individual solutions to solve the original problem.

As a simple example, factorials can be calculated such that f(n) = n * f(n-1) for all n>1 where f(1) and f(0) are both 1. We can implement this function recursively as follows:

unsigned f(unsigned n) {

return n<2 ? 1 : n * f(n-1);

}

While the function itself is naturally recursive, that doesn't mean we must use a recursive solution. In this case, an iterative solution would actually be more efficient:

unsigned f(unsigned n) {

unsigned a = 1;

while (1<n) a *= n--;

return a;

}

However, in languages that allow compile-time computation (such as C++), recursive functions can be advantageous:

constexpr unsigned f(unsigned n) {

return n<2 ? 1 : n * f(n-1);

}

With this function, a good compiler will convert f(6) to the literal constant 720, completely eliminating the runtime overhead of invoking the function recursively. However, for values that cannot be computed at compile time due to excessive recursions, the runtime function will still be invoked, such that f(10) might be replaced with the constant expression 10 * f(9).

Languages that support template metaprogramming can provide the means to completely eliminate the runtime overhead associated with recursion:

template <unsigned N>

constexpr unsigned f () {

return N*f<N-1>();

}

template<>

constexpr unsigned f<1>() {

return 1;

}

template<>

constexpr unsigned f<0>() {

return 1;

}

Note that the terminating conditions are handled through specialisation rather than through recursion. At compile time, f<1>() invokes the first specialisation while f<0>() invokes the second. For all values N>1, the general function is invoked recursively at compile time.

constexpr unsigned x = f<10>();

Compile-time computation will effectively replace the above expression with:

constexpr unsigned x = 3628800;

Note that no code is generated for these template functions so we cannot invoke them at runtime, they are used purely for compile-time computation.

In languages that do not support template metaprogramming or constexpr, we can still make use of recursion, particularly where an iterative approach is too complex to implement efficiently. Divide-and-conquer algorithms are a typical example.

The Quicksort algorithm is a relatively simple recursive algorithm that can be implemented as follows:

void qsort (int a[], int lo, int hi) {

if (hi<=lo) return;

unsigned pivot = partition (a, lo, hi);

qsort (a, lo, pivot-1);

qsort (a, pivot+1, hi);

}

The partition() function does most of the actual work. Given the lower and upper bounds of the array it will select a pivot value and position this value such that all values to the left of it are less than it and all those to the right are not less than it. Once the array is partitioned, the index of the pivot value is returned. This value is used to determine the upper bound of the left sub-array (pivot-1) and the lower bound of the right sub-array (pivot+1).

What are the difference between array declaration in java and c plus plus?

There is no difference, other than that declarations in C++ can also initialise the variable in a single instruction.

C example:

int x; // declaration

x=5; // initialisation

C++ example:

int y=5; // declaration and initialisation combined.

Is Java or C plus plus faster?

Java is considerably more convenient than either C or C++ due to its extremely high level of abstraction. However, that convenience comes at the cost of both performance and efficiency.

C program for upper triangular matrix for a given matrix?

This sounds very much like a homework problem. If you work on it and get started, you found a great place to ask a specific question. However, this is not a place to have your homework done for you.

What is Result set in java?

A table of data representing a database result set, which is usually generated by executing a statement that queries the database.

A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set.

A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, you can iterate through it only once and only from the first row to the last row. It is possible to produce ResultSet objects that are scrollable and/or updatable. The following code fragment, in which con is a valid Connection object, illustrates how to make a result set that is scrollable and insensitive to updates by others, and that is updatable. See ResultSet fields for other options. Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2"); // rs will be scrollable, will not show changes made by others, // and will be updatable In simple words, result set can store the result of the database query(SQL query).

Visit here for more: docs.oracle.com/javase/1.4.2/docs/api/java/sql/ResultSet.html

What is a loop type?

A Loop is a programming language construct that instructs the processor to repeat a sequence of operations a number of times until a specific condition is reached. There are different types of loops. They are: * for loop * while loop * do while loop