Return the number of even ints in the given array java?
int getNumEvens(final int[] nums) {
int numEvens = 0;
for(int i = 0; i < nums.length; ++i) {
if(nums % 2 == 0) {
++numEvens;
}
}
return numEvens;
}
How many base class and derived class can be created in inheritance?
As many as required. The only practical limits are those imposed by the hardware. For instance, 32-bit systems can only address a maximum of 4GB, but only 2GB is actually available to applications. On 64-bit systems there is no practical limit other than hard-drive space (for the virtual memory paging file).
Remember that every class of object requires memory to store its member variables (plus padding for alignment), which has to be multiplied up by the number of instances of those classes. Thus the more complex the hierarchy, the fewer instances you can create overall. Since alignment padding can add a substantial overhead, it's best to declare member variables from largest to smallest within each class because memory is allocated in the same order the members are declared. If a v-table is required (which it typically will be in a multi-level hierarchy) this will consume additional memory: essentially one function pointer per virtual function per override.
That said, it is difficult to imagine any hierarchy so large that you will hit a memory limitation, even on a 32-bit system, unless you happen to embed a particularly large member variable in your class, such as a hi-resolution image or video, rather than use a disk-based file stream. Aside from that the main concern is in how many instances of that hierarchy can you physically construct at one time. However, you need only look at some of the hierarchies within the Microsoft Foundation Classes to realise that your probably just scratching the surface of what is actually possible.
What type of operator is used to compare two values?
Conditional operators are used to compare two values. The result of a comparison is either true or false. Boolean data types can hold the values true or false.
Here's a list of operators.
= Equal to
> Greater than
< Less than
>= Grater than or equal to
<= Less than or equal to
<> Not equal to
Can abstract method be overriden?
An overridden method is one which has already been implemented in the parent class with the same signature but has again been coded in the current class for functionality requirements. An abstract method is one which has only been declared in a class and would have to be implemented by the class that extends this abstract class. The implementation for the method is not available in the class in which it is declared.
In java using command line argument write prime number program?
/* Program to print prime numbers up to given number */
import java.util.*;
public class Prime
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number : (it prints prime numbers upto your given number)");
int n=sc.nextInt();
System.out.println("The Prime number upto "+n+" are : ");
while (n>=0)
{
int count=0;
for (int i=1;i<=n ;i++)
{
if (n%i==0)
{
count++;
}
}
if (count==2)
{
System.out.print(n+" ");
}
n--;
}
}
}
What is the difference between traditional programming and object oriented programming?
Object oriented programming is a design paradigm supported by the languages compiler where aspects of the program are thought of as objects. The code (i.e. functions) and variables required by those methods are grouped together into objects. The object exposes methods to the programmer so the object can be manipulated. There are more advanced aspects of object oriented programming such as polymorphism and inheritance that allow more high level and abstract usage of objects.
Function oriented programming treats functions and variables separately. Functions are used like machines; they take in variables, manipulate, and return them. The variables and functions required to accomplish a task aren't grouped together as in object oriented programming.
For a large project object orientated programming is more flexible and easier to understand. Small, very specific tasks, can some times be best accomplished with straight forward function oriented programming.
Full java program to find the given string is palindrome or not?
return str.equals((new StringBuilder(str)).reverse().toString());
}
Answer 2:import java.io.*;class StringPalindrome
{
protected static void main()throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the String: ");
String s=in.readLine(),n="";
for(short i=(short)(s.length()-1);i>=0;i--)
{
char ch=s.charAt(i);
n+=ch;
}
if(s.equalsIgnoreCase(n))
System.out.print("Palindrome!!!!");
else
System.out.print("Not Palindrome!!!!");
}}
Write a program to check wheather a vowel or not by using if else construct in javac?
import java.util.Scanner;
class Vowels{
public static void main(String[]args){
int c=0;
Scanner obj=new Scanner(System.in);
System.out.println("Enter your String:");
String b=obj.nextLine();
for (int i=0;i<b.length();i++) {
if (b.charAt(i)==('a')b.charAt(i)==('e')b.charAt(i)==('u')b.charAt(i)==('i')b.charAt(i)==('o')b.charAt(i)==('A')b.charAt(i)==('E')b.charAt(i)==('U')b.charAt(i)==('I')b.charAt(i)==('O')){
c++;
}
}
System.out.println("Number of vowels found: "+c);
}
}
Is java is front end or back end?
Backend = software running on a server connecting to databases, mainframes, or simply just doing stuff.
Frontend = the part a user interacts with. It might be an applet, web page, Swing application, or just about anything that can communicate with the backend.
Why Can't I download Java software?
There are many ways to download Java. You could google 'java download' or type in any variation with the words java and download in a search engine of your choice. Also, you could ask a friend to download it for you. For instance, if you have a friend named Mike that is not completely computer illiterate, you could say, "Hey Mike, will you download Java for me, please?". But, the quickest way to download Java is to go to:
http://www.java.com/en/download/
Which data type in Java is the widest?
Data types and Variables
Data types are used to define what kind of information is going to assign to a variable. Java contains two kinds of built-in data types are object oriented and non-object oriented data types. The object oriented data types are defined by a classes. The non object oriented data types are called primitive data types. Java defines the range and the behavior for each data type. However unlike other languages in java three is no need to specify a size of the data type because of it's portability.
Primitive Data types
There are eight primitive data types available in Java are segregated in terms of Integers, Floating-Point and Boolean data types.
Integers
There are four data types to store Integers. They are byte, short, int and long These data types are signed which means that they can hold either positive or negative values.
The range and size of each data type has been given belowTypeSizeRangebyte8-128 to 127short16-32,768 to 32,767int32-2,147,483.648 to 2,147,483,647long64-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Most commonly used integer type is int. The smallest integer type is byte. It is used to store the raw binary data. The short type is mostly applicable to 16 bit computers.
/* This is a example for using Integer Data types
Find the addition of two numbers */
class addition
{
public static void main(String args[])
{
int i=8;
int j=7;
int k;
k= i + j ;
System.out.println(" The addition of " + i + "and" + j + " is" + k);
}
}
The output will be
The addition of 8 and 7 is 15
Here in this example the data type int has assigned to the variables i ,j and k. We can also declare the variables with the same type of data types in the same statement separated by comma. When we need an integer that has a range greater than int, then we should go for long.
Floating-Point Types
Floating point numbers are numbers with decimal point. There are two kinds of floating-point types, floatand double. The range and size of float and double has given here.TypeSizeRangefloat321.4e -045 to 3.4e+038double644.9e-324 to 1.8e+308
Among these two, double is the most commonly used because all of the math function in Java's library use double values.
/* This is example for using floating-point Data Types
Find the square root of given numbers */
class squareroot
{
public static void main(String args[])
{
double x,y,z;
x=13;
y=17;
z=Math.sqrt(x+y);
System.out.println(" The Square Root is " +z);
}
}
The output will be
The Square Root is 5.477225575051661
In this example we have used the floating point data type double. Here we have used the new termMath.sqrt(), Math is a Java's built in class and sqrt() is a method in class Math.
Characters
The char type is used for individual characters, such as letters, numbers, punctuation and other symbols. In Java characters are not 8 bit type like they are in other computer languages. Java uses Unicode to represent the characters. Unicode is a character set that can represent all of the characters found in all human language. So, in Java char type is unsigned 16 bit type range from 0 to 65,536. Since the standard 8 bit ASCII set is subset of Unicode, the ASCII characters are still valid Java characters.
A character variable can be assigned a value by enclosing the character in single quotes.
For example, the letter x assigns to variable ch as like this
char ch;
ch='x';
Since char is an unsigned 16-bit type, it is possible to perform the arithmetic manipulations on a char variable.
/* This is a example for using the Data type character
Doing some arithmetic manipulation in character */
class CharManipulation
{
public static void main(String args[])
{
char ch='x';
System.out.println(" Now the ch is " +ch);
ch++;
System.out.println(" Now the ch is " +ch);
ch++;
System.out.println(" Now the ch is " +ch);
}
}
The Output will be
Now the ch is x
Now the ch is y
Now the ch is
In this example the variable ch is declared char variable and it has assigned to the value of 'x'
In the next line we are incrementing the value of ch by 1. So the corresponding Unicode value will be assigned to ch now. So the letter 'y' will be assigned. In the next line also we are doing the same procedure of incrementing the ch value by 1. So now the value of ch will be 'z'.
Boolean Type
The Boolean type holds either true or false using the reserved word true or false. The expression of the variable using boolean datatype will be either true or false.
For example the boolean data type will be assigned as
boolean b;
b=true;
or
boolean b= true;
Variable declaration in Java
We can define Variable is a place where information can be stored while program is executing. The value of the variable can be changed at any point in the program. The syntax of the variable declaration is
type var-name;
where type is the data type of the variable, and var-name is the name of the variable. We can assign any valid data type to a variable. As we had seen before the data type will decide what kind of values can be assigned to a variable. Variables can be declared anywhere in the Java program, only thing is it should be declared before they can be used. As we said earlier when we want to declare several variables with the same data type, we can declare all of them in the same statement. Variable names in Java must start with a letter, a underscore character( _ ) or with a dollar sign. They cannot start with a number.
There are three kinds of variables can be declared in Java called as instance variable, class variable and local variable. Here we are going to discuss about the local variables. The local variables can be assigned inside the method or inside the block of statements within a method. All the local variables must be initialized before it is been used.
For Example
class VarInit
{
public static void main(String args[])
{
int i=12,j=16,k=30;
System.out.println(" The value of i is " + i );
System.out.println(" The value of j is " + j );
System.out.println(" The value of k is " + k );
}
}
The Output will be
The value of i is 12
The value of i is 16
The value of i is 30
Here in this example since the variables i,j and k hold the same data type we declared them in the same statement. Notice that they have also been initialized with some values.
Why user defined applet class declared public?
Well, it was probably an aesthetic decision on the part of the Java developers, and consider this: The server needs to access some of the applet's attributes, so doesn't it make sense that the applet is public? If the applet was private, nobody would be able to access it.
Default arguments are often considered to be optional arguments, however a default argument is only optional in the sense that the caller need not provide a value for it. The function must still instantiate the argument and must assign the appropriate value to it so, insofar as the function is concerned, the argument is not optional.
To implement a function with a truly optional argument, we can define two overloads of that function, one that accepts the optional argument (without specifying a default value) and one that does not accept the argument. In this way we can define two different implementations, one that uses the argument and one that does not.
void f (); // implementation that does not use the argument
void f (int); // implementation that does use the argument
In many cases, a default argument incurs no significant overhead over that of overloading. Thus we'd only use overloading to implement an optional argument where there is a significant overhead incurred by a default argument. Even so, we must also be aware that by eliminating the overhead within the function itself we may simply be passing that overhead back to the callers, because some or all of them would then have to decide which overload to call, resulting in code duplication that would likely be best handled by the function itself.
54321 4321 321 21 1 what is the code in for loop?
public static void main(String[] args){
for(int i=0;i<5;i++)
{
for (int j=
What type of list sequences items?
a Bulleted list
No, that's incorrect, I'm afraid.
A bulleted list is used when no sequencing is necessary.
A numbered or lettered list is used to indicate a particular sequence of items.
How many dimensions you can declare in array?
It seems that the number of allowed array dimensions is implementation specific and not set by the Java specifications. I'm sure that any Java implementation will allow a reasonable number of dimensions for any project you have.
After a quick test, it seems that Java is not limited by an arbitrary number so much as a practical value. If you add hundreds of array dimensions, Java will allow you to do so as long as you have enough memory allocated for Java. After a bit of copy-pasting the program no longer ran, exiting with a StackOverflowError.
What is the use of main method in java?
The Main method is the method in which execution to any java program begins.
A main method declaration looks as follows:
public static void main(String args[]){
}
The method is public because it be accessible to the JVM to begin execution of the program.
It is Static because it be available for execution without an object instance. you may know that you need an object instance to invoke any method. So you cannot begin execution of a class without its object if the main method was not static.
It returns only a void because, once the main method execution is over, the program terminates. So there can be no data that can be returned by the Main method
The last parameter is String args[]. This is used to signify that the user may opt to enter parameters to the java program at command line. We can use both String[] args or String args[]. The Java compiler would accept both forms.
Why Java is referred to as hot cup of coffee?
The symbol of java used as a hot cup because At the time of taking morning TEA JAMES GOSLIN got
a project which name was green project so thats why he uses the symbol of HOT CUP for JAVA.
What is function overloading in oop?
An overloaded function is a function that has several implementations, the only difference being the number and type of parameters, including usage of the const keyword. Overloads cannot differ by return type alone. The following is a trivial example of function overloading.
const int & max(const int & lhs, const int & rhs){return( lhs>rhs ? lhs : rhs );}
const char & max(const char & lhs, const char & rhs){return( lhs>rhs ? lhs : rhs );}
Since the implementation is exactly the same, regardless of the type of parameters, it would make more sense to enlist the compiler to generate all the possible variants of this overloaded function using a template function. The compiler then generates all the overloads as required, and you only have one function to maintain.
Overloads are better suited to functions that have completely different signatures with a different number of parameters. For instance:
typedef struct rect_tag
{
float width;
float height;
} rect;
const float & Area( const rect & rc ){ return( rc.width * rc.height ); }
const int & Area( const int & width, const int & height ){ return( width * height ); }
const float & Area( const int & width, const float & height ){ return((float) width * height ); } const float & Area( const float & width, const int & height ){ return( width * (float) height ); }
The point of overloading functions is increased flexibility.You don't have to worry about which version of a function you call, nor is there any need to cast parameters to a specific type, since the compiler can work out which version of a function to call simply from the type of parameters you supply. If no suitable overload exists, the compiler will warn you so that you may either provide one, or explicitly cast your variables to a suitable version.
Mixing overloads with default parameter values increases the flexibility further, provided there is no ambiguity regarding which version of the overload is being called.
SIS files are Symbian and JAR files are java. The software that converts a SIS file to a JAR file is called Sis to Jar Converter 1.7.7.2.
User defined data types in c plus plus?
C++ provides the following fundamental types:
Fundamental types correspond to the basic storage units of the machine. From the fundamental types we can construct other types using declarator operators:
The Boolean, character and integer types are collectively known as the integral types. The integral and floating-point types are collectively known as the arithmetic types.
The fundamental types, pointers, arrays and references are collectively known as the built-in types.
The integral types can be further modified using the signed or unsigned modifiers. Strictly speaking, both long and short are also type modifiers because a short implies a short int. This is simply an artefact from C programming where int was implied in the absence of an explicit type.
Note that aliases (using x = type) and type definitions (typedef) are not types per se, they are simply alternative names for preexisting types. For instance, although wchar_t is a built-in type because it does not require a declaration, in reality it is just an alias for an implementation-defined integral type (typically unsigned short).
From these built-in types we can construct other types:
Data structures, classes and enumeration types are collectively known as user-defined types.
In essence, any type that requires an explicit declaration is a user-defined type. This includes all C++ standard library types such as std::string because we cannot use a std::string object unless we include the
When do you declare a variable method and a class final?
When There is No Need to Change the Values of the Variables In Entire lifetime of That variables then we must use that Variable as Final Variable.