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 Write a java program to get and display all the information?

That depends a lot on what information you want to get, and where you want to get it from: from user input; from a text file; from some other kind of file; from a database; etc.

That depends a lot on what information you want to get, and where you want to get it from: from user input; from a text file; from some other kind of file; from a database; etc.

That depends a lot on what information you want to get, and where you want to get it from: from user input; from a text file; from some other kind of file; from a database; etc.

That depends a lot on what information you want to get, and where you want to get it from: from user input; from a text file; from some other kind of file; from a database; etc.

Is Java a top-down or bottom-up approach?

It is a programming language. s of course its a programming language with bottom up approach for programming.

because it follows oops concepts

What type of logical access control method allows you to define who can access an object and type of access that they will have to that object?

That functionality is not available in generic C++, it is a function of the operating system and is therefore platform-specific. Even so, user-credentials cannot be used to determine who can access an object unless you employ some form of biometric security such as fingerprint identification, or a physical security system such as keycards. In the absence of these facilities, you would have to force the user to confirm their credentials every time the object was accessed. After all, the user who originally logged into the system is not necessarily the user currently using the system.

What is rules of accessibility 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.

Why do you need a class in java?

A class, if designed properly, will provide a grouping of related data and common tasks. Rather than having arrays of primitives all over the place, classes allow us to keep various bits of associated information together.

A common example is a generic Person class...

Trying to keep a list of information about people together without classes will consist of several separate arrays of information:

String[] firstNames;

String[] lastNames;

int[] height;

int[] weight

Obviously, trying to keep these collections of data organized and synchronized will take a great deal of effort.

Compare that to using a Person class:

class Person {

String firstName;

String lastName;

int height;

int weight;

}

Then we only need to keep a single array up to date:

Person[] people;

What must computers have in order for it to execute Java programs?

You need a really old computer. Preferably one from 1980 or so. It should have a small monitor. The monitor should take up a lot of deskspace but have a small screen area. Go for purity - so get yourself the earliest version of a borland command line compiler.

I personally find a keyboard is very useful, although you could use dip switches instead . Some geeks swear by a mouse, but there is the possibility that it is a passing fad. You can't be certain that mice are still going to be used in 10 years time.

It would be nice if your PC had a harddrive and a processor.

If you are thinking of learning C++, why not learn assembler first.

In bluej can there be a method within a method?

No, Java only allows a method to be defined within a class, not within another method.

How do you declare variables during run-time in java?

by the use of constructor . we can initialize the variables in java.The name of the constructor should be same as the name of the class .

Is pascal high level language?

The original Pascal programming language was designed by Niklaus Wirth between 1968 and 1969, published in 1970. Object Pascal was developed in 1985 by Larry Tessler, in consultation with Wirth.

How can you fix an ArrayIndexOutOfBoundsException in java?

This is very common exception and name of the exception class tells exactly what kind of problem you have. If you would look into stack trace, which should have been generated too you would be able to find exact place where it happened.

The problem is that "Array Index Out Of Bounds". This means that you used index on array which is invalid. That could negative number, because all arrays starts from 0. If you array has N items and you will try to get item with index N or higher you will get this exception too. Only available indexes are from 0 to N - 1, where 0 points to the first item and N - 1 to the last one.

What is static function and static class?

Static function are function only visible to other function in same file Function outside the class can access, useful whenever we need to have functions which are accessible even when the class is not instantiated.

It is perfectly legal to any instance variable inside of a static method?

No. You will get compilation errors. The complier will complain that you are trying to access non static variables from inside a static method.

A static method can access only static variables.

Write a program to print n natural numbers using for loop?

//to display 'n' natural numbers using for loop......(in C).....

#include<stdio.h>

main()

{

int n,i;

printf("\n Enter the range......Please...\t");

scanf("%d",&n);

printf("\n Range of Natural Numbers.....\t");

for(i=1;i<=n;i++)

{

printf("\t%d",i);

}

}

How do you stop normal execution of finally block?

Theoretically, the finally block will execute no matter what. But practically, the following scenarios can prevent the execution of the finally block.

* The death of thread

* Use of system.exit()

* Turning off the power to CPU

* An exception arising in the finally block itself

Which protocol provides connectionless network service?

In internet protocol suite UDP is the connectionless protocol. There is no initial communication between client and server. UDP will not check whether the transmission was successful.

How do you write a program to accept a month number and display a maximum number of days?

DisplayMonth( int month ) //base 0

{

switch( month )

{

case 0: printf("January\n"); break;

case 1: printf("February\n"); break;

case 2: printf("March\n"); break;

.... and so on

}

}

enjoy

Which is faster array or arraylist?

Array Lists and Arrays can be compared to one another. Actually an Array List is nothing but a growable array that provides us with a lot more features than traditional Arrays. Apart from this - they are both same - used to hold a group of java objects.

Write an application that displays in the command window a box an oval an arrow and a diamond using asterisks as follows?

the code for the box is:

# include <iostream>

using namespace std;

void main ()

{

cout << "*********\n";

cout << "*\t*\n";

cout << "*\t*\n";

cout << "*\t*\n";

cout << "*\t*\n";

cout << "*\t*\n";

cout << "*\t*\n";

cout << "*\t*\n";

cout << "*********\n";

the code for the oval is:

# include <iostream>

using namespace std;

void main ()

{

cout << " ***\n";

cout <<" * *\n";

cout <<"* *\n";

cout <<"* *\n";

cout <<"* *\n";

cout <<"* *\n";

cout <<"* *\n";

cout <<" * *\n";

cout << " ***\n";

the code for the arrow is:

# include <iostream>

using namespace std;

void main ()

{

cout << " * \n";

cout <<" ***\n";

cout <<"*****\n";

cout <<" * \n";

cout <<" * \n";

cout <<" * \n";

cout <<" * \n";

cout <<" * \n";

the code for the diamond:

# include <iostream>

using namespace std;

void main ()

{

cout << " *\n ";

cout <<" * *\n";

cout<<" * *\n";

cout<<" * *\n";

cout<<"* *\n";

cout<<" * *\n";

cout<<" * *\n";

cout <<" * *\n";

cout << " *\n ";

}

Difference between function overloading and default arguments?

A default constructor is one where no arguments are declared or required. Thus if all arguments have defaults then it is still a default constructor, but one that can also serve as an overloaded constructor.

Consider the following which has two constructors, one with no arguments (the default) and one with two arguments (an overloaded constructor):

struct A

{

A () : x (42), y (3.14) {}

A (const int a, const double b) : x (a), y (b) {} int x;

double y;

// ...

};

We can invoke these two constructors as follows:

A a; // invokes default constructor (a.x is 42, a.y is 3.14).

A b (0, 1.0); // invokes overloaded constructor (b.x is 0, b.y is 1.0).

Since both constructors are essentially doing the same thing, they can be combined into a single constructor -- we simply make the 'magic numbers' the default values of the overloaded constructor:

struct A

{

A (const int a=42, const double b=3.14): x (a), y (b) {}

int x;

double y;

// ...

};

A a; // a.x is 42, a.y is 3.14.

A b (0, 1.0); // b.x is 0, b.y is 1.0.

As far as the calling code is concerned, nothing has changed, but the class declaration is simplified by removing a redundant constructor.

Program in Java to illustrate the function overloading?

Below is an example of method overloading which returns the sum of two number types. Each method performs the calculation and returns a value in a different type.

int sum(final int a, final int b) {

return a + b;

}

long sum(final long a, final long b) {

return a + b;

}

float sum(final float a, final float b) {

return a + b;

}

double sum(final double a, final double b) {

return a + b;

}

What is the logical abstrect base class for a class called CricketPlayer?

A logical abstract base class for a class called CricketPlayer could be Batsman class or Bowlerclass.

Can you declared constructor as private?

If you declare the main method anything other than public, it will not run.

If you declare main method as private, you would not be able to execute the class as a standalone java program. Any java class that needs to be executed as a standalone file needs to have a main method that is public, static and returns a void. Otherwise the Java compiler would not recognize the file as an executable standalone java file and would not allow you to run it.

How do you convert capital string to small in Java?

To convert a String object to lowercase in Java, use the toLowerCase() method. "HELLO".toLowerCase() returns a new String: "hello".