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

Write a java code to draw a circle inside in an ellipse?

write a program draw circle and ellipse by using oval methods in java

What Errors are relatively easy to locate and correct because the compiler or interpreter you use highlights every error?

Run time errors or syntax errors are most easy to locate, since the compiler will show you where the errors are. A logic error would be more difficult to locate, since the program runs but does not compute the desired result.

List four JDBC drivers?

  • JDBC ODBC Bridge
  • Native API Partly Java Driver
  • Net Protocol full Java driver

are some types of jdbc drivers

What modifier do you use to prevent that class from having any subclasses?

In Java, you use the final modifier to prevent a class from having any subclasses.

What is the maximum combined length of command line arguments including the space between adjacent arguments?

So for as i know, it depends on the first argument which represents the number of arguments. If argc is 2 bytes in length, 65535 strings can be passed. If argc is 4 bytes in length, 4294967295 strings can be passed. In Both the cases first one is for program name. And the total length should not exceed the heap size.

S.Sunil kumar,MCA(2008-2011) from CEG, Anna University

Answer: OS dependent, for example in DOS only 127

What is a random number and how are generated?

Random numbers that are generated by a computer are pseudo-random (not really random), but they will pass enough statistical tests for randomness to be useful in simulation random processes. Java has random number generators in the standard libraries.

See the related link if you need more information.

What command executes the Java class file Welcomeclass?

I assume you meant Welcome.class, in which case, it would be:

java Welcome

Convert input number to word in java codes?

//By rohan import java.text.DecimalFormat; public class EnglishNumberToWords { private static final String[] tensNames = { "", " ten", " twenty", " thirty", " forty", " fifty", " sixty", " seventy", " eighty", " ninety" }; private static final String[] numNames = { "", " one", " two", " three", " four", " five", " six", " seven", " eight", " nine", " ten", " eleven", " twelve", " thirteen", " fourteen", " fifteen", " sixteen", " seventeen", " eighteen", " nineteen" }; private static String convertLessThanOneThousand(int number) { String soFar; if (number % 100 < 20){ soFar = numNames[number % 100]; number /= 100; } else { soFar = numNames[number % 10]; number /= 10; soFar = tensNames[number % 10] + soFar; number /= 10; } if (number == 0) return soFar; return numNames[number] + " hundred" + soFar; } public static String convert(long number) { // 0 to 999 999 999 999 if (number == 0) { return "zero"; } String snumber = Long.toString(number); // pad with "0" String mask = "000000000000"; DecimalFormat df = new DecimalFormat(mask); snumber = df.format(number); // XXXnnnnnnnnn int billions = Integer.parseInt(snumber.substring(0,3)); // nnnXXXnnnnnn int millions = Integer.parseInt(snumber.substring(3,6)); // nnnnnnXXXnnn int hundredThousands = Integer.parseInt(snumber.substring(6,9)); // nnnnnnnnnXXX int thousands = Integer.parseInt(snumber.substring(9,12)); String tradBillions; switch (billions) { case 0: tradBillions = ""; break; case 1 : tradBillions = convertLessThanOneThousand(billions) + " billion "; break; default : tradBillions = convertLessThanOneThousand(billions) + " billion "; } String result = tradBillions; String tradMillions; switch (millions) { case 0: tradMillions = ""; break; case 1 : tradMillions = convertLessThanOneThousand(millions) + " million "; break; default : tradMillions = convertLessThanOneThousand(millions) + " million "; } result = result + tradMillions; String tradHundredThousands; switch (hundredThousands) { case 0: tradHundredThousands = ""; break; case 1 : tradHundredThousands = "one thousand "; break; default : tradHundredThousands = convertLessThanOneThousand(hundredThousands) + " thousand "; } result = result + tradHundredThousands; String tradThousand; tradThousand = convertLessThanOneThousand(thousands); result = result + tradThousand; // remove extra spaces! return result.replaceAll("^\\s+", "").replaceAll("\\b\\s{2,}\\b", " "); } /** * testing * @param args */ public static void main(String[] args) { System.out.println("*** " + EnglishNumberToWords.convert(0)); System.out.println("*** " + EnglishNumberToWords.convert(1)); System.out.println("*** " + EnglishNumberToWords.convert(16)); System.out.println("*** " + EnglishNumberToWords.convert(100)); System.out.println("*** " + EnglishNumberToWords.convert(118)); System.out.println("*** " + EnglishNumberToWords.convert(200)); System.out.println("*** " + EnglishNumberToWords.convert(219)); System.out.println("*** " + EnglishNumberToWords.convert(800)); System.out.println("*** " + EnglishNumberToWords.convert(801)); System.out.println("*** " + EnglishNumberToWords.convert(1316)); System.out.println("*** " + EnglishNumberToWords.convert(1000000)); System.out.println("*** " + EnglishNumberToWords.convert(2000000)); System.out.println("*** " + EnglishNumberToWords.convert(3000200)); System.out.println("*** " + EnglishNumberToWords.convert(700000)); System.out.println("*** " + EnglishNumberToWords.convert(9000000)); System.out.println("*** " + EnglishNumberToWords.convert(9001000)); System.out.println("*** " + EnglishNumberToWords.convert(123456789)); System.out.println("*** " + EnglishNumberToWords.convert(2147483647)); System.out.println("*** " + EnglishNumberToWords.convert(3000000010L)); /* OUTPUT WILL BE LIKE THIS *** zero *** one *** sixteen *** one hundred *** one hundred eighteen *** two hundred *** two hundred nineteen *** eight hundred *** eight hundred one *** one thousand three hundred sixteen *** one million *** two millions *** three millions two hundred *** seven hundred thousand *** nine millions *** nine millions one thousand *** one hundred twenty three millions four hundred ** fifty six thousand seven hundred eighty nine *** two billion one hundred forty seven millions ** four hundred eighty three thousand six hundred forty seven *** three billion ten **/ } }

Which package is heavier 85 g or 2oz?

Data in computers is not measured in grams...However, to answer your question, 85 grams is heavier; 2 ounces is 56.69 grams when converted.

What is jfc?

The Java Foundation Classes (JFC) are a comprehensive set of GUI components and services which dramatically simplify the development and deployment of commercial-quality desktop and Internet/Intranet applications.

Can a DateTime variable be null?

hi i can say that datetime cant be null because datetime is valuetyp(struct) its not referece type(object)

Using pointers. write a function that receives a character string and a character as argument and deletes all occurrences of this character in the string?

guys ..... instead of using actual pointer arguments i have used parameters ...

this will give you a far better idea of using pointers ........and i have used setbuf function because i am using emacs , it buffers output !!...... just enjoy

#include<stdio.h>

#include<string.h>

void main()

{

char ch,str[25],del[25];

char *p,*q,*r;

int i;

setbuf(stdout,NULL);

printf("\nenter the string:-\n");

gets(str);

setbuf(stdout,NULL);

printf("\nenter the character:-\n");

gets(&ch);

p=str;

r=del;

q=&ch;

delete(p,q,r);

printf("\nthe string with the deleted characters is:-\n%s",del);

}

delete(char *p,char *q,char *r)

{

while(*p!='\0')

{

if(*p!=*q)

{

*r=*p;

r++;

p++;

}

else

{

p++;

continue;

}

}

*r='\0';

}

Give some examples of keywords?

Java Keywords
  • abstract
  • assert
  • boolean
  • break
  • byte
  • case
  • catch
  • char
  • class
  • const
  • continue
  • default
  • do
  • double
  • else
  • enum
  • extends
  • final
  • finally
  • float
  • for
  • goto
  • if
  • implements
  • import
  • instanceof
  • int
  • interface
  • long
  • native
  • new
  • package
  • private
  • protected
  • public
  • return
  • short
  • static
  • strictfp
  • super
  • switch
  • synchronized
  • this
  • throw
  • throws
  • transient
  • try
  • void
  • volatile
  • while
The Java Language Specification makes a special note of the "goto" and "const" keywords:

The keywords const and goto are reserved, even though they are not currently used. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in programs. C++ Keywords
  • and
  • and_eq
  • asm
  • auto
  • bitand
  • bitor
  • bool
  • break
  • case
  • catch
  • char
  • class
  • compl
  • const
  • const_cast
  • continue
  • default
  • delete
  • do
  • double
  • dynamic_cast
  • else
  • enum
  • explicit
  • export
  • extern
  • false
  • float
  • for
  • friend
  • goto
  • if
  • inline
  • int
  • long
  • mutable
  • namespace
  • new
  • not
  • not_eq
  • operator
  • or
  • or_eq
  • private
  • protected
  • public
  • register
  • reinterpret_cast
  • return
  • short
  • signed
  • sizeof
  • static
  • static_cast
  • struct
  • switch
  • template
  • this
  • throw
  • true
  • try
  • typedef
  • typeid
  • typename
  • union
  • unsigned
  • using
  • virtual
  • void
  • volatile
  • wchar_t
  • while
  • xor
  • xor_eq

What is the process of assigning a value to a variable called?

That is called "assignment".

That is called "assignment".

That is called "assignment".

That is called "assignment".

Can you overload plus equals in java?

yes to over load plus in java by using arthamatic operation we can perform it

How do you write a program in Java to check whether a number is a pal prime or not?

import java.io.*;

class PalPrime

{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int x;

void inputData(int X)throws IOException

{

x=X;

}

int Pal(int y)

{

int a=y,b=0,rev=0;

while(a>0)

{

b=a%10;

rev=rev*10+b;

a=a/10;

}

if (rev==y)

return 1;

else

return 2;

}

boolean Prime(int m)

{

int c=0;

for(int i=1;i<=m;i++)

{

if (m%i==0)

c++;

}

if (c==2)

return true;

else

return false;

}

void main()throws IOException

{

System.out.println("Enter a 4 digit no");

int X=Integer.parseInt(br.readLine());

inputData(X);

System.out.println("Enter the same no. again");

int y1=Integer.parseInt(br.readLine());

Pal(y1);

System.out.println("Enter the same no. again");

int m1=Integer.parseInt(br.readLine());

Prime(m1);

if (Pal(y1)==1 && Prime(m1)==true)

System.out.println(x+" is a Pal-Prime No.");

else

System.out.println(x+" is not a Pal-Prime No.");

}

}

In ANSI C you can hide data by using private access specifier Justify?

One can always declare a datatype as static which will limit the scope to the file only. this way data hiding can be achived. For more clearance on the same please refer 'the C programming language'.

Data hiding means only relevant data is visible to the user and all the background information is hidden from the user. In c++, the variables are named as data members and these can be hidden with the help of private access specifier.

In procedural languages, variables(global variables) are free to flow from functions to functions and hence they were not secured. But in C++, only the class in which the data members are being declared can access them by using private specifier. As, the data members and also member functions of a class cannot be accessed outside the class if they have private access so, they get hidden from the user and hence the data hiding is achieved.

Also in inheritance when we derive a class from the base class then the derived class cannot access the private members of the base class. In addition, if a class is derived from another class privately i.e. for example syntax : class B : private A , is used then all the public and protected members (not private) becomes private to class B and cannot be accessed outside the class B, even by using the object of class B.

Hence, data hiding is achieved in C++ through private access specifier.

What are the main ways of exiting a program?

Other than throwing an exception or a run-time library error, or forcibly terminating the process, there is only one way of exiting a program; you return from the entry point function, usually main(), provided by the library, or from winmain(), if you are using Windows.

Describe the difference between Interface-oriented Object-oriented and Aspect-oriented programming?

In object oriented programming cross cutting concerns cannot be implemented while in aspect-oriented these can be implemented easily, but if there is a logic mistake in implementing these cross-cutting concerns then the whole system will fail. In case of object-oriented whole system will not fail.(Excerpt from FrazzledDad blog @ http://frazzleddad.blogspot.com)Aspect-OrientedAspect-oriented programming looks at how many components or pieces of a system might need to interact. The intersections of these pieces are what are important in AOP. "Crosscutting" is a slice across several units, all of which interact during some operation. The article Discussing aspects of AOP in Communications of the ACM, Volume 44, Number 10 (2001) shows an example of a drawing editor with point and line elements. If the drawing is moved, both point and line elements need to update. A crosscut hits these elements for this event. Other examples might include logging or exception handling which hit several different layers in a system. (Viji Sarathy, Aspect Orienting .NET Components )Interface-OrientedInterface-oriented programming is a contract-based approach. Nether side of the interface cares how the other does its work, only that the two sides can communicate via an agreed-upon contract. WSDL-based web services are the prime example of this.Object-OrientedObject-Oriented programming is based on abstraction, encapsulation (data hiding), polymorphism and inheritance. Classes implement these concepts to build objects controlling or implementing a system.Abstraction allows loose coupling between components by providing a layer between objects so that one object isn't concerned with how the other implements its business rules. (Interfaces, layers) Great stuff when you want to isolate parts of the system so they can be swapped out without killing the rest of the sytsem.Encapsulation allows abstraction to work by hiding details of a class's implementation from calling classes. (Public vs. private fields)Inheritance enables base (parent) classes to have common functionality defined in it and passed down to child classes. A Shape class might have a field for color which is inherited by child classes of Square or Circle type.Polymorphism enables implementation of same-named public fields, allowing different classes to perform different actions on the same call - rendering a Square or Circle object differently in a graphic program, even though they might both be subclassed from a base Shape class. (Overriding)

Sort the following numbers 19 5 28 2 7 using bubble sort?

Passes:

bold are "sunk" into place

1: 5 19 2 7 28

2: 5 2 7 19 28

3: 2 5 7 19 28

4*: 2 5 7 19 28

*The last pass had no swaps, thus it breaks out of the sort

Efficiency: O(n^2) in random order O(n) when already sorted

Which program translates an assembly language program into a high-level language?

A High level language is a language like C, Pascal, Fortran. To convert, the easiest way is to use a compiler.

A compiler will take the instructions written in a high level language and convert them into machine code which is the specific instruction set for that type of computer. Assembly language is just a human readable form of a machine code which is how the designers of the computer instruction set made it work.

A disassembler will show the assembly language from machine code. But the compiler usually includes a lot of optimisations from a the high level language and will not often generate very simple assembly.

Memorymically and and not reclaming it when it is no longer it is needed in java there is no such problem as there is as garbage collector what is it?

I guess you want to talk about the garbage collector feature that Java has.

The garbage collector is an automated program that the Java virtual machine would run once in a while. This program would clean up unused memory to ensure that there is enough memory available for the programs.

you can invoke the garbage collector by calling the system.gc() method but this does not guarantee an invocation of the garbage collector. the JVM may or may not call the GC when we invoke it...

Write a program to transpose of a matrix?

Program to find the Transpose of a Matrix

#include

#include

void main()

{

int i,j,n,t;

int m[5][5];

clrscr();

printf("Enter Order of Matrix : ");

scanf("%d",&n);

printf("Enter Elements of Matrix :\n\n");

for(i=0;i

{

for(j=0;j

{

scanf("%d",&m[i][j]);

}

}

printf("Transpose of the Matrix :\n\n");

for(i=0;i

{

for(j=i+1;j

{

t=m[i][j];

m[i][j]=m[j][i];

m[j][i]=t;

}

}

for(i=0;i

{

for(j=0;j

{

printf("\t%d",m[i][j]);

}

printf("\n");

}

getch();

}

Output:

Enter Order of Matrix : 3

Enter Elements of Matrix :

45 56 96

75 36 15

29 64 81

Transpose of the Matrix :

45 75 29

56 36 64

96 15 81

with out using temp variable:

#include

#include

void main()

{

int i,j,n,t;

int m[5][5];

clrscr();

printf("Enter Order of Matrix : ");

scanf("%d",&n);

printf("Enter Elements of Matrix :\n\n");

for(i=0;i

{

for(j=0;j

{

scanf("%d",&m[i][j]);

}

}

printf("Transpose of the Matrix :\n\n");

for(i=0;i

{

for(j=i+1;j

{

m[j][i]=(m[i][j]+m[j][i]-(m[i][j]=m[j][i]));

}

}

for(i=0;i

{

for(j=0;j

{

printf("\t%d",m[i][j]);

}

printf("\n");

}

getch();

}