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

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.