How to create a class in java

How to create a class in java

I am a beginner in programming and tried to learn how to do programming in Java. Friends please explain how can I create a class in Java.

View Answers

January 5, 2013 at 12:48 PM

hi friend, As you said that you are a learner of Java programming and want to create a class in Java so, lets understand first what is class in Java.

Class in Java is a blueprint that facilitate you to declare data members and methods as well as to define methods.

Here sample code is being given which demonstrates how to create a class in Java.

public class JavaSampleClass
{
   int i = 5;
   String str = "How to create a class in Java";
   public void intDisplay()
    {
       System.out.println(i);
    }
   public void strDisplay()
    {
       System.out.println(str);
    }   
}









Related Tutorials/Questions & Answers:
How to create a class in java
How to create a class in java  I am a beginner in programming and tried to learn how to do programming in Java. Friends please explain how can I create a class in Java
to create a java class and methods
to create a java class and methods  How to create a java class without using the library class to represent linked lists of integers and also provide it with methods that can be used to reverse a list & append two lists.Also
Advertisements
create named class - Java Beginners
create named class  Can you check my coding@program: How to create a class named Employee with name and salary. Make a class Manager inherit from...() that prints the manager?s name, department and salary. Make another class named
create a class
create a class  plz provide any example related to class
Create Action class
Create Action Class An action is an important portion of web application... an action class you need to extend or import the Action classes or interface... package. The commonly used action class is ActionSupport. An example of action
how to create interfaces in java
how to create interfaces in java  HI, Here is my code public interface validateInfo { public void validate(String empcode, String password); } class updateInfo implements validateInfo { public void update() { //code
how to create notepad in java
how to create notepad in java  how to create notepad in java
How to create charts in Java?
How to create charts in Java?  Is there any example of creating charts and graphs in Java? thanks   Hi, check the tutorial: Chart & Graphs Tutorials in Java Thanks
How to Create Keyboard in JAVA
How to Create Keyboard in JAVA  please help me to create On-Screen Keyboard with java and please give me an another idia to make it ..............iam waiting for your help ,think u so much
How to Create CurveDraw In Java
How to Create CurveDraw In Java       Introduction In this section, you will learn how to create CurveDraw in java.awt package. This class,supported by the java.awt.geom package
Java Thread class
Java Thread Class is a piece of the program execution Java has... It is created by extending the Thread class or implementing Runnable interface Java Thread Class Example public class thread1 extends Thread { @Override
how create package of this java code
how create package of this java code  Hi,i have email code in java... java.io.*; public class sendmail { private static final String SMTPHOSTNAME...); msg.setContent(message, "text/plain"); Transport.send(msg); } private class
how create package of this java code
how create package of this java code  Hi,i have email code in java...*; import java.io.*; public class sendmail { private static final String..., "text/plain"); Transport.send(msg); } private class
how to create executable - Java Beginners
how to create executable  How do i create a executable file from a java file thnks in adv...!  Hi Friend, Try the following code: import java.io.*; import java.util.jar.*; public class CreateExe { public
How to create first Java Program?
How to create first Java Program?  Hi, I am beginner and I want to write first Java program. How I can setup my machine and write first Java program... and run first Java program: Create program in Note pad: Step 1: Open
how to create reports in swing java?
how to create reports in swing java?  how to create reports in swing java
How to create first program in Java?
How to create first program in Java?  Hi, I am new in Java programming. Tell me How to create first program in Java? Thanks   Hi, Read more at First Java Program. Thanks
How to create and use Array in Java?
How to create and use Array in Java?  Hi, How to create and use Array in Java? Write program to construct and use the array. Thanks   Hi... can read complete example at Array in Java. Thanks
In Java how to get size of class and object?
In Java how to get size of class and object?  In Java how to get size of class and object
In Java how to get size of class and object?
In Java how to get size of class and object?  In Java how to get size of class and object
How do I decompile Java class files?
How do I decompile Java class files?  How do I decompile Java class files
How to create custom exception in Java?
How to create custom exception in Java? In this tutorial we are going to create our own exception class and you will learn the steps to create custom exception class. Custom exceptions are used by Java developers to create
Create Thread by Extending Thread
Create Thread by Extending Thread This section explain how to create thread by extending Thread class in java. Extending Thread : You can create thread... are extending Thread class to create thread. class ThreadClass extends
Create new file in java
Create new file in java We are going to discuss how to create new file in java. First of all we have create class "CreateFile".and after that we.... With File class we create files and directories. Java File represents actual
Can you create an object of an abstract class?
Can you create an object of an abstract class?   Hi, Can you create an object of an abstract class? Thanks
can i restrict a class that it will not allows create more than two objects - Java Interview Questions
can i restrict a class that it will not allows create more than two objects  hi all, can i restrict a class that it will not allows create more than two objects can any help me please. Thaks bala k
How to create new arraylist using Java
someone provides online example how to create new arraylist in java programming. thnaks,   Hi, In java programming language you can create new...How to create new arraylist using Java  hi, I want to develop
how to include a java class in jsp - JSP-Servlet
how to include a java class in jsp  hello sir, this is my first question, i want know that how to use a java class function's variables and methods of a java class in jsp.if possible plz tr to explain with a simple example
how many ways to load the class in java
how many ways to load the class in java  i know some ways to load the class. could plz tell the all the ways.    there r 3 ways to create objects. 1.by using new operator 2.clone() method 3.new Instance(). and some
how to call a java class in jsp - JSP-Servlet
how to call a java class in jsp  hi.. friends iam new to roseindia.i found it very nice site to clarify our douts. i have a problem to use my java class in a jsp.can anyone please help me with this query
how to call a java class in jsp - JSP-Servlet
how to call a java class in jsp  hi.. friends iam new to roseindia.i found it very nice site to clarify our douts. i have a problem to use my java class in a jsp.can anyone please help me with this query
How to Create Circle In Java
How to Create Circle In Java     ..., you will learn how to create Circle Diagram. The java circle is the most...: In this program, you will also show that how to create square drawing. Inside
how to create this diamond structure with java. - Java Beginners
how to create this diamond structure with java.   * *** ***** * *** *** * ***** * *** *** * ***** * *** *** * ***** *** *  ..., Try the following code: class Stars{ public static void main(String
How to create LineDraw In Java
How to create LineDraw In Java     ... will learn how to create Line Drawing. This program  implements a line Drawing component. A java program explains the stroke line i.e. how to make thick
how can create clock baisc in java
how can create clock baisc in java   think u for help me ..   import java.awt.*; import java.util.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; public class DisplayClock extends JFrame
how can create clock baisc in java
how can create clock baisc in java   think u for help me ..   import java.awt.*; import java.util.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; public class DisplayClock extends JFrame
how can create clock baisc in java
how can create clock baisc in java   think u for help me ..   import java.awt.*; import java.util.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; public class DisplayClock extends JFrame
how to get session object in simple java class??
how to get session object in simple java class??  i am fallowing...) GroupDetailsDao.java (it is also a simple java class which have the jdbc logic... java class (GroupDetailsDao.java) please help me
How to create a Java Runtime Editor - Swing AWT
How to create a Java Runtime Editor   Hi, I am working on a requirement in which I need to integrate a java runtime editor in swing application... using java swing, try the following code: import java.awt.BorderLayout
how to set class path
how to set class path  how to set class path in java
how to sort the result of this 2 class program in java.....????
how to sort the result of this 2 class program in java.....????  package setget1_method; import java.util.Scanner; public class Main... setget1_method; class LBook { private String title; private String author; private int
Create a float buffer by using wrap method of FloatBuffer class.
Create a float buffer by using wrap method of FloatBuffer class. In this tutorial, we will see how to create a float buffer by using wrap method of FloatBuffer class. ByteBuffer API. The java.nio.FloatBuffer class extends
How to Create Text Area In Java
How to Create Text Area In Java       In this section, you will learn how to create Text Area in Java... the topic. Program Description:ADS_TO_REPLACE_1 Here, a class "
how to create users in LDAP using java?
how to create users in LDAP using java?  how to create users in LDAP using java
how to create exce sheet using java
how to create exce sheet using java  how to create excel sheet using java
how to create an excel file using java
how to create an excel file using java  how to create an excel file using java
how to create a header in jtable using java swing
how to create a header in jtable using java swing  how to create a header in jtable using java swing   d
Create a short buffer by using wrap method of ShortBuffer class.
Create a short buffer by using wrap method of ShortBuffer class. In this tutorial, we will see how to create a shortt buffer by using wrap method of ShorttBuffer class. ShortBuffer API. The java.nio.ShortBuffer class extends
How to Compress file using DeflaterOutputStram class in java.
How to Compress file using DeflaterOutputStram class in java. In this tutorial, we will discuss  how to use DeflaterOutputStream class in java... class create an output stream with a specific compressor.  The Defleter
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response

Ads