Question about Computers & Internet

1 Answer

What an abstract class in java ? and what is an interface in java ? please give examples if possible

Posted by on

  • sumitnxt Nov 18, 2009

    great.. thanks

×

1 Answer

  • Level 3:

    An expert who has achieved level 3 by getting 1000 points

    All-Star:

    An expert that got 10 achievements.

    MVP:

    An expert that got 5 achievements.

    Vice President:

    An expert whose answer got voted for 100 times.

  • Master
  • 350 Answers

An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this:
abstract void moveTo(double deltaX, double deltaY);
If a class includes abstract methods, the class itself must be declared abstract, as in: public abstract class GraphicObject {
// declare fields
// declare non-abstract methods
abstract void draw();
}
When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, the subclass must also be declared abstract.


In the Java programming language, an interface is a reference type, similar to a class, that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces. Extension is discussed later in this lesson. Defining an interface is similar to creating a new class:
public interface OperateCar {

// constant declarations, if any

// method signatures
int turn(Direction direction, // An enum with values RIGHT, LEFT
double radius, double startSpeed, double endSpeed);
int changeLanes(Direction direction, double startSpeed, double endSpeed);
int signalTurn(Direction direction, boolean signalOn);
int getRadarFront(double distanceToCar, double speedOfCar);
int getRadarRear(double distanceToCar, double speedOfCar);
......
// more method signatures
}
Note that the method signatures have no braces and are terminated with a semicolon. To use an interface, you write a class that implements the interface. When an instantiable class implements an interface, it provides a method body for each of the methods declared in the interface. For example,
public class OperateBMW760i implements OperateCar {

// the OperateCar method signatures, with implementation --
// for example:
int signalTurn(Direction direction, boolean signalOn) {
//code to turn BMW's LEFT turn indicator lights on
//code to turn BMW's LEFT turn indicator lights off
//code to turn BMW's RIGHT turn indicator lights on
//code to turn BMW's RIGHT turn indicator lights off
}

// other members, as needed -- for example, helper classes
// not visible to clients of the interface

}
In the robotic car example above, it is the automobile manufacturers who will implement the interface. Chevrolet's implementation will be substantially different from that of Toyota, of course, but both manufacturers will adhere to the same interface. The guidance manufacturers, who are the clients of the interface, will build systems that use GPS data on a car's location, digital street maps, and traffic data to drive the car. In so doing, the guidance systems will invoke the interface methods: turn, change lanes, brake, accelerate, and so forth.
I hope this helps and good luck!
what an abstract class in - 22e7160.png

Posted on Nov 18, 2009

1 Suggested Answer

6ya6ya
  • 2 Answers

SOURCE: I have freestanding Series 8 dishwasher. Lately during the filling cycle water hammer is occurring. How can this be resolved

Hi,
a 6ya expert can help you resolve that issue over the phone in a minute or two.
best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.
the service is completely free and covers almost anything you can think of (from cars to computers, handyman, and even drones).
click here to download the app (for users in the US for now) and get all the help you need.
goodluck!

Posted on Jan 02, 2017

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

3 Answers

Can you give me examples of abstact nouns


Abstract nouns are things that cannot be experienced with the five senses.Things such as: Compassion, courage, intelligence, and laughter.Good examples are listed : http://examples.yourdictionary.com/examples-of-abstract-nouns.html

Aug 28, 2014 | Healthy Learning Relational Aggression:...

1 Answer

What difference between genricServlet and httpServlet


public abstract class GenericServlet extends java.lang.Object implements Servlet, ServletConfig, java.io.Serializable
  • GenericServlet defines a generic, protocol-independent servlet.
  • GenericServlet gives a blueprint and makes writing servlet easier.
  • GenericServlet provides simple versions of the lifecycle methods init and destroy and of the methods in the ServletConfig interface.
  • GenericServlet implements the log method, declared in the ServletContext interface.
  • To write a generic servlet, it is sufficient to override the abstract service method.
javax.servlet.http.HttpServlet
Signature: public abstract class HttpServlet extends GenericServlet implements java.io.Serializable
  • HttpServlet defines a HTTP protocol specific servlet.
  • HttpServlet gives a blueprint for Http servlet and makes writing them easier.
  • HttpServlet extends the GenericServlet and hence inherits the properties GenericServlet.

May 12, 2011 | Computers & Internet

1 Answer

Good morning,i have to make minor prjt in java.


The simplest basic java is the hello world ! example.
class myfirstjavaprog
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
http://www.javacoffeebreak.com/java101/java101.html

Aug 31, 2009 | Microsoft Windows XP Professional

1 Answer

Javac unable to compile java error or batch file?


first of all you have to set path for your jdk
have you done that???????

if not then go to youtube.com and search for that vedio.

if yes, then i think you have not named the project properly

when you are to save your project, name it in the "name of the main class.java"


for example:

class Manju
{
   public static void main(String arg[]s)
     {
       ___________________________;
       ___________________________;
     }
}

save it as Manju.java and then compile

no matter what other classes are being related to the project.

this much i only know

if you wanna contact me or chat with me, my email id is linushwahs@gmail.com

May 16, 2009 | Microsoft Windows XP Professional

1 Answer

In cpp programming why do we go for abstract base class?


Virtual keyword allows the program to dynamically decide which function to call. That is, when derived class is inherited from a base class the function in derived class can perform a completely different action from the one in Base class. Hence the function call via a pointer or reference maps to different functions based on the type of the object.

Abstract base class is used, so that anyone who is inherting from this class should implement that interface. Because the base class may not have a meaningful implementation for that interface. For example to design a program for computing area of different shapes like rectangle, triangle, hexagon etc. base class can be thought of as Shape. In addition the base class can be made abstract by declaring Area to be a pure virtual function. Then the different shapes like Rectangle, Triangle classes can inherit from Shape and implement Area interface based on their formulae.

Apr 06, 2009 | Microsoft Computers & Internet

4 Answers

Can anyone tell how run java program in cmd prompt???


Hi,

You need to type:

If it's a program.class

java program

or of it's a program.jar

java -jar program.jar

regards

Apr 03, 2009 | Sun Java Programming Language (cdj-275)

1 Answer

How to write jdbc connections


http://www.jdbc-tutorial.com/

window.google_render_ad();

welcome_title_image.gif Java JDBC Tutorial Java JDBC Tutorial
The JDBC ( Java Database Connectivity) API defines interfaces and classes for writing database applications in Java by making database connections. Using JDBC you can send SQL, PL/SQL statements to almost any relational database. JDBC is a Java API for executing SQL statements and supports basic SQL functionality. It provides RDBMS access by allowing you to embed SQL inside Java code. Because Java can run on a thin client, applets embedded in Web pages can contain downloadable JDBC code to enable remote database access. You will learn how to create a table, insert values into it, query the table, retrieve results, and update the table with the help of a JDBC Program example.


window.google_render_ad();
Although JDBC was designed specifically to provide a Java interface to relational databases, you may find that you need to write Java code to access non-relational databases as well.
JDBC Architecture jdbc.jpg Java application calls the JDBC library. JDBC loads a driver which talks to the database. We can change database engines without changing database code.
JDBC Basics - Java Database Connectivity Steps Before you can create a java jdbc connection to the database, you must first import the
java.sql package.
import java.sql.*; The star ( * ) indicates that all of the classes in the package java.sql are to be imported.
1. Loading a database driver,
In this step of the jdbc connection process, we load the driver class by calling Class.forName() with the Driver class name as an argument. Once loaded, the Driver class creates an instance of itself. A client can connect to Database Server through JDBC Driver. Since most of the Database servers support ODBC driver therefore JDBC-ODBC Bridge driver is commonly used.
The return type of the Class.forName (String ClassName) method is “Class”. Class is a class in
java.lang package.
try { Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”); //Or any other driver } catch(Exception x){ System.out.println( “Unable to load the driver class!” ); } 2. Creating a oracle jdbc Connection

The JDBC DriverManager class defines objects which can connect Java applications to a JDBC driver. DriverManager is considered the backbone of JDBC architecture. DriverManager class manages the JDBC drivers that are installed on the system. Its getConnection() method is used to establish a connection to a database. It uses a username, password, and a jdbc url to establish a connection to the database and returns a connection object. A jdbc Connection represents a session/connection with a specific database. Within the context of a Connection, SQL, PL/SQL statements are executed and results are returned. An application can have one or more connections with a single database, or it can have many connections with different databases. A Connection object provides metadata i.e. information about the database, tables, and fields. It also contains methods to deal with transactions.
JDBC URL Syntax:: jdbc: <subprotocol>: <subname> JDBC URL Example:: jdbc: <subprotocol>: <subname>•Each driver

Feb 01, 2009 | Microsoft Windows XP Home Edition

2 Answers

StartActivity fails to launch class called


This example is working try it.

Forwarding.java
----------------------

package com.example.android.apis.graphics;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Forwarding extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.forwarding);
Button goButton = (Button)findViewById(R.id.go);
goButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
Intent intent = new Intent();
intent.setClass(Forwarding.this, ForwardTarget.class);
startActivity(intent);
finish();
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
});
}
}


ForwardTarget
--------------------

package com.example.android.apis.graphics;
import android.app.Activity;
import android.os.Bundle;
public class ForwardTarget extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

setContentView(R.layout.forward_target);
}
}



AndroidManifest.xml
-----------------------------

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.apis.graphics"
android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Forwarding"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ForwardTarget"/>
</application>
</manifest>


forwarding.xml
---------------------

<?xml version="1.0" encoding="utf-8" ?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:padding="4dip"
android:gravity="center_horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="0"
android:paddingBottom="4dip" android:text="forwarding" />
<Button android:id="@+id/go" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="go">
<requestFocus />
</Button>
</LinearLayout>

forward_target.xml
---------------------------

<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:padding="4dip"
android:gravity="center_horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="0"
android:text="forward_target" />
</LinearLayout>


Nov 03, 2008 | Google Android

1 Answer

Java


Look into using the Process class to execute a command you might use on the command line (DATE in your case). Small tutorial that you can use to get you started is at: http://java.sun.com/developer/JDCTec.../tt0304.html#1

You'll probably have to run this command with administrator privileges...not too familiar with Windows.

On a side note, if you use this approach, the example doesn't close any of the streams that were opened to read the output of the command issued. You should do this to avoid unwanted resource consumption.
golu_fixya
thanks

Oct 14, 2008 | Computers & Internet

1 Answer

Schema classes and attributes


Every directory object you create is an instance of an object class contained in the schema. Each object class contains a list of associated attributes that determine the information the object can contain. Classes and attributes are defined independently, so that a single attribute can be associated with multiple classes. All schema classes and attributes are defined by the classSchema and attributeSchema objects, respectively.

Classes

ClassSchema objects are used to define classes in the schema. A classSchema object provides the template for building directory objects of that class. Examples of classSchema include User and Server. A classSchema object contains, among other things, the following information:
Class type (structural, abstract, or auxiliary)

Common name and Lightweight Directory Access Protocol (LDAP) display name

Lists of the "must contain" and "may contain" attributes for instances of the object

Relative distinguished name attribute

A list of possible parent classes

Class types

Three different types of classes exist in the schema:Class type Purpose

Structural
Used to instantiate objects (users, servers and so on) in the directory.

Abstract
Provides templates for deriving structural classes

Auxiliary
Contains predefined lists of attributes that can be included in structural and abstract classes

Attributes

AttributeSchema objects are used to define attributes in the schema. An attributeSchema object determines the allowable contents and syntax for instances of that attribute in the directory. Examples of attributeSchema include User-Principal-Name and Telex-Number. An attributeSchema object contains, among other things, the following information:•
Common name and LDAP display name

Syntax rules

Data constraints (single versus multivalued, minimum, and maximum values)

Whether and how the attribute is indexed

Jul 17, 2008 | Microsoft Windows Server Standard 2003 for...

Not finding what you are looking for?
Computers & Internet Logo

Related Topics:

24 people viewed this question

Ask a Question

Usually answered in minutes!

Top Computers & Internet Experts

Doctor PC
Doctor PC

Level 3 Expert

7733 Answers

kakima

Level 3 Expert

102366 Answers

David Payne
David Payne

Level 3 Expert

14161 Answers

Are you a Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...