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

Abstract method with example in java?

An abstract in java is used to specify that the class/function is not yet complete. When a class in declared as abstract it means that it is not meant to be instantiated (you can't create variables of that type). This is because they are meant to be more of a guideline for other classes. When a class extends an abstract class it must either define all of the abstract methods from the abstract class or it must also be declared as an abstract class itself.

What are the main differences between ASCII code and Unicode?

Range. ASCII has only 128 characters (95 visible, 33 control), UniCode has many-many thousands.

Note: UniCode includes ASCII (first 128 characters), and ISO-8859-1 (first 256 characters). (From these you can deduct that ISO-8859-1 also includes ASCII.)

What is access modifier?

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.

Static keyword in java?

A Static method in Java is one that belongs to a class rather than an object of a class. Normal methods of a class can be invoked only by using an object of the class but a Static method can be invoked Directly.

Example:

public class A {

.....

public static int getAge(){

....

}

}

public class B {

.....

int age = A.getAge();

}

In class B when we wanted the age value we directly called the method using the instance of the class instead of instantiating an object of the class.

Tip:

A static method can access only static variables. The reason is obvious. Something that is common to a class cannot refer to things that are specific to an object...

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..........