O'Reilly logo

Programming with Java by Sunil Patekar, Mahesh Bhave

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 3

JAVA LANGUAGE BASICS

It is said that the best way to learn swimming is to jump into the water right away. Similarly, the best way to learn a programming language is to start coding straight away. Let us start our study of Java programming in an informal way. Let us write a simple Java program and run it.

3.1 Introduction

In our first Java program, we will find the area of a circle with radius 5.

Problem: Write a program to find area of a circle with radius 5.

Solution: See Program 3.1.

 

PROGRAM 3.1 Area of a Circle

 //    first.java

 class first

  {

 public static void main( String args[] )

  {

   int r ;

   r = 5 ;

   System.out.println(3.14 * r * r);

  }

 }

If you run the program, you will get the following output.

 

Output

 78.5 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required