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 platform independent?

ANSWER:

Platform independence means executing a code irrespective of the Operating System on which it is being executed.

Java is called a platform independent language because

# The output of the JAVA compiler is bytecode which is not directly executable. # the bytecode is then interpreted by the JVM on respective OS. The bytecode generated after compilation can be executed on any machine with any OS with the help of JVM.

e.g. U write a simple java program ("samp.java") and compile it, u get a "samp.class" file after compiling without any errors, now you can execute this program on windows OS or Linux or Macintosh which generates the same output and runs fine on all OS.

What loop should no execute if the test expression is false to begin with?

for loop and while loop need the expression to be true for further execution of the program.

How do you identify the character in a string is uppercase?

In order to find whether a character in a string is in uppercase or not, you need to use the ascii\unicode values of the character.

You may want to use the following code--

String str="Your Sample String Here"; //(say you have this string)

int l=str.length();

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

{

char ch=str.charAt(i);

if(ch>=65&&ch<=90)

//Since the values of block letters in ASCII are from 65 to 90

System.out.println(ch);

}

//This program basically prints out the block letters, but you can modify it as you like, by changing the statement after 'if' as you want

Which take a string as input and find its length?

strlen is the C library function that accepts a pointer to a char array and returns an integer specifying the number of characters (in bytes) of the array. This function is usually not used any more, because it does not support multi-byte characters, such as UTF-8.

Any method in a super class can be overridden in its subclass?

False.

Any method declared as final cannot be overridden by any subclasses.

You also cannot technically override a private method. While your subclass can have a method with the same definition as a private method in the superclass, it does not actually override that method.

What is generic class in java?

Generics allows a type for compile-time type safety means it helps detect errors at compile time and makes your code safe. Generics in Collections are the type of elements which it going to hold. It can be any Wrapper class or any user defined class.

What is the need to create an abstract class without abstract?

Actually there is no need & most importantly - you cannot create an abstract class without using the abstract keyword

What is the difference between null array and an empty array?

There is no null array as such. However, a pointer to an array may be nullified (pointing to zero) before memory is allocated to it, or after that memory is released. But the same is true of any pointer. That is, the pointer is NULL, not what it previously pointed to.

An empty array usually refers to a dynamic array for which no memory has yet been allocated (in other words, a null pointer). However, the term can also apply to static arrays or dynamic arrays that have been allocated memory, where every element is initialised with a value that has no significance. For instance, an array of natural numbers (positive integers greater than 0) might be initialised with the value 0 (a non-natural number) in every element to indicate that the array is empty. By contrast, individual elements could be set to zero to indicate which elements are available (an empty element as opposed to an empty array).

Is it compulsory to write static with void main?

Every C# application is started on the startup class' static Main method. Yes, it must be static, but void is not the only returned type. The 4 signatures:

static void Main();

static void Main(string[] arguments);

static int Main();

static int Main(string[] arguments);

Ideally, there should be one and only one Main method in your application.

What is the fundamental questions would you ask when designing forms and reports?

Without knowing the entire background to the form, can I -your customer- complete it without detailed help text? If not, consider using simpler/more common terms for frields.

Does it make sense considering your database design? If not, reconsider the form or your database.

Is it easy to program? If not, it could be more complex to a customer than you may think, or may be an incorrect way of approaching the problem at least.

Implementing stack operation using array representation with java program?

class MyStack implements Stack

{

private String a[]=new String[10];

private int top=0;

public void push(String value)

{

a[top]=value;

top++;

}

public String pop()

{

top--;

return a[top];

}

public int length()

{

return top;

}

public void print()

{

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

System.out.println(a[i]);

}

}

public class StackOperations

{

public static void main(String args[])

{

MyStack ms = new MyStack();

ms.push("silpa");

ms.push("arti");

ms.print();

System.out.print("popped element is ");

System.out.println(ms.pop());

System.out.print("Now stack is with: ");

ms.print();

}

}

Why does an abstract class often define methods WITHOUT actually implementing them?

Because, it wants the implementing or child class to take care of the actual implementation details.

Whether sms is connectionless or connection oriented?

I would say it is connectionless, as it sends the message to the person to revive it without establishing the connection first so there's no way to know if they revived it.

How can i check a null at the end of an character array in java?

A character array, by nature, is a primitive-type data array. It can't contain a null value. You cannot cast a char as a null.

char[] charArray = {'1','2','s',null}; //this doesn't compile.

However, if you have an array of Character objects, then it's possible.

Character[] charArray = {'1','2','s',null}; //this DOES compile

A proposed algorithm is to initialize a test boolean as false, then use a for loop to iterate through the array. Set the flag to true (and break the loop) based upon whether one of the objects you run into is null. What you do from there is up to what the rest of your code says.

Why runtime exceptions are not checked at compile time in java?

Compile time error is any type of error that prevent a java program compile like a syntax error, a class not found, a bad file name for the defined class, a possible loss of precision when you are mixing different java data types and so on.

A runtime error means an error which happens, while the program is running. To deal with this kind of errors java define Exceptions. Exceptions are objects represents an abnormal condition in the flow of the program. It can be either checked or unchecked.

How do you determine which is outer loop or inner loop of the Baltimore beltway?

The outer loop goes counter clockwise, while the inner loop goes clockwise. For example, if you're driving from Fairfax, VA to Washington, DC you're going on the inner loop, and on the way back you're taking the outer loop.

When iam using jfreechart for plotting a linechart can i give a point in y axis and find the exact chart intersection point at x axis?

final XYSeries series1 = new XYSeries("First");

series1.add(1.0, 1.0);

// series1.add(2.0, 4.0);

// series1.add(3.0, 3.0);

// series1.add(4.0, 5.0);

// series1.add(5.0, 5.0);

// series1.add(6.0, 7.0);

// series1.add(7.0, 7.0);

// series1.add(8.0, 8.0);

final XYSeries series2 = new XYSeries("Second");

series2.add(1.0, 1.0);

// series2.add(2.0, 4.0);

// series2.add(3.0, 6.0);

// series2.add(4.0, 8.0);

// series2.add(5.0, 4.0);

// series2.add(6.0, 4.0);

// series2.add(7.0, 2.0);

// series2.add(8.0, 1.0);

final XYSeries series3 = new XYSeries("Third");

series3.add(1.0, 1.0);

// series3.add(4.0, 3.0);

// series3.add(5.0, 2.0);

// series3.add(6.0, 3.0);

// series3.add(7.0, 6.0);

// series3.add(8.0, 3.0);

// series3.add(9.0, 4.0);

// series3.add(10.0, 3.0);

final XYSeriesCollection dataset = new XYSeriesCollection();

dataset.addSeries(series1);

dataset.addSeries(series2);

dataset.addSeries(series3);

JFreeChart chart = ChartFactory.createXYLineChart(

"Line Chart Demo 6", // chart title

"X", // x axis label

"Y", // y axis label

dataset, // data

PlotOrientation.VERTICAL,

true, // include legend

true, // tooltips

false // urls

);

XYPlot xyPlot = (XYPlot) chart.getPlot();

xyPlot.setDomainCrosshairVisible(true);

xyPlot.setRangeCrosshairVisible(true);

XYItemRenderer renderer = xyPlot.getRenderer();

renderer.setSeriesPaint(0, Color.blue);

return chart;

Which type of data uses the least bandwidth?

Primitive data types are smaller in size and hence are efficient in processing and use the least bandwidth.

What is the default scope of bean in Spring framework?

In the Spring framework, the default scope of a bean is singleton. This means that a single instance of the bean is created and shared across the entire Spring container, ensuring that all requests for that bean return the same object. If a different scope is needed, such as prototype, request, session, or application, it can be specified using annotations or XML configuration.

Write a program to find all triad numbers below 1000 where the second number is twice the first and the third is three times the first number?

#include

#include

int main()

{

int i,j,k,l,m,n,p,q,temp,fno,secno,thirdno;

int arr[1][9];

cout<<"---------------------------------------ABRAR TARIQ-------------------------------"<

cout<<"Here are the all possible combinations of the triad numbers between 1 to 1000 ! cheers !"<

int a=0;

for(i=100;i<=1000;i++)

{

for(j=i+1;j<=1000;j++)

{

if(j==2*i)

{

fno=i;

secno=j;

}

if(j==3*i)

{

thirdno=3*i;

}

}

k=fno/100;

temp=fno%100;

l=temp/10;

m=temp%10;

arr[0][0]=k;

arr[0][1]=l;

arr[0][2]=m;

k=secno/100;

temp=secno%100;

l=temp/10;

m=temp%10;

arr[0][3]=k;

arr[0][4]=l;

arr[0][5]=m;

k=thirdno/100;

temp=thirdno%100;

l=temp/10;

m=temp%10;

arr[0][6]=k;

arr[0][7]=l;

arr[0][8]=m;

for(n=0;n<1;n++)

{

for(p=0;p<9;p++)

{

for(q=p+1;q<9;q++)

{

if(arr[n][p]==arr[n][q]arr[n][p]==0arr[n][q]==0)

{

a=1;

}

if(a==1)

break;

}

if(a==1)

{

a=0;

break;

}

}

if(p==9&&q==9&&a==0)

{

cout<<<","<<<","<<<

cout<<"---And---"<

}

}

return 0;

}