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

Java program that will input 10 scores and output the highest and lowest score?

import javax.swing.JOptionPane; //marlonroxas

public class loop_exer2

{

public static void main(String agrs[])

{

String input;

int trial=10, sc=0, h=0, l=0, test=0;

System.out.print("Scores: ");

for (int ctr=1;ctr<=10;ctr++)

{

input=JOptionPane.showInputDialog("Enter the Scores ["+trial+"] trials ");

sc=Integer.valueOf(input);

System.out.print(sc+", ");

if(test==0){h=sc;l=sc;test=1;}

if(sc>h){h=sc;}

else if(sc<l){l=sc;}

}JOptionPane.showMessageDialog(null, "Highest Score is: "+h+

"\n\nLowest Score is: "+l);

System.out.println();

System.out.println("Highest Score: "+h);

System.out.println("Lowest Score: "+l);

}

}

Why super constructor should be first statement in subclass constructor in java?

Because, the parent class also needs to be initialized when you create an object in the inheritance hierarchy.

Write a java program to print 'Sunny' Numbers till 'n'?

class Sunny

{

void accept(int n)

{

int n1=n+1;

double x=Math.sqrt(n1);

if((int)x==x)

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

else

System.out.println("not a sunny number");

}

}

What is the function of structured exception handling or SEH in Windows?

Microsoft supports Structured Exception Handling (SEH) as a programming technique only at the compiler level. In particular, MS Visual C++ compiles __try, __except, and __finally as the three non-standard keywords used in this program. As well, SEH is supported by a number of WIn32 API functions including RaiseException which allows to raise any SEH exceptions manually. Overall, it is a native handling mechanism for Windows and features the "finally" mechanism that is currently not present in the standards C++ exception. SEH is set up to handle each thread of execution separately.

Write a java program to initialize array of string with the days of the week?

final String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

What is the size of a Java object and how can you find it?

Most Java objects seem to be 32KB and are located under your downloaded programs.

If you double click on your "My Computer" icon then double click on "Local Disk (C:) " there you should find an area with a "Windows" folder double click on that and there should be a "Downloaded Programs" folder in which if you double click on that you will be able to then see your Java objects - OR - instead of going into the "Windows" folder you could double click on the "Programs" folder and there will be a "Java" folder in there (which ever you prefer).

Wap to sorting the element of the array?

void main()

{

int i,j,temp1,temp2;

int arr[8]={5,3,0,2,12,1,33,2};

int *ptr;

for(i=0;i<7;i++)

{ for(j=0;j<7-i;j++) {

if(*(arr+j)>*(arr+j+1))

{ ptr=arr+j;

temp1=*ptr++;

temp2=*ptr;

*ptr--=temp1;

*ptr=temp2;

clrscr();

for(i=0;i<8;i++)

printf(" %d",arr[i]);

getch(); }

Write a c program the extracts and prints the rightmost digit of the integral portion of the float?

#include<stdio.h>

int main (void)

{

float x,y;

int z,w;

printf("enter a number:");

scanf("%6.2f",&x);

y=x/10.0;

z=x-y;

w=z%10;

printf("the rightmost digit is %d\n",w);

return 0;

}//main

Inverse of matrix in java?

import java.util.Scanner;

public class Exercise07_23 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter a11, a12, a13, a21, a22, a23, a31, a32, a33: ");

double[][] A = new double[3][3];

for (int i = 0; i < 3; i++)

for (int j = 0; j < 3; j++)

A[i][j] = input.nextDouble();

double[][] inverseOfA = inverse(A);

printMatrix(inverseOfA);

}

public static void printMatrix(double[][] m) {

// ????

}

public static double[][] inverse(double[][] A) {

double[][] result = new double[A.length][A.length];

// Compute |A|

double determinantOfA = 1; // A[0][0] * A[1][1] * A[2][2] * ...;

result[0][0] = (A[1][1] * A[2][2] - A[1][2] * A[2][1]) / determinantOfA;

result[0][1] = 1; // ??

result[0][2] = 1; // ??

result[1][0] = 1; // ??

return result;

}

}

What is the symbol for get on the Trackers interface?

its the same symbol as "have" a hand with an arrow pointing at it!!

Why java is platform independent explain by diagram?

Java is a platform independent language becoz of the bytecode magic of java. In java, when we execute the source code...it generates the .class file comprising the bytecodes. Bytecodes are easily interpreted by JVM which is available with every type of OS we install.

How do you use arrays in biginteger?

In Java, you would create an array of type BigInteger, then initialize each object (each array element) with the newoperator. I believe it would be something like this: BigInteger[] myArray = new BigInteger[5]; for (int i = 0; i

What is the difference of jdk in between java 2 SE and java NewEdition?

First of all, it's "JDK", not "jdk", and "Java", not "java".

What do you mean by "Java new edition"? I do not find that term when I Google for it.

"Java 2 SE" is a brand name for very old, obsolete versions of Java, between version 1.2 and 1.4, inclusive.

The current version of "Java SE" (Java Standard Edition), as it is now called, is version 7, with support still available for version 6. These versions are also called 1.7 and 1.6, respectively.

See <http://www.oracle.com/technetwork/java/javase/jdk7-naming-418744.html>

Why does aircoditioner work while on the road while traveling but not around town at slower speeds?

you are low on r-12 or r-134a. the pressure switch on the high pressure side controls the compressor kickin on and off, but at a higher rev, you may have enuff pressure, and at low, the pressure may not be enuff. so get a fill kit.

How event-driven methodology facilitates GUI programming?

The first computers had to use polling to determine events that happened, such as key presses, mouse movement, and joystick movement. A long-running process might cause the screen to appear unresponsive. As the number of elements on the screen increased, and particularly with the advent of multi-tasking, it was no longer appropriate for the application to maintain its own state through polling.

Instead, all modern GUIs advise running programs of events that would interest that program. Keypresses, mouse events, and so on are no longer checked many times per second, which would cause extreme lag on even the fastest computers. A typical web browser, for example, might have hundreds or thousands of "windows", including buttons, text, and so on. If each window had a thread that had to run full-time just to detect if it were doing anything, it would result in massive slowdown as tens of thousands of mini-programs competed for limited system resources.

What is the of abatract keyword in java 1.7?

"abstract" is used for a class that is not supposed to be instantiated directly. The reason this is used is because the class is not complete; the details are supposed to be filled out in subclasses (derived classes). An abstract class will usually have one or more abstract methods; a method that is declared by name (to make sure derived classes have this method), but without a method body.

What is access modify in java?

  1. Default- visible to the package
  2. Public - visible to all
  3. Protected- visible to the package and all subclasses
  4. Private- visible to the class

Write a program in java for creating multiple threads?

class NewThread implements Runnable { String name; Thread t; NewThread(String threadname) { name=threadname; t=new Thread(this,name); System.out.println("New Thread:"+t); t.start(); } public void run() { try { for(int i=5;i>0;i--) { System.out.println(name+ ":"+i); Thread.sleep(1000); } } catch(InterruptedException e) { System.out.println(name+" Interrupted"); } System.out.println(name+" exiting"); } } class MultiThreadDemo { public staticvoid main(String[] args) { new NewThread("One"); new NewThread("Two"); new NewThread("Three"); try { Thread.sleep(10000); } catch(InterruptedException e) { System.out.println("Main Thread Interrupted"); } System.out.println("Main Thread Exiting"); } }

Output:

New Thread :Thread[One,5,main]

New Thread : Thread[Two,5,main]

One:5

Two:5

New Thread : Thread[Three,5,main]

Three:5

One:4

Three:4

Two:4

One:3

Three:3

Two:3

One:2

Three:2

Two:2

One:1

Three:1

Two:1

One exiting

Three exiting

Two exiting

Main Thread Exiting

How do you find size of any object in java OR is there any operator or fun.. equivalent size of in c plus plus?

No, there is no such operator or function in Java that can tell you the amount of memory an object uses.

What will a parent of a child in your class say about you?

it depends on who the child is and if you have hurt that child teased that child and things like that

What is an instance of a class Red many definitions of a constructor But did not understand the exact working of a constructor What is the main use of constructor how it works?

The consttructor creates a new instance of the class

for example the class shown below does not exist until the constructor is called, where it sets the class up for first use.

Class Dog

{

int _legs, _eyes;

string _breed;

//CONSTRUCTOR, this takes an input from the user which sets the breed of the dog, and sets the default number of legs and eyes.

public Dog(input)

{

_legs = 4;

_eyes = 2;

_breed = input;

}

}

if the user calls the constructor with the string "Labrador", that is one instance of the class, if the user calls it again with the string "terrier" that is another instance. the class is constructed like this:

//Class instancename = New class(parameters);

Dog lab = New Dog("Labrador");

hope this helps

Steve