Explain the bitwise operators available in Java with an example?
Java's bitwise operators operate on individual bits of integer (int and long) values. If an operand is shorter than an int, it is promoted to int before doing the operations. It helps to know how integers are represented in binary. For example the decimal number 3 is represented as 11 in binary and the decimal number 5 is represented as 101 in binary. Negative integers are store in two's complement form. For example, -4 is 1111 1111 1111 1111 1111 1111 1111 1100. == == & - and
| - or
^ - Xor
~ - not
<< - left shift
>> - right shift
>>> - right shift
Examples:
3 & 5 = 1 (1 if both bits are 1.)
3 | 5 = 7 (1 if either bits are 1) 3^5 = 6 (1 if both bits are different)
~3 = -4 (Inverts the bits)
3 << 2 = 12 (Shifts the bits of n left p positions. Zero bits are shifted into the low-order positions.)
5 >> 2 = 1 (Shifts the bits of n right p positions. If n is a 2's complement signed number, the sign bit is shifted into the high-order positions.)
-4 >>> 28 = 15 (Shifts the bits of n right p positions. Zeros are shifted into the high-order positions.)
{| !
!
!
!
!
|
|}
CAGE framework consist of cultural distances, administrative distances, geographic distance and economic distance in the analysis. it is created by Indian Guru, Pankaj Ghemawat.
Print the hello in double quotes in java?
public class TestStringHello {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("" Hello "");
}
}
Output: " Hello "
A delimiter is a sequence of one or more characters used to specify the boundary between separate, independent regions in plain text or other data ...
delimiters are used in java to split one large string into smaller ones.
ex: "val1;val2;val3"
the above string can be broken down into 3 small strings val1, val2 and val3. here semicolon is the delimiter
In Java classes we can declare multiple constructors. The JVM would dynamically decide which constructor to invoke based on the parameters passed from the calling class.
Ex:
public class Test {
public Test(){
...
}
public Test(String arg1){
...
}
public Test(String arg1, int arg2){
...
}
}
In the above class, there are 3 different constructor declarations. Whenever a constructor is invoked from a calling class, the JVM would decide which one to invoke based on the number of arguments passed.
A Java editor is nothing but a tool that can be used to edit java source files.
Ex: Textpad, Notepad, Eclipse etc...
Using for loop print the stars in the shape of equilateral triangle in java?
public class Traingle {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
char c=' ';
for (int i=0; i<4; i++)
{
for (int k=0; k<6-i; k++)
{
System.out.print(" ");
}
for (int j=0; j<i*2+1; j++)
{
System.out.print("*");
}
System.out.println(c);
}
}
}
Collection framework is a framework in java that helps us handle multiple java objects in one shot. For example if you have an employee validation system where you have details about all the employees in an office, you will have lets say 1000 employee objects available in an ArrayList which we can iterate and check if every employee that is going through the door is a valid employee.
Some of the collections we can use are:
a. ArrayList
b. Vector
c. HashMap
d. HashSet
e. etc
What is fitness function in GA algorithm?
In order to understand the fitness function, you first have to understand that a genetic algorithm is one which changes over time (it evolves). In nature we have things like predators and harsh environments which eliminate unwanted specimens of animals (a slow zebra will get eaten by a lion). We need to simulate this behavior when programming genetic algorithms.
The fitness function basically determines which possible solutions get passed on to multiply and mutate into the next generation of solutions. This is usually done by analyzing the "genes," which hold some data about a particular solution to the problem you are trying to solve. The fitness function will look at the genes and make some qualitative assessment, returning a fitness value for that solution. The rest of the genetic algorithm will discard any solutions with a "poor" fitness value and accept any with a "good" fitness value.
In short: the goal of a fitness function is to provide a meaningful, measurable, and comparable value given a set of genes.
Java program that computes proper divisors af an integer?
,
this answer is not perfect, its logic is correct. Validation for a floating point number has to be done. Change the code urself..
import java.io.*;
class proper
{
public static void main(String args[])
{
try
{
System.out.println("Enter the number");
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String str = br.readLine();
int n = Integer.parseInt(str);
int b[]=new int[n];
if(n>0)
{
for(int i=1;i
{
if(n%i == 0)
{
b[i]=i;
}
}
System.out.print("Proper divisors of " + n + " are");
for(int i=1;i
{
System.out.print(b[i]);
}
}
else
{
System.out.println("please enter a positive number");
}
}catch(Exception e)
{
System.out.println("Caught exception " + e);
}
}
}
What is advantage of using Object oriented Concept?
a. OOP provides a clear modular structure for programs which makes it good for defining abstract datatypes where implementation details are hidden and the unit has a clearly defined interface.
b. OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
c. OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.
A .lib file, or a statically-linked library file, is a file which can contain information like: pre-written code; subroutines; classes; values; types e.t.c.
A library file offers functionality pre-built for drag-and-drop type usage, rather than requiring the programmer to include large numbers of classes or other information into their project.
What are the methods of isi mitigation?
The methods of ISI mitigation are 1- Adaptive Equalization 2- DS-Spread Spectrum 3- OFDM 4- Directional Antennas Hope this helps you. Regards Fahad
Value, and its datatype depends on whatever variable we're changing.
Is there a if exists statement in Java programming?
In java you will be handling objects. An object, for example, can be a Person, that will hold the first and last name of that someone and maybe an address or phone number. Each object can be like a mini java program in that it can have methods (or functions) of its own. However, an object generally needs to be instantiated before you can access the fields or methods of that function. If it is not you will get a runtime error that may kill your program. To check if the object has been instantiated (that is, if it exists) you would call:
if(person null) which makes it evaluate the opposite way.
How does the CPU differentiate between command and data?
In general the only difference between commands, or instructions, and data is the context in which each appears. If the CPU is fetching the contents of memory to get the next instruction, then it assumes that the Program Counter register points to commands. If the CPU is executing an instruction that needs to fetch data from memory, the data at the address specified by the instruction are fetched, assuming that the address points to data.
This is what allows a program to be loaded into memory in the first place; the part of the operation system responsible for this operation treats the program as data, loading it into memory as instructed in the file. Then the OS branches to a specified place within that memory and begins fetching instructions there.
This blurring between instructions and data has also been used in the past to allow a program to modify itself as it executes. This is usually considered poor practice; some operating systems, such as HP's OpenVMS, even set up memory page protections to keep this from happening.
If two references are having same hashcodes is that mean those two are refering to same object?
Possibly. It could also mean that the two references are referring to two different Objects, which contain the same data.
A Web cache is a temporary memory in your browser where temporary information about the web site you are visiting are stored. Information like login id, password, previous history of pages you visited etc would be stored in the cache...
Comparison between an Abstract Class and an Interface:
While an abstract class can define both abstract and non-abstract methods, an interface can have only abstract methods. Another way interfaces differ from abstract classes is that interfaces have very little flexibility in how the methods and variables defined in the interface are declared. These rules are strict:
Generate N random numbers in between 1 and 6 inclusive?
// First we want to create our random number generator.
// Normally we seed it with the current system time, but go ahead
// and use another method if you don't like that.
Random rnd = new Random(System.currentTimeMillis());
// Next step is to create a place to put our numbers.
// (Assuming you want to generate random integers)
int[] nums = new int[N];
// Now fill our array with random numbers.
// Random.nextInt(n) will give us a number from 0 (inclusive) to n (exclusive)...
// So we want to first get a number from [0-6) and add 1 to get the specified range.
for( int i = 0; i < nums.length; ++i )
nums[i] = rnd.nextInt(6) + 1;
How many axes of symmetry has a rectangle?
All rectangles have 2 axes of symmetry, which are the lines joined by the two pairs of midpoints of opposite sides.
How can you force the garbage collector to run?
You can't force it but you call System.gc(), which is a "hint" to the runtime engine that now might be a good time to run the GC. But garbage collection using this method is not guaranteed to be done immediately.
there is another way to explicitly call the gc().
this method is also define in Runtime class of package java.lang.
But u can not create a direct object of class Runtime like
Runtime a = new Runtime(); //wrong
For that u have to call the method getRuntime() which is static and it is also define in Runtime class the way to create object is
Runtime run; //right
run = Runtime.getRuntime(); //right
now u can call the gc() through the "run " Object.
like run.gc(); //right
Naming and directory services play a vital role in intranets and the Internet by providing network-wide sharing of a variety of information about users, machines, networks, services, and applications.
JNDI is an API specified in Java technology that provides naming and directory functionality to applications written in the Java programming language. It is designed especially for the Java platform using Java's object model. Using JNDI, applications based on Java technology can store and retrieve named Java objects of any type. In addition, JNDI provides methods for performing standard directory operations, such as associating attributes with objects and searching for objects using their attributes.
JNDI is also defined independent of any specific naming or directory service implementation. It enables applications to access different, possibly multiple, naming and directory services using a common API. Different naming and directory service providers can be plugged in seamlessly behind this common API. This enables Java technology-based applications to take advantage of information in a variety of existing naming and directory services, such as LDAP, NDS, DNS, and NIS(YP), as well as enabling the applications to coexist with legacy software and systems.
Using JNDI as a tool, you can build new powerful and portable applications that not only take advantage of Java's object model but are also well-integrated with the environment in which they are deployed.