Advantages of static keyword in java?
When we want that a class member should be used independently of any object of that class, we have to precede that member's declaration with the keyword static .
When a member is declared as static, it can be acccessed without creationg an object of the class and without referring to the object.That static is , a static member belons to a class as a whole and not to any one instance/object of that class.
The static member is shared by all objects of thatclass.
What is a class in programming?
class is summation of data member and data types(basically known as instance variable of a class). making a class is basically an encapsulation under various access specifiers on which its object accessibility depends. these data functions can be accessed inside or outside the class with the help of object(class variable) of a class. an object defined in another class(i.e. outside the original class) can access its own class members which r not declared under private mode but can access public members and it is derived then can also access protected data members or data types also.
Difference between Java and the C plus plus?
Classes are the basic unit of code in Java, whereas the basic unit of code in C++ are functions.
All objects in Java descend from a common class (Object), which allows more generic code. While this can also be (manually) implemented within C++, generic programming is best achieved using templates and concepts.
All methods in Java (including destructors) are virtual by default. In C++, methods must be explicitly declared virtual if they are expected to be overridden, or explicitly declared final if they must not be overridden.
Java does not permit operator overloading, thus we cannot operate upon objects as intuitively as we can in C++.
Benefits of inheritance in Java programming?
Advantages of Inheritance
1) Code Re-usability
2) consumes less time
3) Without changing the super class we can add some more methods in the super class by inheriting it in the derived class
What are range of character data type in c plus plus?
The range of character data types in C++ is the set of characters in the host's character set.
It is inappropriate to consider the numerical range of such things as characters, because that depends on the particular codeset involved, such as ASCII, EBCDIC, UNICODE, KANJI, etc. Doing that leads to non-portable code, and lazy programming practices. Do not write code that depends on the collating sequence of the character set, or the numerical difference between two characters.
Type char can be signed or unsigned, the value range is -128..127 or 0..255 respectively.
Where was the Java programming language invented?
James Gosling, PhD (born May 19, 1955 near Calgary, Alberta, Canada), along with other engineers and scientists, invented Java. Gosling is a famous software developer and is actually best known as the father of the Java programming language.
How do you create a concrete method inside abstract class?
The same way you create a concrete method in a concrete class. When a class is abstract, it can contain abstract methods. That doesn't mean that all methods must be abstract. Hope this helps.
These are small capsules of nano materials inside it,which when contacted with the body,splits up an soothes the skin . It can be used as revitilizer for various purposes. It is one of the effective technique used.
What is need for function overloading in Java?
To overload a method in java, you only needs to write a method with the same name of other in your class but with diferente kind or number of parameters. For example:
class MyClass{
void printNumber(int x){
System.out.println(x);
}
void printNumber(int x, int y){
System.out.println(x+y);
}
}
the type of the value that your method return could change if you want.
What are the examples of polymorphic viruses?
1260 is a computer virus developed by Mark Washburn in 1989. This virus used a form of polymorphic encryption in it's code which randomized the algorithm used by the virus but kept the core function of it intact. Polymorphic code does this by infecting files with an encrypted copy of itself, then varying it's signature by randomizing its decryption algorithm. Then it repeats. Hope this helped, here's some relevant info on the subject:
http://en.wikipedia.org/wiki/1260_(computer_virus)
http://en.wikipedia.org/wiki/Mark_Washburn
http://en.wikipedia.org/wiki/Timeline_of_computer_viruses_and_worms
--
Answered by Alix Saunders
How Convert decimal to binary using stack?
Where can one find java project tutorials?
Java project tutorials can be found on Oracles homepage as well as Javas homepage. Netbeans and Eclipse also provide tutorials for setting up java projects in their specific integrated development environments.
Please note that the answer below is the most expandable answer. By this I mean that it can be easily changed to display the output given for any number of digits in a number. There are far simpler solutions which do not require any explanation, but are useless in an evolving setting.
To answer this question, we need to look at the Math.log10 function. Ignoring the possible anomalous results of this function (check the current Java API to find out what other results are possible), we can find the number of digits in a number by using: (log10(n) + 1). If n is equal to the value 10^m for a value m, then the function will return m. That is to say, if n is equal to 10, then the result of the function will be 1, since 10^1 = 10. Likewise, if n is equal to 100, then the result of the function will be 2, since 10^2 = 100, and so forth. If you look at the numbers in between, you will find the function returns a decimal result. log10(99) = 1.9956, for example. This means that the range of answers you will get for the values [10,99] will return the range of answers from [1.0,2.0). The same can be found looking at the range of values [100,999] which return in the range [2.0,3.0). From this we find that the function log10 always returns either an integer or a fractional value which will always be at most 1.0 less than the number of digits in the number sent to it. In either case, if we simply truncate it (cast the double as an int) and add 1, we come up with our getNumDigits function.
int getNumDigits(int n) {
return ((int) Math.log10(n)) + 1;
}
And to finish up your question, we can add in another method to deal with the results.
// we're assuming the number n comes from somewhere else,
// whether hard-coded or passed as input to the program
void displayNumDigits(int n) {
switch(getNumDigits(n)) {
case 1:
System.out.println("One digit");
break;
case 2:
System.out.println("Two digits");
break;
case 3:
System.out.println("Three digits");
break;
default:
System.out.println("More than three digits");
}
}
How can you initialize an array in Java?
If you refering to Object then String[] something=new String[2]; Here you have to remember that something only allocated space for 2 String object but it did not created them yet. By default Objects are intantiated to null so if you try to print the content of an array System.out.println(something[0]);//print null System.out.println(something[0].toLowerCase()); Throws NullPointerException Couple other ways to create Arrays In java String[] something=new String[]{"Me","You"}; String[] something={"Me", "You"};
How can you save java servlet program for running?
If ur developing servlet program manually.The First thing is that u have to put servlet-api jar file should be set in classpath. The root directory is like that
create a folder name.inside the folder create one more folder name WEB-INF. Inside the WEB-INF folder create two folders one is classes and another is Lib
In the WEB-INF folder you have to put web.xml. In classes you have to put servlet.java. In Lib u have to put servlet-api.jar file. Go to command prompt then compile servlet.java .Create a war file. steps to create war file file jar cvf name.war . enter .open the browser type the bar http://localhost: portnumber enter & then apache tomcat server start.Click tomcat manager.It will ask username & password.
then submit.In the downstairs page there is a option name War file to deploy .Click on choose file.It will locate where is the war file .Select it & deploy it.click the programs then you have to type in the addresss bar what u had written in url-pattern in web.xml then enter u get the output.
we cover constructors and destructors for C++ objects. Constructors give a means to initializing newly created objects and can be overloaded. Destructors offer a way to perform clean up on an object just before it is destroyed; a class can have at most one destructor. Together constructors and destructors provide a method of encapsulating the lifespan of an object. Although we have not done anything useful with destructors so far, we will see that they are extremely useful as our programs get more complex.
In mathematics, an ordered list numbers is called a sequence. Sequences come in many types, but we can model a generic sequence with a class. Sequences can be of any length, but we will put a limit of 100 terms on our sequences for this first example:
The code above describes a sequence class with two constructors, a member function, and two data members. The first constructor is a default constructor, which creates a sequence with no terms in it. The second constructor takes an array of terms and a length; the terms are copied from the array to the sequence via a for-loop. The member function outputs the length of the sequence and then all of the terms-a check is made internally to assure that sequence has at least one term before outputting them. The data members are the length and an array of doubles to hold the terms.
In this main function, we create two instances of our sequence object and call Print() to output the sequences to the console window.
What are the advantages of overriding method in java class?
Any time you have a class that inherits a method from a superclass, you have the opportunity to override the method (unless, as you learned in the earlier chapters, the method is marked final). The key benefit of overriding is the ability to define behavior that's specific to a particular subclass type. The following example demonstrates a Porsche subclass of Car overriding the Car version of the drive() method:
public class Car {
public void drive() {
System.out.println("Generic Car Driving Generically");
}
}
class Porsche extends Car {
public void drive() {
System.out.println("Porsche driving Full Throttle");
}
}
For abstract methods you inherit from a superclass, you have no choice. You must implement the method in the subclass unless the subclass is also abstract. Abstract methods must be implemented by the concrete subclass, but this is a lot like saying that the concrete subclass overrides the abstract methods of the superclass. So you could think of abstract methods as methods you're forced to override.
The Car class creator might have decided that for the purposes of polymorphism, all Car subtypes should have an drive() method defined in a unique, specific way. Polymorphically, when someone has an Car reference that refers not to an Car instance, but to an Car subclass instance, the caller should be able to invoke drive() on the Car reference, but the actual runtime object (say, a Porsche instance) will run its own specific drive() method. Marking the drive() method abstract is the Car programmer's way of saying to all subclass developers, "It doesn't make any sense for your new subtype to use a generic drive() method, so you have to come up with your own drive() method implementation!" A (non-abstract), example of using polymorphism looks like this:
public class TestCars {
public static void main (String [] args) {
Car a = new Car();
Car b = new Porsche(); //Car ref, but a Porsche object
a.drive(); // Runs the Car version of drive()
b.drive(); // Runs the Porsche version of drive()
}
}
class Car {
public void drive() {
System.out.println("Generic Car Driveing Generically");
}
}
class Porsche extends Car {
public void drive() {
System.out.println("Porsche driving Full Throttle");
}
public void brake() { }
}
In the preceding code, the test class uses a Car reference to invoke a method on a Porsche object. Remember, the compiler will allow only methods in class Car to be invoked when using a reference to a Car. The following would not be legal given the preceding code:
Car c = new Porsche();
c.brake(); // Can't invoke brake();
// Car class doesn't have that method
To reiterate, the compiler looks only at the reference type, not the instance type. Polymorphism lets you use a more abstract supertype (including an interface) reference to refer to one of its subtypes (including interface implementers).
How do you achieve abstraction in java?
Abstraction in Java is achieved using interfaces and abstract class. abstract means something which is not complete or concrete but abstraction itself is a great programming concept and allow you to write code which is more flexible to change.
Explain this keyword with example in java?
this is one of the keyword in java programming language. this can be used inside any method to refer to the current object. example: class Box{ double width; double height; double depth; Box(double w,double h,double d){ this.width=w; this.height=h; this.depth=d; }
} The significance of the keyword this would be realized in cases where we use inheritance. There may be cases where you have methods of the same name in both the current class and its parent. That is when the keyword "this" can be used to tell the JVM to invoke the method of the current class and not the parent class. this refers to the object with which the method inside a class is called. For instance, I call studentObject.getGrade(), in the getGrade() method to call my own method or variables, i.e. a private instance variable named grade, I would state: this.grade. Though inside the class any method or variable that is called without an object automattically calls the most local method or variable, i.e. I could just call grade for the above example given that I do not have a variable of the same name declared in the method. "this" is useful in those circumstances where there are more than one variable with the same name, just for example that I do have a variable named grade in my getGrade() method, to get my instance variable for my object I would simply call this.grade, thus to be safe use this for instance variables.
Static variable and static methods in java?
== == Static method cannot be overwritten because it belongs to the class and not to the Object
If you're asking about overriding or overloading, then yes. Static methods can be overridden and overloaded just like any other methods.
High-level programming language intepreted?
EZtrieve and EZtrieve Plus are examples of a high level language that can be either compiled or run interpretive.
Differences among sequential access direct access?
Let's say you have a set of 100 pieces of data, which are all names. Now, if you want to find a specific name, "Kevin", you can find it in different ways. You could either go through each of the records one after another, or you could randomly generate a number, and check if that record is "Kevin", this is potentially faster than sequential access as "Kevin" could be the last record.
How are pointer different from other variables?
A pointer variable is a variable that contains the memory location of another variable or an array (or anything else in memory). Effectively, it points to another memory location.
For standard variables, you define a type, assign a value to that variable or read the value from it, and you can also read the memory location (&n = memory location of n) of the variable.
For pointers, you can point them to any variable, even another pointer, and you can get the value of the variable it points to (*p), the location of that variable in memory (p), or the address in memory of the pointer itself (&p).
Consider:
long n = 65;
long *p;
p = &n;
Results:
Type | Name | Location | Value
long n 0xA3FF 65
long * p 0x31DF 0xA3FF
So p points to n. Now,
n = 65
&n = 0xA3FF
p = 0xA3FF
*p = 65
&p = 0x31DF
You may find yourself having to use typecasts frequently when using pointers.
Pointers are useful when passing data to functions.
For instance, consider the following function:
void add(int a, int b, int c) { c = a + b; }
The problem here is that the computer copies each variable into a new memory location before passing them to the function as local variables. This function effectively does nothing. However, if you change the function to:
void add(int a, int b, int *c) { c = a + b; }
and call the function by passing in the location of the variable to the function:
add(a,b,&c);
then you can modify the variable itself.
Pointers are also good for working with arrays:
char *c = "Hello World";
int i=0;
while (c[i] != 0x00) { cout << c[i]; c++ } //print one letter at a time.
Java programing in library management system program?
import java.io.*;
class lib
{
int bno,fine=10,edit,date,ret,userdt;
String auth,publi,buknam;
void get()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("\tEnter the book number:");
bno=Integer.parseInt(br.readLine());
System.out.print("\tEnter the book u want:");
buknam=br.readLine();
System.out.print("\tEnter the author's name:");
auth=br.readLine();
System.out.print("\tEnter the edition:");
edit=Integer.parseInt(br.readLine());
System.out.print("\tEnter the date of issuing:");
date=Integer.parseInt(br.readLine());
System.out.print("\tEnter the return date:");
ret=Integer.parseInt(br.readLine());
}
}
class fin extends lib
{
void get1()throws IOException
{
BufferedReader br2=new BufferedReader(new InputStreamReader(System.in));
System.out.print("\tuser returning date:");
userdt=Integer.parseInt(br2.readLine());
if(userdt>ret+10)
{
System.out.println("\t\t PAY THE FINE AMOUNT...!!!! RS:"+fine+"/-");
}
}
void disp()
{
System.out.println("\t THANKS FOR USING OUR SERVICE...:-)...");
}
}
class libmain
{
public static void main(String ar[])throws Exception
{
BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
int s,k=0,i;
fin f=new fin();
System.out.println("\n\t\t^*^*^*^*^*^*^* LIBRARY MANAGEMENT ^*^*^*^*^*^*^");
do
{
System.out.println("------------------MENU-------------------------------");
System.out.println("\nENTER UR CHOICE\n\t1.GONNA TAKE A BOOK\n\t2.RETURN THE BOOK\n\t3.EXIT");
s=Integer.parseInt(br1.readLine());
switch(s)
{
case 1:
f.get();
f.disp();
break;
case 2:
f.get();
f.get1();
break;
case 3:
k=1;
break;
}
}
while(k==0);
}
}
with regards
sm.muthu :-)