What are the benefits of using Abstract Data Types?
Why should an object hide its data?
As my AP Computer Science teacher eloquently said:
"You can't let strangers touch your private parts"
Therefore, if data was not hidden, a client class can modify all the variables(given that it is not a final constant) by simply calling:
className.variableName = newWrongData;
By using special methods to access the variables, the class can change its internal implementation, without breaking compatibility with other classes that are already using it.
How do you write a Java program to convert a decimal number to an octal number?
public class Dataconversion {
public static void main(String[] args) {
System.out.println("Data types conversion example!");
int in = 44;
System.out.println("Integer: " + in);
//integer to binary
String by = Integer.toBinaryString(in);
System.out.println("Byte: " + by);
//integer to hexadecimal
String hex = Integer.toHexString(in);
System.out.println("Hexa decimal: " + hex);
//integer to octal
String oct = Integer.toOctalString(in);
System.out.println("Octal: " + oct);
}
}
How do you convert java class file into exe file?
This isn't done. Exe is Windows executible file format. If you're tring to use a java program, you'll need to have the latest version of java installed on your computer. Then you should be able to start the java application same as you would an exe file (double click it)
However, there are wrapper applications out there that will basically combine the aforementioned process in an exe. Sometimes this wrapper is included with various Java IDE's, or can be downloaded separately.
It is also possible to compile the source code of a program written in Java directly to a native binary (that is, a *.exe file on Windows). Several Java to Native compilers exist.
Also, there are several programs available that can change .class files to .exe files.
I think both of them are very good and useful, but they are different of course, for example java is more secure and safe programming, but is also depended how web browsers support it, php is the programming which is relevant for all web servers.
What is the state of an object in java?
Each Java object has varaibles - which in this case are called fields. They store information about the object. For example, a class to store a date might have "fields" to store the day, the month and the year. The values stored in these fields are collectively called the object's "state".
What are some examples of procedural and non procedural programming?
Procedural programming is classic programming where the program language is used to tell the computer EXACTLY what do do - step by step. Examples are Assembler, Fortran, Cobol, C, etc etc. Very detailed, very difficult and time consuming to write, but very efficient from the computers point of view. NON-procedural programming is where you tell the computer what you want, and it figures out how to get it. Non/P programming is often used for database manipulations, like SQL, Visual Basic, etc etc. A SQL command like "Select name, address, city, state, zip order by zip" is non procedural. That one line replaces dozens, or hundred of lines, that would be needed to do the same thing in Cobol or C to get data out of a database.
Why you say main is a user defined function?
In C programming there is no real difference. The only criteria associated with the main function is that it must have one (and only one) of the following prototypes:
int main (void);
int main (char* argv[], int argc);
The first is used when the program accepts no arguments, while the second is used when it does accept arguments. The argv argument is a null-terminated array of null-terminated strings, where argv[0] is the fully-qualified path to the executable and argv[argc] is the array's null-terminator.
Some implementations allow other prototypes, however these are non-standard and therefore not guaranteed to be portable across all implementations.
In C++ the main function must be declared in the global namespace. All user-defined functions should (ideally) be declared in user-defined namespaces to avoid polluting the global namespace. In C there are no namespaces; all functions are global. Although C++ supports function overloading, this does not apply to the main function; there can be only one global main function.
In C++, when we reach the end of the main function without encountering a return statement, the all-zeroes bit pattern is implicitly returned. The all-zeroes bit pattern is typically used to denote no error, hence it is the default. However, in C, there is no default return value so a return statement is obligatory. The all-ones bit pattern is typically used to explicitly denote that some error occurred. Other bit patterns may be explicitly returned to denote specific types of error, however not all execution environments make use of the return value.
Other than that, the main function is no different to any other user-defined function.
Hi all,
javascript is case sensitive vbscript is not.
javascript will explore in all the browser, vb accept only internet explore
javascript only for client side, vbscript both client side and serverside
js is client side validation,vbscript for server side validation
if you don't get. u can reach me iamselvam85@gmail.com
Find out prime number between 1 to 100 in java?
public class v3
{
public static void main()
{
int b=0,i;
for(i=1;i<=100;i++)
{
for(j=1;j<=i;)
{
if(i%j==0)
{
b=j;
System.out.print(b+" ");
b=0;
}
}
}
}
}
What role does abstraction play in object oriented programming?
Eg If we consider a car which has lot of parts such as wheels steering DVD player etc.
We need to know how to use it. We need not know what is the
structure of all these parts to buy and drive a car.
Another eg is Television. The Television has lot of properties and behavoiurs like height width displayOn,displayOff etc and also it has chips and internal wires which enables the television's functions.
But for working the Television we don't need to know these internal things.
What are Principles of object oriented programming language?
Java is an object oriented programming language. The main concepts used in Java are:
Class
Defines the abstract characteristics of a thing (object), including the thing's characteristics (its attributes, fields or properties) and the thing's behaviors (the things it can do, or methods, operations or features). One might say that a class is a blueprint or factory that describes the nature of something. For example, the class Dog would consist of traits shared by all dogs, such as breed and fur color (characteristics), and the ability to bark and sit (behaviors). Classes provide modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, meaning that the characteristics of the class should make sense in context. Also, the code for a class should be relatively self-contained (generally using encapsulation). Collectively, the properties and methods defined by a class are called members.
Object
A pattern (exemplar) of a class. The class of Dog defines all possible dogs by listing the characteristics and behaviors they can have; the object Lassie is one particular dog, with particular versions of the characteristics. A Dog has fur; Lassie has brown-and-white fur.
Instance
One can have an instance of a class or a particular object. The instance is the actual object created at runtime. In programmer jargon, the Lassie object is an instance of the Dog class. The set of values of the attributes of a particular object is called its state. The object consists of state and the behaviour that's defined in the object's class.
Method
An object's abilities. In language, methods (sometimes referred to as "functions") are verbs. Lassie, being a Dog, has the ability to bark. So bark() is one of Lassie's methods. She may have other methods as well, for example sit() or eat() or walk() or save_timmy(). Within the program, using a method usually affects only one particular object; all Dogs can bark, but you need only one particular dog to do the barking.
Message passing
"The process by which an object sends data to another object or asks the other object to invoke a method." Also known to some programming languages as interfacing. For example, the object called Breeder may tell the Lassie object to sit by passing a "sit" message which invokes Lassie's "sit" method. The syntax varies between languages, for example: [Lassie sit] in Objective-C. In Java, code-level message passing corresponds to "method calling". Some dynamic languages use double-dispatch or multi-dispatch to find and pass messages.
Inheritance
"Subclasses" are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own.
For example, the class Dog might have sub-classes called Collie, Chihuahua, and GoldenRetriever. In this case, Lassie would be an instance of the Collie subclass. Suppose the Dog class defines a method called bark() and a property called furColor. Each of its sub-classes (Collie, Chihuahua, and GoldenRetriever) will inherit these members, meaning that the programmer only needs to write the code for them once.
Each subclass can alter its inherited traits. For example, the Collie class might specify that the default furColor for a collie is brown-and-white. The Chihuahua subclass might specify that the bark() method produces a high pitch by default. Subclasses can also add new members. The Chihuahua subclass could add a method called tremble(). So an individual chihuahua instance would use a high-pitched bark() from the Chihuahua subclass, which in turn inherited the usual bark() from Dog. The chihuahua object would also have the tremble() method, but Lassie would not, because she is a Collie, not a Chihuahua. In fact, inheritance is an "a... is a" relationship between classes, while instantiation is an "is a" relationship between an object and a class: a Collie is a Dog ("a... is a"), but Lassie is a Collie ("is a"). Thus, the object named Lassie has the methods from both classes Collie and Dog.
Multiple inheritance is inheritance from more than one ancestor class, neither of these ancestors being an ancestor of the other. For example, independent classes could define Dogs and Cats, and a Chimera object could be created from these two which inherits all the (multiple) behavior of cats and dogs. This is not always supported, as it can be hard both to implement and to use well.
Abstraction
Abstraction is simplifying complex reality by modelling classes appropriate to the problem, and working at the most appropriate level of inheritance for a given aspect of the problem.
For example, Lassie the Dog may be treated as a Dog much of the time, a Collie when necessary to access Collie-specific attributes or behaviors, and as an Animal (perhaps the parent class of Dog) when counting Timmy's pets.
Abstraction is also achieved through Composition. For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and many more components. To build the Car class, one does not need to know how the different components work internally, but only how to interface with them, i.e., send messages to them, receive messages from them, and perhaps make the different objects composing the class interact with each other.
Encapsulation
Encapsulation conceals the functional details of a class from objects that send messages to it.
For example, the Dog class has a bark() method. The code for the bark() method defines exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and volume). Timmy, Lassie's friend, however, does not need to know exactly how she barks. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface - those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in future, thereby allowing those changes to be made more easily, that is, without changes to clients. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected or private, determining whether they are available to all classes, sub-classes or only the defining class. Some languages go further: Java uses the default access modifier to restrict access also to classes in the same package, C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow one to specify which classes may access any member.
Polymorphism
Polymorphism allows the programmer to treat derived class members just like their parent class' members. More precisely, Polymorphism in object-oriented programming is the ability of objects belonging to different data types to respond to method calls of methods of the same name, each one according to an appropriate type-specific behavior. One method, or an operator such as +, -, or *, can be abstractly applied in many different situations. If a Dog is commanded to speak(), this may elicit a bark(). However, if a Pig is commanded to speak(), this may elicit an oink(). They both inherit speak() from Animal, but their derived class methods override the methods of the parent class; this is Overriding Polymorphism. Overloading Polymorphism is the use of one method signature, or one operator such as "+", to perform several different functions depending on the implementation. The "+" operator, for example, may be used to perform integer addition, float addition, list concatenation, or string concatenation. Any two subclasses of Number, such as Integer and Double, are expected to add together properly in an OOP language. The language must therefore overload the addition operator, "+", to work this way. This helps improve code readability. How this is implemented varies from language to language, but most OOP languages support at least some level of overloading polymorphism. Many OOP languages also support Parametric Polymorphism, where code is written without mention of any specific type and thus can be used transparently with any number of new types. Pointers are an example of a simple polymorphic routine that can be used with many different types of objects.
Decoupling
Decoupling allows for the separation of object interactions from classes and inheritance into distinct layers of abstraction. A common use of decoupling is to polymorphically decouple the encapsulation, which is the practice of using reusable code to prevent discrete code modules from interacting with each other. However, in practice decoupling often involves trade-offs with regard to which patterns of change to favor. The science of measuring these trade-offs in respect to actual change in an objective way is still in its infancy.
Note: Not all of the above concepts are to be found in all object-oriented programming languages, and so object-oriented programming that uses classes is called sometimes class-based programming. In particular, prototype-based programming does not typically use classes. As a result, a significantly different yet analogous terminology is used to define the concepts of object and instance.
What are the limitation of object oriented programming language?
What is difference between array and class?
An array stores a list of values, usually of the same type. Values are distinguished by a subscript.
A class usually doesn't store objects, but it defines a template for objects. Objects based on this class store data, which can be of different types, and are distinguished by name (similar to variables). A class thus defines a new, composite, data type (so does an array, but in a more limited way).
Besides, a class can also define functions (usually called "methods"), specifically for objects of that type.
Usage example: If you want to sort 100 numbers, or do some other work with them, you might store them in an array of numbers (integers, or floating-point numbers, depending on your needs).
If, on the other hand, you want to store information about a person, you might create a class, where you define that a "person" includes information about a first name, last name, birthdate, etc.
Advantage:
1.) Java program are platform independent, it can run on any PC or any operation system.
2.) It is dynamic, simple and robust.
3.) It is purely OOPS language having all the OOPS concept.
Disadvantage:
1.) It takes more time to execute then " C language" as it runs first on JVM (Java Virtual Machine).
2.) More memory consuming then other languages.
What is serialization in Java?
Serialization is the ability to easily store the state of an Object in memory onto some long-term medium (on a hard drive, for example). Basically, the Serializable interface allows us to tell Java to turn our Object into a byte-stream. The Object could be a document that the user is working on, or a more complex data class which needs the ability to be saved to the hard drive. Using the Serializable interface (and related I/O methods), Java will do most of the work for us.
FUNCTION OVERLOADING:
- when we define two functions with same name,in same class(may be) distinguished by their signatures
- resolved at compile time
- same method bt different parameters in each of them
FUNCTION OVERRIDING:
- when we redifine a function which is already defined in parent class
- resolved at run time
- changing the existing method
Does Java support multidimensional arrays?
Yes, Java supports multidimensional Arrays.
Syntax is
int[ ][ ] aryNumbers = new int[x][y];
x represents number of rows
y represents number of columns
What is member variable in java?
We use the term member variable to refer to variables that are defined inside a method.
Ex:
public String getName(){
String x = "ttt";
.....
}
In the method getName() x is a member variable
Is there such thing random numbers?
yes, because the number generated is from the computer's CPU database and is selected randomly therefore it must be a random number
It depends on how the numbers are generated. If they are based on things in the environment, like noise levels, then yes. If they are solely generated by computer functions, then no, they are pseudo-random numbers, which will be random enough for most purposes.
How do you overload or override a method?
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");
}
}
Draw a diamond with for loop in java?
// Import Library
import javax.swing.*;
//Beginning class Diamond
public class Diamond
{
//Main method
public static voidmain(String[] args)
{
//Declaring Variables
String strRow = null;
double dblRow = 0;
//GUI user input
strRow = JOptionPane.showInputDialog("Please enter an ODD number ");
dblRow = Integer.parseInt(strRow);
//validate a odd number
if ((dblRow % 2)== 0)
//if not an odd number user is advised
JOptionPane.showMessageDialog(null, "The number entered is not an ODD number. Please, try again");
//Building diamond
else
{
//setting up first 1/2 of the diamond - rows
for(int a=1; a<(dblRow/2+.5); a++ )
{
//Assigning empty spaces from right side
for (int b=1; b<(dblRow/2+1.5)-a; b++)
{
System.out.print(" ");
}
//filling out with *
for(int c=0; c<(a*2)-1; c++)
System.out.print("*");
System.out.println();
}
//Creating middle line of the diamond
for(int d=1; d { System.out.print("="); } System.out.println(); //setting our second 1/2 of the diamond - rows for(int a=1; a<(dblRow/2+.5); a++ ) { //Assigning empty spaces from right side in second part of diamond for(int c=0;c System.out.print(" "); //filling out with * for(int b=1; b { System.out.print("*"); } System.out.println(); } } } }
What are the OOPS Principles explain?
Some of the key OOPS principles are:
Encapsulation - The ability to make changes in your code without breaking the code of all others who use your code is a key benefit of encapsulation. You should always hide implementation details. To elaborate, you must always have your variables as private and then have a set of public methods that others can use to access your variables. Since the methods are public anyone can access them, but since they are in your class you can ensure that the code works the way that is best for you. So in a situation that you want to alter your code, all you have to do is modify your methods. No one gets hurt because i am just using your method names in my code and the code inside your method doesnt bother me much.
If you want maintainability, flexibility, and extensibility (and I guess, you do), your design must include encapsulation. You do that by:
• Keep instance variables protected (with an access modifier, mostly private).
• Make public accessor methods, and force calling code to use those methods rather than directly accessing the instance variable.
• For the methods, use the JavaBeans naming convention of set and get.
Inheritance - Inheritance is the feature by which functionality in one class is used in another class. It creates a parent child relationship between classes.
Polymorphism - Polymorphism refers to the feature wherein the same entity exists as multiple items. Ex: method overriding, method overloading etc.