Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

java tech

+ Follow
since Jul 13, 2005
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by java tech

Interface can fully abstract a class interface from its implementation that�s using this we can specify what a class do but not how it does it. Interfaces are similar to classes but they don�t have instance variables and there methods are declared without a body. Once it is defined, any number of classes can implement interface and one class can implement any number of interfaces. Each class is free to determine the details of its own implementation.
For example:

Interface callback{
Void callback(int param)

Access is either public or not specified, if not specified then it is considered to be default and interface is available to other members of the package. Variables can be declared inside interface declaration. They are however implicitly final and static that is they cannot be changed by the implementing class. Variable and method are public if access declaration is public.

Implementing Interfaces

Class client implements callback{
Public void callback(int p){
System.out.println(�callback called with � +p);

If a class implement two interface that declare the same methode then the same method will be used by clients of either interface.
A class which implements interface can be define additional members of its own class.

Accessing Implementations through interface References

We can also declare variable as object references that use an interface. Any instance of a class that implement the declared interface can be referred to by such a variable.When we call a method through one of the references, the correct version will be called based on the actual instance of the interface being referred to. The methode to be executed is looked up dynamically at run time ,allowing classes to be created later than the code which calls method on them.

For Examle:
Class testIface
Public static void main(String args[]){
Callback c= new client();
Variable c is declared to be of the interface type callback, but it is assigned as instance of client. C can be used to access the callback() method ,it cannot access any other member of client class .An interface variable only has knowledge of the methods declared by its interface declaration, this c could not be used to access non interface method since it is defined by client but not callback.
If a class includes an interface but doesn�t fully implement the methods defined by that interface, then that class must be declared as abstract.

Abstract class Incomplete implements callback{
Int a,b;
Void show(){
System.out.println(a+ � �+b);

Interface tool is an important part of java program environment. In C++ we have multiple inheritance so a class can inherit from many classes but since it causes a lot of ambiguity this procedure is avoided in java and instead we use interfaces which once declared can be called in any number of classes any number of times.
15 years ago
In C & C++ the name of each class or function was taken from the same namespace. This means a unique name has to be used for each class name to avoid class name collision. But using this procedure , after a while we run out of convenient, descriptive names for individual classes. We must assure that the name we choose should be unique and not collide with class names chosen by other programmers. To solve this problem Java provides a mechanism for partitioning the class namespace into manageable chunks. This mechanism is the PACKAGE. Packages are containers for classes that are used to keep the class name space compartmentalized. The package is both a naming and a visibility control mechanism. We can define classes inside a package that are not accessed by the code outside that package. This allows our classes to have intimate knowledge to the rest of the world.
In general , a Java source file can contain any of the following four internal parts:
�A single package statement (optional).
�Any number of import statements (optional).
�A single public class declaration (required).
�Any number of classes private to the package (optional).

To create a package is quite easy: we just have to include a package command as the first statement in a java source file. Any classes declared within that file will belong to the specified package. The package statement defines a namespace in which classes are stored . If we omit the package statement ,the class names are put into the default package, which has no name.

package Mypack;

Java uses file system directories to store packages. For example , the .class files for any classes is to be declared a part of Mypack must be stored in a directory called Mypack
More than one file can include the same package statement.
We can also create a hierarchy of packages. To do so we simply separate package name by using a period.

package Mypack.pk1;

We cannot rename a package without renaming the directory in which the classes are stored.
A simple question arises in our mind ,how does the Java run-time system know where to look for packages that we create. First , by default , the Java run-time system uses the current working directory as its starting point. Thus if our package is in the current directory ,or a subdirectory of the current directory ,it will be found. Second ,we can specify a directory paths by setting the CLASSPATH environmental variable.
For example in order for a program to find Mypack, one of two things must be true. Either the program is executed from a directory immediately above Mypack, or CLASSPATH must be set to include the path to Mypack.
Java also include import statement to bring certain classes,or entire packages, into visibility. Once imported ,a class can be referred to directly by using its name.

import pkg1.pkg2.*;

for example we can import using the following statement

import java.util.*;
class MyDate extends Date{

Packages are used extensively while writing programs in java so that we can use the same name for referring to different programs & there is no namespace collision.
15 years ago
Hi friends
I always wondered what is the need of java when we have languages like C through which we can program most efficiently and a language like C++ which implements OOPs principle which help organize complex program through the use of inheritance, encapsulation and polymorphism .When I tried to find out the answer to my query I realized it is the �Complexity� that we need another language java for programming.
Java was first conceived by James Gosling, Patrick Naughton, Chris Warth, Ed frank and Mike Sheridan at Sun Microsystems in 1991.The language was initially called �OAK� but was renamed as JAVA.

There is a vast amount of similarity between C++ and Java. First, Java was designed ,tested and refined by real working programmers. It is a programmer�s language. Second, Java is cohesive and logically consistent. Third it gives programmer full control. Its because of similarities between Java and C++, people mostly think of Java as simply the Internet version of C++. But it is a big Myth. Java is neither upwardly nor downwardly compatible with C++.

The common thought is that the original impetus for java is internet, instead the primary motivation was the need for a platform-independent language that could be used to create software to be embedded in various consumer electronics devices, such as microwave ovens and remote controls. Many different type of CPUs are used as controllers.

The trouble with C and C++ is that they are designed to be compiled for a specific target .Although it is possible to compile a C++ program for any type of CPU but we require a full C++ compiler targeted for CPU. The major problem that comes in is that it is expensive and time consuming to create. A easier and cost efficient solution was needed, this effort led to creation of Java.

The second force was World Wide Web. Java can be used to create two types of programs Application and Applets.
Application is a program that runs on an computer under the Operating System of our computer. Applet is a application designed to be transmitted over the Internet and executed by a java compatible web browser. It is a program that can react to user input and dynamically change. Two fundamental problem associated with this is Security and Portability. Java answers to both these concerns by providing a firewall between a networked application and over computer.

To overcome the problem of portability we translate java in bytecode. Byte code is highly optimized set of instruction designed to be executer by java runtime system Java Virtual Machine. Once run-time Package exists for a given system, any java program can run on it. Sun supplies Just In Time (JIT) computer for bytecode. It compiles bytecode into executable code in real time on demand basis that is it compiles when its needed. This yields significant performance boost.
The initial release of Java was nothing short of revolutionary, but it did not mark the end of Java�s era of rapid innovation. It is just the beginning.
15 years ago