Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

Java Report File

Java report file

Uploaded by

francerachit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Java Report File

Java report file

Uploaded by

francerachit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

A

INDUSTRIAL TRAINING REPORT

on

JAVA
submitted
in partial fulfilment of the Requirements for
the award of the degree of

Bachelor Of Technlogy

In

Department of Computer Science

SUBMITTED TO-: SUBMITTED BY:

Mr. Vishal Namdev Nitin Sharma

Roll no. :-21EBRCS004

3th Year 5th Sem

Department of Computer Science Engineering


GOVERNMENT ENGINEERING COLLEGE, BARAN
RAJASTHAN TECHNICAL UNIVERSITY

2023-24
ACKNOWNL EDGEMENT

We wish to express our deep sense of gratitude to our training supervisor


internshala for guiding me from the inception till the completion of the
summer training. We sincerely acknowledge him for giving his valuable
guidance, support for literature survey, critical reviews, and comments for
our training.

Words are inadequate in offering our thanks to Mr. Vishal Namdev Sir of
CSE Department, for consistent encouragement and support for shaping our
project in the presentable form.

We also like to express our thanks to all supporting CSE faculty members
who have been a constant source of encouragement for successful
completion of the project.

Also, our warm thanks to Govt. Engineering College, Baran who provide
us this opportunity to carry out, this prestigious Project and enhance our
learning in various technical fields.

Nitin Sharma
21EBRCS004

I
ABSTRACT

This report “ JAVA LANGUAGE ” aims to provide interactive platform to the


studentsto learn and grow. This software will help students in accessing their
learning and implementing capabilities. The product will help the user to work in
a highly effective and efficient environment. Students only need the will to learn
and java enabled system to take this quiz. This software also stores the details of
the user in the database which can be accessed further in future. This system
enables user to take quiz on the choice of his or her subject of interest and later
evaluate his or her learning based on the result. This provide the students with the
scope of improvement. This system also generates the final result and provides
facilities like storing the details of the user in the database. The project “JAVA
LANGUAGE” is developed with the objective of making the system reliable,
easier, fast, and more informative.

III
List of Contents

Certificate I

Acknowledgement II

Abstract III

List of Content IV

Chapter 1 : Introduction of Java 1

Chapter 2 : The Java Platform

2.1 Java and Open Source 2

2.2 Java Virtual machine 2

Chapter 3 : Installation Of Java

3.1 Check installation 3

3.2 Installing the Java Development Kit 3

3.3 Downloading and Installing 3

3.4 Note on Editions 3

Chapter 4 : Configuring Variable

4.1 Validate installation 5

4.2 Development Process with Java 5

4.3 Garbage collector 5

4.4 Classpath 5

Chapter 5 : Write, Compile And Run a Java Program

5.1 Write Source Code 6

5.2 Compile and run your Java program 6

5.3 Using the classpath 7

IV
Chapter 6 : Package

6.1 Advantage of Java Package 8

Chapter 7 : Class And Object

7.1 Class in Java 9

7.2 Properties Of Class 9

7.3 Class Declaration in Java 9

7.4 Example of Class in Java 9

7.5 Object in Java 10

7.6 Declaring Object 10

Chapter 8 : Inheritance

8.1 Why Do We Need Java Inheritance 11

8.2 Important Terminology used in Java Inheritance 11

8.3 How to Use Inheritance in Java 11

8.4 Inheritance in Java Example 11

Chapter 9 : Variable And Method

9.1 Variables in Java 12

9.2 How to Declare Variable in Java 12

9.3 How to Initialize Variable in Java 12

9.4 Types of Variable in Java 12

9.5 Method 13

9.6 Main Method 13

9.7 Constructor 13

V
Chapter 10 : Modifiers And Import Statement

10.1 Access modifiers 15

10.1.1 Table 10.1.1 15

10.2 Other Modifers 15

10.3 Import statements 15

Chapter 11 : Interface

11.1 Class methods and class variables 16

11.2 Abstract class and methods 16

Chapter 12 : Working With Classes

12.1 Difference Between What to do and How to do it 18

12.1.1 Table 12.1 18

12.2 Integrated Development Environment 19

12.3 Define getter and setter methods 20

12.4 Create an Address object 20

12.5 Solution Creating Java objects and methods 20

Chapter 14 : History Of Java 22

Chapter 15 : Features Of Java 24

Appendix IV

Reference V

VI
Chapter-1
INTRODUCTION OF JAVA

With the invention of microprocessors, the world is scientifically developed with


sophisticated equipments, systems, and devices. Microprocessors are used in computers,
televisions, and fax machines. Even the hand-held devices such as pagers, PDAs (Personal
Digital Assistant), and cell phones make use of microprocessors. All these electronic devices
are helpful because of their communication capabilities. With the increasing capabilities and
decreasing cost of information processing and networking technologies, the network is
growing rapidly for transmitting information through electronic systems.

Internet is the network of networks between different types of computers located at different
places to transmit information. Information can reach to any place in the world quickly at a
cheaper rate through the Internet. Thus, the Internet has made the world a global village for
information exchange. The emerging infrastructure of electronic devices and interconnected
computer networks create an environment that presents new challenges to software industries.
for this emerging computing environment. Java process to be a well suited programming
language. it is found suitable for networked environments involving a great variety of
computer and devices.

 Java has many characteristics that have contributed to its popularity:

 Platform independence Many languages are compatible with only one platform. Java
was specifically designed so that it would run on any computer, regardless if it was
running Windows, Linux, Mac, Unix or any of the other operating systems.

 Simple and easy to use Java's creators tried to design it so code could be written

 efficiently and easily. Multi-functional Java can produce many applications from
command-line programs to applets to Swing windows (basically, sophisticated
graphical user interfaces).

Java does have some drawbacks. Since it has automated garbage collection, it can tend to use
more memory than other similar languages. There are often implementation differences on
different platforms, which have led to Java being described as a "write once, test everywhere"
system Lastly, since it uses an abstract virtual machine", a generic Java program doesn't have
access to the Native API's on a system directly. None of these issues are fatal, but it can mean
that Java isn't an appropriate choice for a particular piece of software.

1
Chapter-2
THE JAVA PLATFORM

One thing that distinguished Jasa from some other languages is its ability to run the same
compiled code across multiple operating systems.In other languages, the source code (code
that is written by the programmer), is compiled by a compiler into an executable file. This file
is in machine language, and is intended for a single operating system/processor combination,
so the programmer would have to re-compile the program seperately for each new operating
system processor combination Java is different in that it does not compile the code directly
into machine language code. Compilation creates bytecode out of the source code. Bytecode
generally looks something like this:

a7 14 73 50 lb 92 74

When the code is run by the user, it is processed by something called the Java Virtual
Machine (JVM). The JVM is essentially an interpreter for the bytecode. It goes through the
bytecode and runs it. There are different versions of the JVM that are compatible with cach
OS and can run the same code. There is virtually no difference for the end-user, but this
makes it a lot easier for programmers doing software development.

2.1 Java and Open Source:-

In 2006 Sun started to make Java available under the GNU General Public License (GPL).
Oracle continues this project called OpenJDK.

2.2 Java Virtual machine :-

 The Java vimal machine (JVM) is a software implementation of a computer that


executes programs like a real machine.

 The Java virtual machine is written specifically for a specific operating system, eg for

 Linux a special implementation is required as well as for Windows. > Java programs
are compiled by the Java compiler into bytecode. The Java virtual machine interprets
this bytecode and executes the Java program

2.3 Java Runtime Environment vs. Java Development Kit :-

 A Java distribution comes typically in two favors, the Java Runtime Environment
(JRE) and the Java Development Kit (JDK).

 The Java runtime environment (JRE) consists of the JVM and the Java class libraries
and

 contains the necessary functionality to start Java programs. The JDK contains in
addition the development tools necessary to create Java programs.

 The JDK consists therefore of a Java compiler, the Java virtual machine, and the Java
class libraries.

2
Chapter-3
INSTALLATION OF JAVA

3.1 Check installation

 Java might already be installed on your machine. You can test this by opening a
console (if you are using Windows: Win R, enter cmd and press Enter) and by typing
in the
 following command: java -version

 If Java is correctly installed, you should see some information about your Java
installation. If the command line returns the information that the program could not be
found, you have to install Java.

3.2 Installing the Java Development Kit :-


Before installing the Java Development Kit (JDK), you should probably know what it is It is
distributed by Orack. It contains the core libraries and compiler required to develop Java. The
JDK should not be confused with the JRE (Java Runtime Environment). The JRE is a JVM for
running, as opposed to compiling, Java programs.

3.3 Downloading and Installing :-

 To download the JDK, to


http://www.orack.com/technetwork/java/javase/downloads/index.html Click on "JDK
with NetBeans Bundle". Follow the instructions for downloading the JDK installation
file.

Windows: If you are running Windows, simply run the executable file and follow the
installation instructions.

Unix, Solaris, or Linux: For Linux and Unix, download the "Jdk1 6.0" for Linux systems.
Save the downloaded file in any drive. Once you have saved the file, extract it to a place that
you can remember, by using Terminal or by double clicking on the file. When you have
finished extracting the file, copy the JDK 1.6.0 folder and paste it in the usr/local To paste to
the usr/local directory, you have to be in root) so that every user can use the java files. You
can delete the downloaded zip file so that it doesn't take up space your drive.

Macintosh: The latest available JDK is automatically installed by the operating system.
Because Java for Macintosh is developed and maintained by Apple, in coordination with Sun,
the current version on the Macintosh may not be the current version that is available

3.4 Note on Editions :-


> The JDK comes in three editions.

 Java Standard Edition (JSE) - This version is the basic platform for Java. The course
will focus on this edition.

 Java Micro Edition (JME) - This edition is primarily for developing programs to run
on consumer applicances, such as PDAs and cell phones.

3
Chapter-4
CONFIGURING VARIABLE

Before writing code, it is recommended that you set the Path variable on your system so
you can compile your code more easily.

 For Windows Users

 From the Control Panel, double click "System" (System and Maintenance in Vista)

 For Windows 7 or Vista, click on "System" "Advanced System Settings" on the left,
and then on "Environment Variables."

 For XP and 2000, click on the "Advanced" tab and click on "Environment Variables"
For NT, click on the "Environment" tab.

 Select the Path variable and click "Edit"

 Add the path to the bin directory of where Java is installed on your hard drive. It
should probably be: C Program Files\Java jdk 1.6.0 20 bin unless you changed it
during installation.

 Click OK

 For Linux and UNIX

 One way to set your path in Linux/Unix is to add a path export to your bash profile. In
order to do this, first open your bash profile in a text editor. For example,

 pico-/.bash profile

 Then add this line:

 export PATH-SPATH:/usr/local/jdk/bin

 Note that the path to the java directory "/usr/local/jdk/bin may be different on your
machine.

 Restart your shell

 For Macintosh

 Apple sets everything up for you. Sa back and relax.

 The only drawback is that because Apple handles development and maintenance of
Java on the Mac, there is usually a delay from the time that a new version is released
by Sun and the time that the new version is released on the Mac. Also, getting the
latest version sometimes requires an operating system upgrade.

 Oh well, you can't have everything.

4
4.1 Validate installation

 Switch again to the command line and run the following command.

 java -version

 The output should be similar to the following output.

 java version "1.7.0_25"

 OpenJDK Runtime Environment (leedTea 2.3.10) (7u25-2.3.10-1ubuntu0.13.04.2)

 OpenJDK 64-Ba Server VM (build 23.7-b01, mixed mode)

4.2 Development Process with Java

 Java source files are written as plain text documents. The programmer typically writes
Java source code in an Integrated Development Environment (IDE) for programming.
An IDE supports the programmer in the task of writing code, eg, it provides auto-
formating of the source code, highlighting of the important keywords, etc.

 At some point the programmer (or the IDE) calls the Java compiler (javac). The Java
compiler creates the bytecode instructions. These instructions are stored in .class files
and can be executed by the Java Virtual Machine.

4.3 Garbage collector

 The JVM automatically re-collects the memory which is not referred to by other
objects. The java garbage collector checks all object references and find the objects
which can be automatically released.

 While the garbage collector releases the programmer from the need to explicitly
manage memory the programmer still need to ensure that he does not keep unneeded
object references otherwise the garbage collector cannot release the associated
memory. Keeping unneeded object references are typically called memory leaks.

4.4 Classpath

 The classpath defines where the Java compiler and Java runtime book for .class files to
load. This instructions can be used in the Java program

 For example if you want to use an external Java library you have to add this library to
your classpath to use it in your program

5
Chapter-5
WRITE, COMPILE AND RUN A JAVA PROGRAM

5.1 Write source code:-

 The following Java program is developed under Linux using a text editor and the
command line. The process on other operating system should be similar and but is not
covered in this description.

 Select or create a new directory which will be used for your Java development. In this
description the path \home\vogella\javantarter is used. On Microsoft Windows your
might want to use c:\temp\javastarter. This path is called javadir in the following
description. Open a text editor which supports plain text, eg gedir under Linux or
Notepad under Windows and write the following source code.

Fig.5.1

the source code in your javadir directory with the Helloworld.java filename. The name
of a Java source file must always equals the class name (within the source code) and end
with the java extension. In this example the filename must be HelloWorld.java
because the class is called Helloworld.

5.2 Compile and run your Java program:-

 Open a shell for command line access:-

Switch to the Javadir directory with the command cd javadir, for example in the above
example via the ed \home\vogella\javastarter command. Use the is command (air under
Microsoft Windows) to verify that the source file is in the directory. Compile your Java
source file into a class file with the following command.

Javac Hello World.java

6
Afterwards list again the content of the directory with the is or dir command. The directory
contains now a file "HelloWorld.class". If you see this file you have successfully compiled
your first Java source code into bytecode.

You can now start your compiled Java program. Ensure that you are still in the jardi directory
and enter the following command to start your Java program

Java Hello World

The system should write "Hello World" on the command line.

Fig.5.2

5.3 Using the classpath

 You can use the chsspath to run the program from another place in your directory.

 Switch to the command line, e.g. under Windows Start Run emd. Switch to any
directory you want. Type:

Java Hello World

 If you are not in the directory in which the compiled class is stored then the system
should result an error message Exception in thread "main"
java.lang.NoClassDefFoundError: test/TestClass.

 To use the class type the following command. Replace "mydirectory" with the
directory which contains the test directory. You should again see the "Hello World"
output.

7
Chapter-6
PACKAGE

Java groups classes into functional packages.

Packages are typically used to group classes into logical units. For example all graphical
views of an application might be placed in the same package called com.vogella.web
application views.

It is common practice to use the reverse domain name of the company as top level package.
For example the company might own the domain, vogella.com and in this example the Java
packages of this company starts with com.vogella.

Other main reason for the usage of packages is to avoid name collisions of classes. A name
collision occurs if two programmers give the same fully qualified name to a class. The fully
qualified name of a class in Java consists out of the package name followed by a dot (.) and
the class name.

Without packages, a programmer may create a Java class called Test. Another programmer
may create a class with the same name. With the usage of packages you can tell the system
which class to call. For example if the first programmer puts the Teat class into package report
and the second programmer puts his class into package reader you can distinguish between
these classes by using the fully qualified name, eg reader. Test or report. Test.

6.1 Advantage of Java Package

1) Java package is used to categorize the classes and interfaces so that they can be easily
maintained.

2) Java package provides access protection.

3) Java package removes naming collision.

Fig.6.1

8
Chapter-7
CLASS AND OBJECT

7.1 Class in Java

A Class in Java is a set of object which shares common charaterstics / behaviour and common
properties and attritutes. It is a user- defined blue print or prototype from which objects are
created.
For example:-Student is a class while a particular student named ravi is an object.

7.2 Properties Of Class

 Class is not a real- world entity. It is just a templete or blue print or prototype from
object are created.

 Class does not occupy memory.

 Class is a group of variable of different data types and a group of method.

7.3 Class Declaration in Java

access_modifier class <class_name>


{
data member;
method;
constructor;
nested class;
interface;
}

7.4 Example of Class in Java

// Java Program for class example

class Student {
// data member (also instance variable)
int id;
// data member (also instance variable)
String name;

public static void main(String args[])


{
// creating an object of
// Student
Student s1 = new Student();
System.out.println(s1.id);
System.out.println(s1.name);
}
}

9
7.5 Object in Java
An object in java is a basic unit of object oriented programming and represents real life
entites. Objects are the instances of a class that are created to use the attributes and method of
a class. A typical java program create many objects, which as you known, interact by
invoking methods. An object consists of :

1) State: It is represented by attribute of an object. It also reflects the properties of an


objects.

2) Behavior: It is represented by the methods of an object. It also refects the response of


an object with other objects.

3) Identity: It gives a unique name to an object and enables one object to interact with
other objects.

7.6 Declaring Object

When an object of a class is created, the class is said to be instanaied. All the instances share
the attributed and the behavior of the class. But the values of those attributes, i.e. the state are
unique for each object. A single class may have any number of instances.

Example:

Fig.7.6

As we declare variable like. This is notify the complier that we will use the name to refer to
data whose type is type. With a primitive variable, this declaration also reserves the proper
amount of memory for the variable. So for refrence variable, the type must be strictly a
concrete class name. In general, we can’t create object of an objects of an abstract class or an
interface.

7.7 Initializing A Java Object

The new operator instanties a class by allocating memory for a new object and returning a
reference to that memory. The new operator also invoke the class contructor.

10
Chapter-8
INHERITANCE

Java, Inheritance is an important pillar of OOP( Object Oriented Programming). It is the


mechanism in java by which one class is allowed to inherit the features(fields and methods) of
another class. In java, Inheritance means creating new classes based on existing ones. A class
that inherit from another class can reuse the methods and field of that class. In addition, you
add new fields and methods to your current class as well.

8.1 Why Do We Need Java Inheritance

 Code Reusability : The code written in the super class is common to all
subclasses.Child classes can directly use the parent class mode.

 Method Overriding : Method Overriding is achievable only through Inheritance. It is


one of the ways by which java achivies Run Time Polymorphisms.

 Abstraction : The concept of abstract where we do not have to provide all details is
achieved through inheritance. Abstraction only showns the fuctionally to the user.

8.2 Important Terminology used in Java Inheritance


1. Class : Class is a set of object which shares common characterstics/ behaviour and
commomly properties/ attributes. Class is a not a real-world entitiy.

2. Super class/Parent Class: The class whose features are inherited as known as a super
class(or a base class or a parent class).

3. Sub Class / Child Class: The Class that inherits the other class is known as a subclass
(or a derived class,extended class, or child class). The Subclass can add its own fields
and methods in addition to the super class field and methods.

8.3 How to Use Inheritance in Java

The extent keyword is used foe inheritance in java. Using the extents keyword indicates you
are derived from an existing class. In other word,”extends” refers to increased functionally.

Syntax :

class derived -class extends base class


{
//methods and field
}

8.4 Inheritance in Java Example

Example: In the below example of inheritance, class bicycle is a base class, class
mountainbike is a derived class that extends the bicycle class and class test is a driver class to
the run the program.

11
Chapter-9
VARIABLE AND METHOD

In Java, Variable are the data containers that saves the dates values during java programing
execution. Every variable in java is assigned a data type that designates the type and quantity
of value it can hold. A variable is a memory location name for the data.

9.1 Variables in Java


Java variable is a name given to a memory location. It is the basic unit of storage in a
program.

 The value stored in a variable can be changed during program execution.

 Variable in Java are only a name given to a memory location. All the operation done
on the variable affect that memory location.

 In Java, all variable must be declared before use.

9.2 How to Declare Variable in Java


We can declare variables in java as pictually depicted below as a visual aid.

From the image, it can be easily perceived that while declaring a variable, we need to take
care of two things that are:

1. Datatype: Type of data that can be stored in this variable.


2. Variable name: Name given to the variable.

In this way, a name can only be given to a memory location. It can be assigned value in two ways:

 Varaible initialization

 Assigning value by taking point

9.3 How to Initialize Variable in Java?


It can be perceived with the help pf 3 components that are follows:

 Datatype: Type of data that can be stored in this variable.

 Variable_name: Name given to the variable.

 Value: It is the initial value stored in the variable.

9.4 Types of Variable in Java


Now let us discuss different types of variables which are listed as follows:
1. Local Variables
2. Instance Variable
3. Static Variable

12
9.5 Method
A method is a block of code with parameters and a return value. It can be called on the object.

package com.vogella.javaintro.base:

public class MyMethodExample { void tester (String a) ( System.out.println("Hello World");


}
}

Method can be declared with var-args. In this case the method declares a parameter which
accepts from zero to many arguments (syntax: type.. name:) A method can only have one var-
args parameter and this must be the last parameter in the method.

Overwrite of a superclass method: A method must be of the exact same return parameter and
the same arguments. Also the return parameter must be the same. Overload methods: An
overloaded method is a method with the same name, but different arguments. The return type
can not be used to overload a method.

9.6 Main Method

A public static method with the following signature can be used to start a Java application.
Such a method is typically called main method.

public static void main(String[] args) {


}

9.7 Constructor

A class contains constructors that are invoked to create objects based on the class definition.
Constructor declarations look like method declarations except that they use the name of the
class and have no return type. A class can have several constructors with different parameters.
Each class must define at least one constructor.

In the following example the constructor of the class expects a parameter.

package com.vogella.javaintro.base:

public class MyConstructorExample2 {

String s

public MyConstructorExample2 (String s) {

this.s =3;
}
}

If no explicit constructor is defined the compiler adds implicitly a constructor. If the class is
sub-classed then the constructor of the super class is always implicitly called in this case.

13
In the following example the definition of the constructor without parameters (also known as
the empty constructor) is unnecessary. If not specified the compiler would create one.package
com.vogella.javaintro.base;

public class MyConstructorExample (

// Unnecessary, would be created by the compiler if left out

public MyConstructorExample( ) {
}
}

package com.vogella.javaintro.base;

public class MyConstructorExample (

// Unnecessary, would be created by the compiler if left out

public MyConstructorExample() (

The naming conversion for creating a constructor is the following: classname (Parameter pl,
..) ().

Every object is created based on a constructor. This constructor method is the first statement
called before anything else can be done with the object.

14
Chapter-10
MODIFIER AND IMPORT STATEMENT

10.1 Access modifiers


There are three access modifiers keywords available in Java. public, protected and private.
There are four access levels: public, protected, default and private. They define how the
corresponding element is visible to other components. If something is declared public, e.g
classes or methods can be freely created or called by other Java objects. If something is
declared private, e.g a method, it can only be accessed within the class in which it is declared.
protected and default are similar. A protected class can be accessed from the package and sub-
classes outside the package while a default class can get only accessed via the same package.
The following table describes the visibility:

Table 10.1.1 Access Level

Modifier Class Package Subclass World


Public Y Y Y Y
Proctected Y Y Y Y

Modifier Class Package Subclass World


No Modifier Y Y N N
Private Y N N N

10.2 Other Modifers

 Final Methods cannot be overwritten in a subclass.


 Abstract method: No method body
 Synchronized Method : thred safe, can be final and have any access control
 Native Methods: PLstform dependent code, apply only to methods
 Strictfp : class on method

10.3 Import statements


10.3.1 Usage of import statements

In java you have to access a class always via is full-qualified name, e.g the package name and
the class name. You can add import statements for classes or package name and the class
name. You can add import staements for classes or package into your class file, which allow
you to use the related classes in your code without the package qualifier.

10.3.2 Static Imports

Static import is a features that allow members (field and methods) which are defined in a class
with the public static access modifier to be used in java code without specifying the class in
which the member is defined. The features provides a typesafe mechanism to include consists
into code without having to reference the class that orginally defined the field.

15
Chapter-11
INTERFACE

Interfaces are contracts for what a class can do but they say nothing about the way in which
the class must do it. An interface is a type similar to a class. Like a class an interface defines
methods. An interface can have only abstract methods, no concrete methods are allowed.
Methods defined in interfaces are by default public and abstract - explicit declaration of these
modifiers is optional. Interfaces can have constants which are always implicitly public, static
and final A class can implement an interface. In this case it must provide concrete
implementations of the interface methods. If you override a method defined by an interface
you can also use the @override annotation.
The following code shows an example implementation of an interface and its usage within a
class.

package com.vogella.javaintro.base;

public interface MyDefinition (


// constant definition
String URL-"http://www.vogella.com":

// define several method stubs


void test();
void write(String a);
}

package com.vogella.javaintro.base:

public class MyClassImplementation implements MyDefinition {

#Override

public void test() {

// TODO Auto-generated method stub


}

@Override
public void write(String s) {
// TODO Auto-generated method stub
}
}

11.1 Class methods and class variables


Class methods and class variables are associated with the class and not an instance of the
class, ie. objects. To refer to these element you can use the classname and a dot (".") followed
by the class method or class variable name. Class methods and class variables are declared
with the static keyword. Class methods are also called static methods and class variables are
also called static variables or static fields.
An example for the usage of a static field is printin of the following statement:
System.out.println("Hello World"). out is a static field, an object of type.

16
PrintStream, and you call the printin () method on this object. If you define a static variable
the Java runtime environment associates one class variable for a class no matter how many
instances (objects) exists. The static variable can therefore be seen as a global variable. The
following code demonstrates the usage of static fields.

package com.vogella.javaintro.base;

public class MyStaticExample (

static String PLACEHOLDER - "TEST";

static void test() { System.out.println("Hello");

package com.vogella.javaintro.base;

public class Tester (

public static void main(String[] args) {

System.out.println(MyStaticExample. PLACEHOLDER); MyStaticExample.test();

If a variable should be defined as constant, you declare it with the static and the final
keyword. The static method runs without any instance of the class, it cannot directly access
non-static variables or methods.

11.2 Abstract class and methods


A class and method can be declared as abstract. An abstract chass can not be directly
instantiated. If a class has at least one method which only contain the declaration of the
method but not the implementation then this class is abstract and can not be instantiated. Sub-
classes need then to define the methods except if they are also declared as abstract. If a class
contains an abstract method it also needs to get defined with the keyword abstract. The
following example shows an abstract class.

package com.vogella.javaintro.base;

public abstract class MyAbstractClass i abstract double returnDouble();

17
Chapter-12
WORKING WITH CLASS

12.1 Difference Between What to do and How to do it

 Table 12.1 .1

What to do How to do it
Create a new class called MY NEW CLASS. package test;

public class MYNEWCLASS

}
Create a new atrritute (instance variable) package test;
Called varl of type string in the MY NEW
CLASS class. public class MYNEWCLASS {
private string varl;
}
Create a Constructor for your package test;
MYNEWCLASS class which has a string
parameter and assigns the value of it to the public class MYNEWCLASS {
varl instance variable. private string varl;

public MYNEWCLASS (String paral)


{
varl= paral;
//or this.varl = paral;
}
}
Create a new method called dosomething in package test;
your class which does not return a value and public class MYNEWCLASS{
has no parameter. private string varl:
public MYNEWCLASS(String){
varl = paral;
//or this.varl = paral;}
Public void dosomething( )

Create a new method called dosomething in package test;


your class which does not return a value and public class MYNEWCLASS{
has two parameter, int and a person. private string varl:
public MYNEWCLASS(String){
varl = paral;
//or this.varl = paral;}
Public void dosomething( )

18
Create a new method called dosomething in your package test;
class which returns an int value and has three
parameters, two strings and a person. public class MYNEWCLASS{
private string varl;

public MYNEWCLASS(String paral) {


varl = paral;
// or this.varl = paral;}

public void dosomething( )


{

public void
dosomething2(int a, person person) {
}

Public int
Dosomething3 (String a, String b,
person,person) {
return 5 ;
}
}

Create a class called MYOTHERCLASS with package test;


two instance variables. One will store a string
the other will store a dog. Create getter and publicclass MYOTHERCLASS{
setter for these variable. String myvalue;
Return myvalue;
}

public void
set MYVALUE(String my value)

12.2 Integrated Development Environment


The previous chapter explained how to create and compile a Java program on the command
line. A Java Integrated Development Environment (IDE) provides lots of ease of use
functionality for creating java programs. There are other very powerful IDE'S available, for
example the Eclipse IDE.. For an introduction on how to use the Eclipse IDE please see
Eclipse IDE Tutorial. The remaining description uses the phrase: Create a Java project
called...". This refers to creating a Java project in Eclipse. If you are using a different IDE
please follow the required steps in this IDE. Exercises - Creating Java objects and methods
Create a Person class and instantiate it Create a new Java project called com
vogella.javastarter.exercises and a package with the same name. Create a class called Person.
Add three instance variables to it, one for storing the first name of the person, on for storing
the last name and one for storing the age of the Person. Use the constructor of the Person
object to set the values to some default value. Write a public method called writeName()
which uses the System.out.println( method to print the first name of the person to the console.
Create a new class called Main with a public static void main(String[] args). In this method
create an instance of the Person class.

19
Use constructor

Add a constructor to your Person class which takes the first name, last name and the age as
parameter. Assign the values to your instance variables. Create in your main method two
objects of type Person and call the writeName method on it.

12.3 Define getter and setter methods

Define methods which allow you to read the values of the instance variables and to set them.
These methods are called setter and getter. Getters should start with get followed by the
variable name whereby the first letter of the variable is capitized. Setter should start with set
followed by the variable name whereby the first letter of the variable is capitized. For example
the variable called firstName would have the getFirstName() getter method and the
setFirstName(String s) setter method. Change your main method so that you create one person
object and use the setter method to change the last name.

12.4 Create an Address object


Create a new object called Address. The Address should allow you to store the address of a
person. Add a new instance variable of this type in the Person object. Also create a getter and
setter for the Address object in the Person object.

12.5 Solution Creating Java objects and methods

Create a Person class and instantiate it

The following is a potential solution for Section 11.1, "Create a Person class and instantiate

package exercises.exercise04;

class Person {

String firstname ="Jim^ prime prime

String hstname =`Knopf ;

int age = 12

voi d writeName() {

// Writes the firstname

System.out.println(firstname);

// Alternatively you can combine strings with + Systemout


.println(firstname+"+"+hstmame+"+agc)

package exercises.exercise04;
public class Main (

public static void main(String[] args) {

Person person = new Person();

20
person.writeName();

Use constructor

package com.vogella.ja vastarter.exercises 1;

class Person {

String firstName;

String lastName;

int age:

public Person(String a, String b, int value) {

firstName =a:

hstName = b

age value;

void writeName() {

Writes the firstname

21
Chapter-13
HISTORY OF JAVA

It is quite interesting to know the development of Java technology, which is widely accepted
in the area of networked distributed computing Java evolved from a project developing a
language for programming consumer electronic devices at Sun Microsystems, USA.

Sun's Stealth Project in 1990 was aimed to do research in the area of application of computers
in the consumer electronics market. Bill Joy, James Gosling, Mike Sheridan, Patrick
Naughton (formerly the project leader of Sun's Open Windows user environment), and several
other individuals discussed the ideas for the Stealth Project in January 1991.The vision of this
project was to develop smart consumer electronic devices that could all be centrally controlled
and programmed from a handheld-remote-control-like device. The Stealth group began to
work to achieve this goal. It was realized that a platform-independent development-
environment was needed.

Green Project was initiated by Patrick Naughton, Mike Sheridan, and James Gosling of Sun
Microsystems in 1991 (Members of the Stealth Project, which later became known as the
Green Project) The tasks of the project were divided amongst the members of Green Project.
Mike Sheridan concentrated on business development. Patrick Naughton worked on the
graphics system, and James Gosling was to identify the appropriate programming language
for the Green Project. Even though creating a new language was not the aim of Green Project,
a new linguage was created as a programming tool in this project since C++ was found
unsuitable for the project.

An intelligent remote control called 7 (Star Seven) was delivered as the first product of Green
Project in 1992. It is a PDA- ke device comprising of a new language oak, an operating
system called GreenOS, user interface, and hardware. This device was quite impressive to Sun
Executives. But no customer was interested in this project. The market was not conducive to
this

type of device in the consumer electronics industry.

The new langage Oak was created by James Gosling a Green Team member, specifically for
7. Gosling named the new language Oak because that name was struck while looking at an
oak three outside of his office window. The name Oak was later renamed to Java in order to
avoid legal issues since Ouk was the name of an existing language.

In November 1992, the Green Project was incorporated under the name FirstPerson. In 1993.
Time-Wamer was demanding for proposals for set-top box operating systems and video- on-
demand technology with an objective of sending the data to consumer all over the country for
display on the television sets. At the same time (1993, NCSA released the first graphical web
browser Mosaic 1.0, an easy-to-use front end to the World Wide Web.

When First Person was bidding on the Time-Wamer TV trial based on video-on-demand
technology. Time-Wamer chose Silicon Graphics, Inc. (SGI) over Sun. Hence, half of the
members of First Person left for SGI and the remaining members continued to work at Sun

Mosaic web browser revolutionized people's perceptions. The remaining member of First
Person returned to work on Java (Oak was renamed Java) to develop Java-based web browser.
First Person was dissolved gradually. Naughton and Jonathan Payne developed WebRunner
(named after the movie Blade Rumer). Later Wev Runner was officially announced as the

22
Hot Java browser in 1994. This was the turning point for Java. At that time the World Wide
Web changed the face of Internet and it was winning the race on Internet.

Arthur Ban Hoff implemented the Java compiler in Java itself whereas Gosling implemented
it in C. The Java compiler, written in Java made the people to accept Java as a full- featured
language.

Sun Microsystems officially announced Java environment at Sun World'95 on May 23, 1995.
Java entered into the mainstream of the Internet after a struggle for about four years. Netscape
Communications incorporated Java into its web browser Netscape Navigator. Within a
decade, Java was destined to be the most overreaching technology in the Internet, Java was
not

restricted to the Internet alone. The initial goal of Sun was ako achieved by using Java

technology in interactive set-top boxes, hand-held devices and other consumer electronics

products.

Sun released the first version 1.0 of Java in 1996. Java is an object-oriented programming
language which evolved from C++. It is also a high-level programming language. The
different forms of Java versions are discussed in the next section.

23
Chapter-14
FEATURES OF JAVA

According to Sun, Java is defined as a simple, object-oriented, distributed, interpreted, robust,


secure, architecture neutral portable, high performance, multithreaded, and dynamic
programming language and platform

Java is simple because the syntax of well-known languages such as C and C++ are used with
modifications meant for simplification and improvement. It is easy to read and write Java
code if the reader is familiar with C/C++

Almost everything in Java is centered on creating objects, manipulating the objects and
making objects work together. Only the primitive operations and data types are at the sub-
object level. Hence Java is an object-oriented programming language.

An application can be distributed in many systems which are connected together. Since
networking capability is incorporated in Java, the data/file can be sent across many systems to
run the application.

Java is robust because it is more reliable. It ensures the reliability by providing early checking
for possible errors. It eliminates error-prone constructs such as pointer. It eliminates error-
prone constructs such as pointer. It also supports runtime error handling.

Java programs are compiled to a byte code format that can be read and run by interpreters on
many platforms including Windows, Line, etc. Hence, it is architecture neutral. Because of
this feature it is portable to new hardware and operating systems.

Although the speed of execution of Java programs is slower compared to C/C++ programs,
Java is meant for distributed applications. Whenever the file/data is transmitted from one
system to another, the performance is not affected. Hence, it is having high performance.

Java supports mutithreaded programming to perform several tasks simultaneously. Any code
can be loaded without recompilation at runtime. Hence it is dynamic

24
CONCLUSION
This course has been an excellent and rewarding experience. I can conclude that there have
been a lot I've learnt from my work through online teaching.

Needless to say, the technical aspects of the work I've done are not flaw less and could be
improved provided enough time.

As someone who was just interested in WordPress, whatsoever I believe my time spent in
research and discovering new tools was well worth it and contributed to finding an acceptable
solution to an important aspect of web design and development.

Two main things that I've learned are: the importance of time-management skills and self-
motivation.

25
REFERENCE

1. URL:- https://www.greeksforgreeks.org

2. URl:- https://www.javapoint.com

26

You might also like