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

Given a sorted array- 8 13 17 26 44 56 88 97. Using binary search method find the element 88. show the contents of high low and mid at each step?

The array has eight elements indexed 0 to 7. The middle element will be found at index (0+7)/2=3. Element 3 has the value 26, which is smaller than 88, so 88 must reside in the array starting at index 4 ending at index 7.

The array has four elements indexed 4 to 7. The middle element can be found at index (4+7)/2=5. Element 5 has the value 56, which is smaller than 88, so 88 must reside in the array starting at index 6 ending at index 7.

The array has two elements indexed 6 to 7. The middle element can be found at index (6+7)/2=6. Element 6 has the value 88. Thus 88 was found at index 6.

How do you calculate the point on the edge of a circle that corresponds to a degree given the radius of the circle?

public void getPoint(double r, double angle)

{

//cosine*hypotenuse=adjasent

double x = r * Math.cos (Math.toRadians(angle))//in radians;

//sine * hypotenuse =opposite

double y=r*Math.sin(Math.toRadians(angle))//also in radians;

System.out.println("( "+x+", "+y+" )");

}

How is interface instantiated in anonymous class for example new ActionListener?

They key word here is anonymous class. While ActionListener may be an interface, the anonymous class would be a subclass of ActionListener. It would be like creating a new class which implements ActionListener.

JButton button = new JButton("Press Me!");

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ev) {

System.out.println("PRESS");

}

});

Default constructor in java?

If you don't type a constructor into your class code, a default constructor will be automatically generated by the compiler. The default constructor is ALWAYS a no-arg constructor. (Obviously the compiler has no clue what all arguments you might want for your class. So it takes the safe way out with a no argument constructor)

A no-arg constructor is not necessarily the default (i.e., compiler-supplied) constructor, although the default constructor is always a no-arg constructor. The default constructor is the one the compiler provides! While the default constructor is always a no-arg constructor, you're free to put in your own no-arg constructor.

What is an unclosed string literal?

The error "unclosed string literal" means that you wrote a double quote " somewhere but you didn't write another double quote later on to close the string.

Note: You cannot start writing a string on one line and continue on another line, like this:

System.out.println("Hello

World");

If you absolutely want to distribute this over multiple lines, do it like this:

System.out.println("Hello "

+ "World");

How to write Java program for find longest word in a string?

class LongestWord

{

String str = "Ram is intelligent boy";

String stringArray[] = str.split("\\s");

public String compare(String st1, String st2){

if(st1.length()>st2.length()){

return st1;

}

else{

return st2;

}

}

LongestWord(){

String word = "";

for(int i=0;i

if(i==0){

word = stringArray[0];

}

word = compare(word, stringArray[i]);

}

System.out.println("Longest word = " + word);

}

public static void main(String []args){

new LongestWord();

}

}

What is an example program in Bluej whether a number is a palindrome or not?

class test

{

public static void main(int num)

{ int num2=num;

int rnum=0;

while (num2>0)

{ int q=num2/10;

int dig=num2%10;

rnum = rnum*10+dig;

num2=q;

}

if (rnum==num)

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

else

System.out.println("Not a Palindrome number");

}

}

If else else sample programs java?

if (i==2)

if (j==2) System.out.println ("i==2 and j==2");

else System.out.println ("i==2 and j<>2");

else System.out.println ("i<>2");

What is containment in oop?

When an object in created within another object, the relationship between them is containment.

Why the index of an array be a positive number?

Since an array cannot contain a negative number of items, the size of an array must be at least 0. So if you ever tried to retrieve the element at a negative index in an array, it would automatically be understood to be out-of-bounds.

Conditional statement inside a conditional loop?

int i = 100;

while(i > 0) { // Conditional loop

--i;

if((i % 2) == 0) { // Conditional statement inside a conditional loop

System.out.println(i + " is even.");

}

}

Write a program to find the number of and sum of and sum of all integer greater than 100 and less than 200 that are divisible by 7?

This is a homework assignment. write your homework assignments for you because you have been given them so that you learn the skills you will need in life.

However, if while doing this assignment you have specific things you need help to understand WikiAnswers will be happy to answer these specific questions for you.

How do you make struts action class thread safe?

1.Only Use Local Variables

§The most important principle that aids in thread-safe coding is to use only local variables, not instance variables , in your Action class. Local variables are created on a stack that is assigned (by your JVM) to each request thread, so there is no need to worry about sharing them. An Action can be factored into several local methods, so long as all variables needed are passed as method parameters. This assures thread safety, as the JVM handles such variables internally using the call stack which is associated with a single Thread.

2.Conserve Resources

As a general rule, allocating scarce resources and keeping them across requests from the same user (in the user's session) can cause scalability problems. For example, if your application uses JDBC and you allocate a separate JDBC connection for every user, you are probably going to run in some scalability issues when your site suddenly shows up on Slashdot. You should strive to use pools and release resources (such as database connections) prior to forwarding