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

What is purpose of keyword new?

The keyword new is used to instantiate or create Java class objects.

ex:

String empName = new String("Rocky");

The above statement creates a new String object of name empName and value as Rocky

What is the difference between object-oriented and procedural programming?

Procedural programming can sometimes be used as a synonym for imperative programming. To a programming paradigm based upon the concept of the procedure call. Procedures, also known as routines, subroutines, methods, or functions (not to be confused with mathematical functions, but similar to those used in functional programming) simply contain a series of computational steps to be carried out. Any given procedure might be called at any point during a program's execution, including by other procedures or itself. The important features of Procedural Programming. 1. Programs are organized in the form of subroutines and all data items are global. 2. Program controls are through jump(goto) and calls to subroutines 3. Subroutines are abstracted to avoid repetitions. 4. Suitable for medium sized software application 5. Difficult to maintain and enhance the program code. K E Narayana

How do you write a program in java to check a number is neon number?

class neonn

{

; public static void check()throws IOException

; {

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

; int num;

; System.out.println("Enter the number to be checked!");

; num=Integer.parseInt(br.readLine());

; int square;

; square=num*num; //squaring the number

;

; int sum=0;

;

; String sqs=Integer.toString(square);

; for(int i=0; i<sqs.length(); i++)

; sum+=Integer.parseInt(sqs.substring ( i,i+1 ) ) ;

;

; if (sum==num) //checking if the sum of the square is equal to the number entered

; System.out.println(num+" is a Neon Number!"); // if yes. It is neon

; else

; System.out.println(num+" is not a Neon number!"); //otherwise not

;

; }

;

}

What is the difference structured programming language and java?

There is no difference between procedural programing language & structure programing language

What is the implicit name of the parameter that gets passed into the set method of class in c?

Every non-static member function has a hidden pointer parameter named this which refers to the instance of the class the function was invoked against. For a given class, C, the type of the hidden this pointer is const C* but if the function is declared const, the pointer is const C* const. When referring to any class member, m, from within any non-static member function, this->m is implied.

What is overload protection?

It is protection installed to protect, usually motors, from going beyond the amperage capacities that were set down by the manufacturer's specifications of the motor. As a motor loads up to its rated HP it will operate within the motors amperage range. More loading on the motor will increase the amperage draw to a point where the motor's winding will start to burn or short out due to insulation breakdown of the motor coils. Over load protection is a settable device that will limit the current to a specific value. The setting on the over current device is the motor's FLA (full load amps). If the motor amperage goes higher that the set point the overload protection, the overload protection contacts will open and drop the motor's magnetic contactor off line. In some cases this could be an annoyance but it does save the motor from destroying itself.

What is difference between constant in c plus plus and final in java?

The final keyword can be used to modify a class, method, or variable.

When used on a variable, it means that variable cannot be changed once set.
When used on a method, it means that no subclasses may override that method.

Object and classes Use a person as an example?

A class is like a template. You can define a class "Person", which defines what type of data you want to store for a person - for example, for a computer game, the person's name his accumulated score, and how many lives he has left. The class might better be called "Player" in this case - but you can just as well store other data for a Person.

Then, you create objects for two different players. You declare variables player1 and player2, both of type "Person". It is in these variables - player1 and player2 - where you store specific information about individual persons.

A class is like a template. You can define a class "Person", which defines what type of data you want to store for a person - for example, for a computer game, the person's name his accumulated score, and how many lives he has left. The class might better be called "Player" in this case - but you can just as well store other data for a Person.

Then, you create objects for two different players. You declare variables player1 and player2, both of type "Person". It is in these variables - player1 and player2 - where you store specific information about individual persons.

A class is like a template. You can define a class "Person", which defines what type of data you want to store for a person - for example, for a computer game, the person's name his accumulated score, and how many lives he has left. The class might better be called "Player" in this case - but you can just as well store other data for a Person.

Then, you create objects for two different players. You declare variables player1 and player2, both of type "Person". It is in these variables - player1 and player2 - where you store specific information about individual persons.

A class is like a template. You can define a class "Person", which defines what type of data you want to store for a person - for example, for a computer game, the person's name his accumulated score, and how many lives he has left. The class might better be called "Player" in this case - but you can just as well store other data for a Person.

Then, you create objects for two different players. You declare variables player1 and player2, both of type "Person". It is in these variables - player1 and player2 - where you store specific information about individual persons.

How to declare a float variable in java?

it is the same as an int, String, or any of the others:

float myVar = 5.7f;

If you try to assign a decimal number you must place an "f" at the end, otherwise Java will assume you are trying to assign a double.

Why do need Unicode when you have Ascii?

ASCII only has 127 standard character codes and only supports the English alphabet. While you can use the extended ASCII character to provide a set of 256 characters and thus support other languages there's no guarantee that other systems will use the same code page, so the characters will not display correctly across all systems (the characters you see will depend upon which code page is currently in use). Moreover, some languages, particularly Chinese, have thousands of symbols that simply cannot be encoded in ASCII.

UNICODE encoding supports all languages and the first 127 symbols are also the same as ASCII, so all characters appear the same across all systems. UTF8 is the most common UNICODE encoding in use today because it uses one-byte per character for the first 127 characters and is therefore fully compliant with non-extended ASCII. If the most-significant bit is set then the character is represented by 2 or more bytes, the combination of which maps to the UNICODE encoding.

How are Structure passing and returning implemented by the complier?

When structures are passed as arguments to functions, the entire structure is typically pushed on the stack, using as many words as are required. (Programmers often choose to use pointers to structures instead, precisely to avoid this overhead.) Some compilers merely pass a pointer to the structure, though they may have to make a local copy to preserve pass-by-value semantics. Structures are often returned from functions in a location pointed to by an extra, compiler-supplied ``hidden'' argument to the function. Some older compilers used a special, static location for structure returns, although this made structure-valued functions non-reentrant, which ANSI C disallows

What are the features of java swing?

Swing is the next-generation GUI toolkit that Sun Microsystems has developed for the Java language. It is essentially a vast component framework built over parts of the older AWT component libraries used in Java 1.0 and 1.1. Swing is written in 100% Java; there are no native calls. Hence, it can run on any platform with a compatible Java virtual machine. 1. It provides Java programmers many new powerful components-- most of which we've been begging for since Java's inception. 2. It gives developers a chance to create a powerful, portable application that can not only target users on any Java-compatible platform, but also target their desired look-and-feel as well. 3. The distribution is easy to learn, but can also be used at varying levels of complexity to curtail to the programmer's wishes.

Does The statements within a while loop execute at least once?

No. If the loop condition is not satisfied then the loop would not be executed even once.

while(condition)

{

.....

/statements

.....

}

here,when the condition is true then the statements will be executed. Otherwise they would be skipped without being executed.

Only for do.. while loops this execution at least once holds good.

The data type of an item price?

I am assuming that the question is "What would the best data type to represent a price".

Although this is open for debate, in Java I think that the best data type for a price is double and the best data type in C# to be decimal.

I hope this answers your question.

How do you initialize an array variable in java program?

An array in java is a collection of items stored into a single unit. The array has some number of slots (elements), each slot in the array can hold an object or a primitive value. Arrays in java are objects that can be treated just like other objects in the language

Arrays can contain any type of element value , but we can't store different types in a single array. We can have an array of integers or an array of strings or an array of arrays.

To create an array in java ,use three steps

1. Declare a variable to hold the array

2. Create a new array object and assign it to the array variable

3. Store things in that array

What is finally statement in java?

Although try and catch provide a great way to trap and handle exceptions, we are left with the problem of how to clean up if an exception occurs. Because execution transfers out of the try block as soon as an exception is thrown, we can't put our cleanup code at the bottom of the try block and expect it to be executed if an exception occurs.

Exception handlers are a poor place to clean up after the code in the try block because each handler then requires its own copy of the cleanup code. If, for example, you opened a database connection somewhere in the guarded region, each exception handler would have to release the connection. That would make it too easy to forget to do cleanup, and also lead to a lot of redundant code. If you forget to close the connection in cases where an exception occurs, you will be left with orphan connections which can eventually crash your database. To address this problem, Java offers the finally block.

A finally block encloses code that is always executed at some point after the try block, whether an exception was thrown or not. Even if there is a return statement in the try block, the finally block executes right after the return statement is encountered, and before the return executes!

This is the right place to close your files, release your db connections, and perform any other cleanup your code requires. If the try block executes with no exceptions, the finally block is executed immediately after the try block completes. If there was an exception thrown, the finally block executes immediately after the proper catch block completes. Let's look at another pseudocode example:

1: try {

2: // This is the first line of the "guarded region".

3: }

4: catch(DatabaseDownException) {

5: // Put code here that handles this exception

6: }

7: catch(SomeOtherException) {

8: // Put code here that handles this exception

9: }

10: finally {

11: // Put code here to release any resource we

12: // allocated in the try clause.

13: }

14:

15: // More code here

As before, execution starts at the first line of the try block, line 2. If there are no exceptions thrown in the try block, execution transfers to line 11, the first line of the finally block. On the other hand, if a SomeOtherException is thrown while the code in the try block is executing, execution transfers to the first line of that exception handler, line 8 in the catch clause. After all the code in the catch clause is executed, the program moves to line 11, the first line of the finally clause. To summarize - THE FINALLY BLOCK WILL EXECUTE ALWAYS. There is actually a catch here about the finally block executing always, but I will leave you to ponder over it for sometime. We will look at it a little later.

What are the various access specifiers?

Three types of access specifier private , public ,protected

Can a double value be assigned to float variable?

THIS IS FOR JAVA i don't know about anything about other languages yes it can be assigned

the syntax is:

int (number) = (float) number

FOR EXAMPLE:

int = a;

a = (float ) 5.5;

if the (float) is not there then in Java it gives an error saying precision loss of data type

How do you declare data types?

typedef data_type data_name, for instance:

typedef int myDataType;

What is pointer in java?

There is no concept similar to pointers in Java. Pointers are a feature in C programming using which a programmer can access the memory. This was the cause of major catastrophic programming bugs. The creators of Java excluded this feature just to avoid such catastrophic bugs.

Java program to simulate a car?

import java.awt.*;

import java.util.*;

import java.applet.*;

/*

<APPLET CODE="Animation.JAVA" WIDTH=400 HEIGHT=300>

</APPLET>

*/

//The basic applet class.The applet shows 4 cars crossing each other at a square.

public class Animation extends Applet implements Runnable

{

Thread t;

//4 variables used to vary the car's positions.

int x1=0,x2=380,y1=50,y2=250;

public void start()

{

if(t==null)

{

t=new Thread(this,"New Thread");//New side Thread created on start of applet.

t.start();

}

}

public void stop()

{

if(t!=null)

{

t=null;//On stop of applet the created thread is destroyed.

}

}

//Implementation of method run() of Runnable interface.

public void run()

{

Thread t1=Thread.currentThread();

while(t==t1)

{

repaint();

try

{

Thread.sleep(100);

}

catch(Exception e)

{ }

}

}

public void paint(Graphics g)

{

setBackground(Color.cyan);

g.setColor(Color.BLACK);

x1=(x1+16)%400;

x2=x2-16;

y1=(y1+12)%300;

y2=y2-12;

if(y2<0)

y2=288;

if(x2<0)

x2=384;

//Draw the roads using 2 filled rectangles using black color.

g.fillRect(0,130,400,40);

g.fillRect(180,0,40,305);

//Draw the white colored lines.

g.setColor(Color.white);

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

{

if(i!=9 && i!=10)

g.drawLine(i*20,150,i*20+10,150);

}

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

{

if(j!=7 && j!=8)

g.drawLine(200,j*20,200,j*20+10);

}

//Draw 4 colored cars using filled round rectangles.

g.setColor(Color.red);

g.fillRoundRect(x2,152,20,8,2,2);

g.fillRoundRect(x1,140,20,8,2,2);

g.fillRoundRect(190,y1,8,20,2,2);

g.fillRoundRect(202,y2,8,20,2,2);

}

}

What is comparing an object or process to a standard?

finding meaning in data by looking for patters or trends