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 are the people of java called?

Java is an island in the chain called Indonesia, so people who live on this island are called " Indonesians"

To find Armstrong number in java?

/*Program to find whether given no. is Armstrong or not. Example : Input - 153 Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */ class Armstrong{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); int n = num; //use to check at last time int check=0,remainder; while(num > 0){ remainder = num % 10; check = check + (int)Math.pow(remainder,3); num = num / 10; } if(check == n) System.out.println(n+" is an Armstrong Number"); else System.out.println(n+" is not a Armstrong Number"); } }

What Example of structured programming?

C is a structured programming language. PHP, COBOL is also a structured programming language. These languages follow a top down approach.

What are the differences between class and abstract class?

Below is the main difference between the 3 components:

  • Concrete class - Provides implementation for all its methods & also for methods from extended abstract classes or implemented interfaces
  • Abstract class - Does not provide implementation for one or more of its methods
  • Interface - Does not provide implementation for any of its methods

Examples of codes in java?

public class Hello
{//opens the class
public static void main(String args[])
{//opens the main method
System.out.println("Hello World");
}//closes the main method

}//closes the class







Note: The compiler all the sentences that have "//" before them.

What is a transient variable?

Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the val ue of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null

Flow chart for addition of two matrices?

For the resulting matrix, just add the corresponding elements from each of the matrices you add. Use coordinates, like "i" and "j", to loop through all the elements in the matrices. For example (for Java; code is similar in C):

for (i = 0; i <= height - 1; i++)
for (j = 0; j<= weidht - 1; j++)
matrix_c[i][j] = matrix_a[i][j] + matrix_b[i][j]


What is an escape character in Java?

The escape character, the back slash: \, is the character that signals the following character is not what it normally means, i.e. as a reserved symbol, or as a new symbol.

The uses of the escape character include:

In Strings when " or ' is a required part of the string

String example1 = "She said,"Hello""; //the escape sequence signifies the " is actually //a " not the end of the String literal.

In Formatting Strings

\n means new line

\t means tab

i.e.

System.out.println("Hello\nHow are you?\tFine thank you.");

// Prints

// Hello

// How are you? [tab] Fine thank you.

And of course the really idiosyncratic one:

When the back slash is essential to a string, and you don't want it to be a escape character:

\\ means \

i.e.

System.out.println("\");

// Prints \

Why to use 'import' in java?

The import statement in Java allows to refer to classes which are declared in other packages to be accessed without referring to the full package name. You do not need any import statement if you are willing to always refer to java.util.List by its full name, and so on for all other classes. But if you want to refer to it as List, you need to import it, so that the compiler knows which List you are referring to.

Classes from the java.lang package are automatically imported, so you do not need to explicitly do this, to refer to String, for example.

How do you install java script on Android phone?

JavaScript comes pre-installed with the browser that Android runs by default. It cannot be "installed" and "uninstalled" on its own.

You may be trying to install Java, the programming language and VMs.

Real time example of circular queue?

Technically that's a statement, not a question, but check this out

http://en.wikipedia.org/wiki/Circular_buffer

Basically, any operating system uses these for loading files into. The basic idea is that you have a fixed chunk of memory to work with.

How many simple data types are there?

There are a total of 8 simple or primitive data types in Java. They are:

  • byte
  • short
  • int
  • float
  • double
  • boolean
  • long and
  • String

Why we use super in java?

The keyword super is used to refer to the parent class instance of the current class.

Lets say we have a class

class A extends B {

...

public void getName(){

}

...

}

Lets assume the parent class B also has a method getName()

Inside class A if you call getName() it would by default call the current class's method. To make the JVM intentionally call the super class method we can use super

if we say super.getName() then the parent class instance of the method would be called.

Write a program to find gcd using recursive method in java?

for two positive integers:

public static int gcd(int i1, int i2) {

// using Euclid's algorithm

int a=i1, b=i2, temp;

while (b!=0) {

temp=b;

b=a%temp;

a=temp;

}

return a;

}

How do you count the number of words in a string?

To find the length of the string we use length method. The length property returns the length of a string (number of characters we use).The length of an empty string is 0.

For example:

function myFunction() {

var str = "Hello World!";

var n = str.length;

Hope this hepls.

Three address code in compiler design?

prod=0;

i=1;

do

{

prod = prod +a[i] * b[i];

i=i+1;

} while(i<=20);

Write a menu driven program in java to find area of different shapes. 1. Circle 2. Triangle 3. Rectangle?

Remember that the area of a rectangle is width * height:

static int getArea(Rectangle r) {

return r.width * r.height;

}

Why java is not open source?

Many makers of software have a rather large financial investment into their software, the making of it as well as the invention of intellectual property that defines its core functionality. It's a business, and these businesses hope to gain back money from selling the software.

The open source market allows earning money through secondary channels, such as installation and runtime support, consultation, advertisement, and offers little protection of trade secrets, such as the secret and unique algorithm that lies at the center of the (hypothetical) lottery number prediction software.

Java program to find compound interest?

public class SimpleInterest{

float principal,intRate, numOfYears;

public void setPrincipal(float principal){

this.principal = principal;

}

public void setIntRate(float intRate){

this.intRate = intRate;

} public void setNumOfYears(float numOfYears){

this.numOfYears = numOfYears;

} public float calculateSimpleInterest(){

return (this.principal * this.intRate * this.numOfYears) /100; } public static void main(String argv[]){

float principal,intRate, numOfYears;

SimpleInterest simpIntObj = new SimpleInterest();

principal = Float.parseFloat(argv[0]);

intRate = Float.parseFloat(argv[1]);

numOfYears = Float.parseFloat(argv[2]);

simpIntObj.setPrincipal(principal);

simpIntObj.setIntRate(intRate);

simpIntObj.setNumOfYears(numOfYears);

System.out.println ("Principal = "+principal);

System.out.println ("Interest Rate = "+intRate);

System.out.println ("Num of Years = "+numOfYears);

System.out.println ("Simple Interest Amount = "+simpIntObj.calculateSimpleInterest());

} }

String reverse program with single string and without using library functions in java?

You can create a separate string initially empty. Then using a loop, start at the end of the string and add it to the end of the other string. At the end of the loop, the other string would contain the reverse.

What are the advantage of data type double over data type int?

Some Clarityint data type is that of an integer, positive and negative whole numbers. The range of this data type is limited to -2,147,483,648 -- +2,147,483,647

double data type is: a double precision floating point number, positive and negative, and covers a much larger range.

However there are limitations to the precision of any representation of a floating point number, because all floating point representations are based on negative powers of 2 and the sums of negative powers of 2 i.e. 1/2 is represented as 2-1, 1/4 is represented as 2-2, but 1/3 is the sum of 1/4 + 1/16 + 1/64, etc (the sum of all negative even powers of 2) to the limit of the precision provided by the floating point representation.

Where the double outweighs the int data type is that it can express very large integer numbers without loss of precision.

In terms of processing time to perform operations on each data type, there are no benefits in using the double - it occupies 64 bits (8 bytes) of RAM vs 32 bits (4 bytes) of RAM for the int.

Original answerAs It Is Quite Clear that The range Of Double pricision

Number IS More Than that Of INT....So When We use Double

Over The int ...its Whole Space (that is reserved Somewhere

in the Memory that is Further recalled By Compiler) Just

Gets double of it.........

Benefit is.......Its useful In Program Codes To Avoid BUGs..

Loss Is..........takes DOUBLE Space in memory Allocation as compared to INT..........

String concaination program using pointers in C?

#include<stdio.h>

#include<conio.h>

void main()

{

char a[5][10];

int i;

clrscr();

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

{

printf("enter %d string",i+1);

scanf("%s",&a[i]);

}

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

{

printf("\n%s",a[i]);

}

getch();

}

Write a program that accepts a number and output its equivalent in words?

/*mycfiles.wordpress.com
program to convert digits to character*/
#include
#include
void main()
{
int a[5],i,n;
clrscr();
cout<<"Enter the Value";
cin>>n;
for(i=4;i>=0;i--)
{
a[i]=n%10;
n=n/10;
}
for(i=0;i<5;i++)
{
if(a[i]!=0)
{
switch(a[i])
{
case 0:cout<<"Zero";
break;
case 1:cout<<"One";
break;
case 2:cout<<"Two";
break;
case 3:cout<<"Three";
break;
case 4:cout<<"Four";
break;
case 5:cout<<"Five";
break;
case 6:cout<<"Six";
break;
case 7:cout<<"Seven";
break;
case 8:cout<<"Eight";
break;
case 9:cout<<"Nine";
break;
}
}
}
getch();
}


------------------------------------------------------------------------------------


Program to Convert Numbers into Words

#include

void pw(long,char[]);
char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","
eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","
fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","
seventy"," eighty"," ninety"};


void main()
{
long n;
clrscr();
printf("
Enter any 9 digit no: ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
pw((n/10000000),"crore");
pw(((n/100000)%100),"lakh");
pw(((n/1000)%100),"thousand");
pw(((n/100)%10),"hundred");
pw((n%100)," ");
}
getch();
}


void pw(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}


// for any query visit
// "http://www.c.happycodings.com/Beginners_Lab_Assignments/code51.html"

Program to Convert Numbers into Words

#include

void pw(long,char[]);
char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","
eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","
fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","
seventy"," eighty"," ninety"};


void main()
{
long n;
clrscr();
printf("
Enter any 9 digit no: ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
pw((n/10000000),"crore");
pw(((n/100000)%100),"lakh");
pw(((n/1000)%100),"thousand");
pw(((n/100)%10),"hundred");
pw((n%100)," ");
}
getch();
}


void pw(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}


// for any query visit
// "http://www.c.happycodings.com/Beginners_Lab_Assignments/code51.html"

Why applet tag is used in java program?

Applets are designed to be embedded within web browsers. The obvious advantage here is the ability to run a Java program directly in your web browser, without having to manually launch a completely separate program.

What is inheritence in java?

Inheritance is an object oriented feature supported by Java wherein the features of one Java class can be inherited/made available in another class. This creates a parent child relationship between these 2 classes. Class Inheritance in java mechanism is used to build new classes from existing classes. The inheritance relationship is transitive: if class x extends class y, then a class z, which extends class x, will also inherit from class y. Object-oriented programming allows classes to inherit commonly used state and behavior from other classes.

Example:

public class Parent {

private String name = "Rocky";

public String getName(){

return this.name;

}

}

public class Child extends Parent {

public static void main(String[] args){

System.out.println("Name in Parent is: " + getName());

}

}

Here the getName() method is available only in the parent class but is directly used in the child class because the method is public and is directly accessible to the child class since it has extended the parent class.

Benefits of Inheritance:

One of the key benefits of inheritance is to minimise the amount of duplicate code in an application by sharing common code amongst several subclasses. Where equivalent code exists in two related classes, the hierarchy can usually be refactored to move the common code up to a mutual superclass. This also tends to result in a better organisation of code and smaller, simpler compilation units.

Inheritance can also make application code more flexible to change because classes that inherit from a common superclass can be used interchangeably. If the return type of a method is superclass