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 parameter in java?

It actually doesn't. You see... it actually takes the orange and once its completed its 340th task, it evaluates the juice out of it. Now, about the transmit part, Javas are actually mammals that used to exit a long while back.

What are applets?

An applet is an application designed to be transmitted over the Internet and executed by a Java-compatible Web browser.

Applets are small applications that are accessed on an Internet server, transported over the Internet, automatically installed, and run as part of a Web document.

Applet has no main method.

Program to find the sum of harmonic series?

Let's assume that you want the sum of the general harmonic series:

sum(n=0,inf): 1/(an+b)

Since we know that the harmonic series will converge to infinity, we'll also assume that you want the sum from 0 to n.

double genHarmonic(const double n, const double a, const double b) {

double sum = 0.0;

// perform calculations

int k;

for(k = 0; k <= n; ++k) {

sum += 1.0 / (a * k + b);

}

return sum;

}

Telephone bill program written in java source codes?

I Want the Java Coding For Creating Phone Bill & Customer Name & Her Details, Plz Send The Coding For Creating Phone Bill,

Thank You

Regards

Suresh

What is an attribute in java?

The attributes in schema are defined like kid elements. In order to have the attributes the element has a complex type.

Attribute are the set of data elements that define the object. The declaration of an object attribute take the following form:

<modifier> <type> <name> = initial_value;

What is the use of keyword virtual?

New is used to dynamically allocate memory in C++. It will also call the default constructor of a class that is created with it.

int *array; // First declare a pointer

array = new int [5] // Allocate enough memory for a 5 element int array

// To deallocate your memory when you are finished with it, you must call delete on your pointer

delete[] array;

myClassType *mct = new myClassType; // example for class

...

delete mct; // class delete

The virtual keyword means that the class has a static virtual table (vtable) containing function pointers for each type of the class. This enables polymorphism by allowing a pointer to the base class to be assigned an address of any instance of the class in the hierarchy, and then invoking a method through that pointer - which will properly choose the correct method for that class type. Virtual also ensures that the constructors and destructors are invoked in the correct order.

How do you write java program to generate the number triangle?

Save the following file as PascalTriangle.java:

public class PascalTriangle {

public static void main(String args[]) {

int x = 6;

int triangle[][] = new int[x][x];

for (int i = 0; i < x; i++) {

for (int j = 0; j < x; j++) {

triangle[i][j] = 0;

}

}

for(int i = 0; i < x; i++) {

triangle[i][0] = 1 ;

}

for (int i = 1; i < x; i++) {

for (int j = 1; j < x; j++) {

triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j];

}

}

for (int i = 0; i < x; i++) {

for(int j=0;j<=i;j++) {

System.out.print(triangle[i][j]+ " ");

}

System.out.println();

}

}

}

answer 2:

import java.util.*;

class pascal

{

protected static void main()throws Exception

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the limit: ");

byte a=sc.nextByte();

sc.close();

String l[]=new String[a];

for(byte i=0;i<a;i++)

l[i]="";

l[0]="1";

l[1]="1 1";

for(byte i=2;i<a;i++)

{

for(byte j=0;j<(i+1);j++)

{

if(j==0j==i)

l[i]+="1 ";

else

{

StringTokenizer st=new StringTokenizer(l[i-1]);

byte k=(byte)st.countTokens(),n=0;

String w[]=new String[k];

for(byte f=0;f<w.length;f++)

w[f]="";

for(byte f=0;f<l[i-1].length();f++)

{

if(l[i-1].charAt(f)==' '){

n++;

continue;

}

w[n]+=l[i-1].charAt(f);

}

n=0;

int x=Integer.parseInt(w[j-1])+Integer.parseInt(w[j]);

l[i]+=(String.valueOf(x)+" ");

}

}

}

for(byte i=0;i<l.length;i++)

{

System.out.println();

for(byte j=a;j>=i;j--)

System.out.print(" ");

for(byte j=0;j<l[i].length();j++)

System.out.print(l[i].charAt(j));

}

}

}

Write a program in java to take one's full name and print its initials?

public class suthagar {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

String[] names={"suthagar","mani","kalai"};

String[] address={"pondy","vilupuram","pondy"};

String[] possion={"manager","clerk","assicent manager"};

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

{

System.out.println("Name"+(i+1)+"="+names[i]);

System.out.println("Address"+(i+1)+"="+address[i]);

System.out.println("Possion"+(i+1)+"="+possion[i]);

}

}

}

Do while loop uses?

The DO WHILE loop is like the WHILE loop very much, except for one thing. The WHILE loop is like an IF loop but it keeps on going. The WHILE loop needs to start, so the beginning, when you are setting the conditions, is exactly the same. When the WHILE loop is done, it goes back to right before the conditions. The DO WHILE loop starts the WHILE loop so that you can have a WHILE loop that does not start with conditions, but instead, needs conditions to keep on going. This might not be the exact syntax, because if it doesn't work try it without the semicolon after the while. And anyways, if that doesn't work, I started with C++, not C.

do

CONTENT

while(CONDITIONS);

The WHILE loop goes back to the DO if the conditions are matched. The DO happens without any conditions.

:) :) :)

Programming to calculate a factorial number?

double factorial(double N)

{

double total = 1;

while (N > 1)

{

total *= N;

N--;

}

return total; // We are returning the value in variable title total

//return factorial;

}

int main()

{

double myNumber = 0;

cout << "Enter the number: ";

cin >> myNumber;

cout << endl << "Factorial of N is: " << factorial(myNumber);

return 0;

}

What is the function of break in java programming?

The break keyword is used to prematurely exit the current block of code. Java only allows it to be used in the body of a loop or switch, and is helpful when you want a special reason to stop executing that code.

Here is an example, in which we will search through an array of integers for a particular value. If that value is found, we will print out its location in the array and then stop running.

void search(int num, int[] array) {

// Store the position of num in array (or -1 if it wasn't found)

int position = -1;

// Here is our search loop

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

if(array[i] == num) {

// If we find the number, store its position and exit the loop

position = i;

break;

}

}

// Print out our results

if(position >= 0) {

System.out.println(num + " found at position: " + position);

}else {

System.out.println(num + " was not found in the array");

}

}

Why is a just-in -time compiler useful for executing Java programs?

I'm not sure if it's "useful" as much as it is the fact of it being how the Java compiler works.

However, there's a GCC frontend for compiling Java to native machine code rather than bytecode.

Why system class is imported on java?

Some classes are imported by default, because they are used so often.

The java.lang package is automatically imported. According to the Java API, java.lang "provides classes that are fundamental to the design of the Java programming language."

See the related links section below for a link to a list of all classes currently in java.lang.

What is the full form of J2EE?

"Java" refers to both a language and a platform. The runtime and libraries that comprise the platform are based on the Java language and come in 3 flavors: Java SE (Standard Edition): Formerly J2SE but renamed to Java Standard Edition when the Java 2 convention was dropped with the release of Java 5 (formerly J2SE 1.5). It contains a good all-around mix of general purpose libraries including JDBC (Java Database Connectivity), JNDI (Java Naming Directory Interface), RMI (Remove Method Invocation), AWT, and Swing. Java EE (Enterprise Edition): Formerly J2EE (see above). It includes Java Standard Edition plus most of the other Java technologies including JavaMail, Activation, JAXB (Java API for XML Binding), Servlets, JSF (Java Server Faces), JMS (Java Messaging Service), EJB (Enterprise Java Beans), and others. Most of the APIs are very component-oriented and are intended to provide pluggable interfaces for business components to form robust, distributed internet applications. Java ME (Micro Edition): Formerly J2ME. It includes most of Java SE and some additional APIs for handheld devices. Java Enterprise Edition is based on Java, but includes a larger set of libraries than Java Standard Edition, which to most people is synonymous with the word "Java." Note that many of the technologies featured in Java Enterprise Edition are available separately and can be added to the Java Standard Edition platform as needed. Hi! Java is a language and j2ee is a plateform which implements java language. Java can be divided into 3 categories
1.core java
2.advanced java
3.J2EE
core java and advanced java are the standard editions of java where as J2EE is the enterprise edition
witout completing core and advanced java u will not be able to understand J2EE

What is the use of const keyword?

Marks constant data, ie data that should not be changed.

Why is inheritance useful?

Inheritance is a powerful feature provided by the Java programming language that allows classes to extend or re-use the features of other existing java classes. This way we can avoid code duplication. Instead of copying all the source code from one class, we can extend that class to ensure that all the functionalities of that class is available in our new class.

Why should the java main method has the return type as void?

A void method is one that returns no value. The Java main() method is the first method to be called, therefore it doesn't need to return a value to another Java method, therefore it is declared as void. If something needs to be returned to the operating system, this is done differently, not by "returning a value" in the sense of Java.

Explain the different object based and object oriented concepts in C?

A data structure (declared with the struct keyword) should be used to define a plain-old data type (a POD). A POD is a class, but one that has trivial construction and no invariants or methods (there is no encapsulation). PODs are primarily used for compatibility between C++ and C code, since C has no understanding of objects.

Which one executed first static block or static methods in java?

Static Blocks are always executed first.

A static block is executed when your class is charged but a static method is executed only when is called, therefor first the class is charged and then is executed a method.

How many ways are there to pick n objects from n objects if order does matter?

There is a mathematical function called "factorial", and it is denoted by "!" (the exclamation mark). The factorial is when you multiply a number by every number before it, all the way down to 1.

Eg: 5! = 5*4*3*2*1=120

So, when you choose n objects in random order, at first you have n choices. After that, you have n-1 choices left, and after that, then you have n-2 choices left, and so on.

So the answer to the question "How many ways are there to pick n objects from n objects if order does not matter is: n!

where n! = n*(n-1)*(n-2)*(n-3)*(n-4) . . . (3)*(2)*(1).

* * * * *

That is the number if the order DOES matter.

If the order does NOT matter, as the question requires, the answer is 1.

How can be different forms of polymorphism achieved?

  1. Implicit Parametric Polymorphism
  2. Subtype Polymorphism
  3. Explicit Parametric Polymorphism

To Write program in Java to create applets to Create a color palette with matrix of buttons using applet viewer?

/* <applet code=palette height=600 width=600>

</applet> */

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

public class palette extends Applet implements ActionListener,ItemListener

{

Button[] colors;

Checkbox foreground,background;

TextArea workarea;

CheckboxGroup cbg;

Panel buttonpanel,checkpanel,palettepanel;

String colour;

public void init()

{

buttonpanel=new Panel();

buttonpanel.setLayout(new GridLayout(3,3));

colors=new Button[9];

colors[0]=new Button("RED");

colors[1]=new Button("GREEN");

colors[2]=new Button("BLUE");

colors[3]=new Button("CYAN");

colors[4]=new Button("ORANGE");

colors[5]=new Button("WHITE");

colors[6]=new Button("BLACK");

colors[7]=new Button("YELLOW");

colors[8]=new Button("PINK");

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

{

colors[i].addActionListener(this);

buttonpanel.add(colors[i]);

}

checkpanel=new Panel();

checkpanel.setLayout(new FlowLayout());

cbg=new CheckboxGroup();

foreground=new Checkbox("ForeGround",cbg,true);

background=new Checkbox("BackGround",cbg,false);

foreground.addItemListener(this);

background.addItemListener(this);

checkpanel.add(foreground);

checkpanel.add(background);

workarea=new TextArea(8,40);

workarea.setFont(new Font("Garamond",Font.BOLD,20));

palettepanel=new Panel();

palettepanel.setLayout(new BorderLayout());

palettepanel.add(workarea,BorderLayout.CENTER);

palettepanel.add(checkpanel,BorderLayout.EAST);

palettepanel.add(buttonpanel,BorderLayout.SOUTH);

add(palettepanel);

}

public void itemStateChanged(ItemEvent ie)

{

}

public void actionPerformed(ActionEvent ae)

{

colour=ae.getActionCommand();

if(foreground.getState()==true)

workarea.setForeground(getColour());

if(background.getState()==true)

workarea.setBackground(getColour());

}

public Color getColour()

{

Color mycolor=null;

if(colour.equals("RED"))

mycolor=Color.red;

if(colour.equals("GREEN"))

mycolor=Color.green;

if(colour.equals("BLUE"))

mycolor=Color.blue;

if(colour.equals("CYAN"))

mycolor=Color.cyan;

if(colour.equals("ORANGE"))

mycolor=Color.orange;

if(colour.equals("WHITE"))

mycolor=Color.white;

if(colour.equals("BLACK"))

mycolor=Color.black;

if(colour.equals("YELLOW"))

mycolor=Color.yellow;

if(colour.equals("PINK"))

mycolor=Color.pink;

return mycolor;

}

}

Java program to find greatest among 4 numbers?

The cheap way out, just use what java has available: the Arrays class (of course you have to import it first). int[] array = {42, 12, 1337, 0}; // the four numbers to be sorted Arrays.sort(array); //Now array is sorted

// array should now contain {0, 12, 42, 1337}; Of course there are other ways to sort, especially writing algorithms yourself, but that's such a bore. Just for reference I have attached links to common sorts below.