javawithus.com

Increment and Decrement Operators

Increment and decrement operators are widely used in controlling loops. These operators provide a more convent and compact ... -2 ) % 40 + 0 – ( -2 % 4 )( 0 + 0 ) – 2( 0 – 2 )-2 Next : Overloading constructors and methodsPrev : Final variables

Using Ellipsis to A!ccept Variable Number of Arguments

A method can receive a variable number of arguments with the use of ellipsis (three consecutive dots: …) In order to do so, ... ular method rather than the one taking variable number of arguments. Verify this fact yourself by modifying the code above.

Relation between a Super Class and Sub Class

A sub class has an ‘is a’ relationship with its superclass. This means that a sub class is a special kind of its super cl ... ble of type B. class A {     B obj; } Class B { } Next : Final classes and methods Prev : Inheritance introduction

Get and Set methods

We were able to create objects of the Student and initialise the variables of the object using the constructor. But after th ... (String n, int rn, int m1, int m2, int m3) { name = n;    setRollNumber(rn); setMarks1(m1); setMarks2(m2); setMarks3(m3); }

The constituents of a class

A class as already stated has three major components- variables, constructors and methods. A class may have all of these, ... : “+marks3);    } } Next : Creating objects and calling methods Prev : Introduction to object oriented programming

Call by Value and Call by Reference

Before we look into what the terms call by value and call by reference mean, let us look at two simple programs and examine ... cond objectNumber c=b;// c also refers to the second objectboolean result1= a==b; // falseboolean result2= b==c; // true

Mathematical Operations in Java

We have already seen about mathematical calculations in Java. We will now recollect them and then look at a few other aspect ... yte varaibles. we cast num1 to double and perform the division in the following way. double result = (double) num1 / num2;

More about Data Types

Here, we will discuss more about the data types we have seen in the previous article. Contents Storing integers Storing ... llowing shows an example. int a = 3; String str = “The value of a is ” + a; str now stores the String “The value of a is 3”

Class as a Reference Data Type

It has already been said that a class is also a data type- a non primitive reference data type. This was very much implici ... . And then t1 is compared to t2. Run the program and see down the result. Next : Constants or literals Prev : Casting

Converting a String to different Cases

In this article, we will see how to convert a given String to different cases using simple looping and methods of the String ... “Camel Case: ” + toCamelCase(inputString));        System.out.println(“Title Case: ” + toSentenceCase(inputString));    } }

The Hello World Program

Java is an object oriented programming language. We write classes and build objects out of them. A class is a blueprint or a ... ever, here again “Hello World!” should be written on a single line. Strings in Java should begin and end on the same line.

Variables and Data Types

Programs are often required to store information. For example, to write a program that adds two numbers, we need to store ... “+ firstNumber + ” and “+ secondNumber + ” is “+ result ); } } Next : More about data typesPrev : Hello World Program

Final Classes and Methods

Inheritance is surely one of the highly useful features in Java. But at times, it may be desired that a class should not be ... as final. The example cited above is just illustrative. The actual scenario in real world programming is much more complex.

Overloading Constructors and Methods

When more than a single constructor is defined in a class, it is known as constructor overloading. Similarly, when more th ... and would generate a compilation error. Next : Static methods and variables Prev : Increment and decrement operators

Formulating Algorithms

Now that we have learnt about two of the control structures, we shall see how we can formulate algorithms using theses struc ... tialised num to 1. But for an operation whose identity value isn’t known, version 2 is the only approach that can be taken.

Displaying text using printf() method

In addition to the print() and println() methods, the printf () method is also quite frequently used for displaying text th ... 89 Flags call also be provided in the format String to add further formatting. In addition, we can format dates and times.

The protected Access Specifier

As we have lardy said, there also exists the protected access specifier in addition to the public and private access specifi ... variables of class B are not accessible from class A. Similarly, protected variables of class A are not accessible from B.

Naming Conventions for Identifiers

If you have observed every program written by us closely, you would have noticed certain similarities in the way we have ... a variable, a class, an interface or some other entity. Next : Mathematical operations in Java Prev : Java Comments

Taking Input as Command Line Arguments

You must have now by realised what String[] args within the declaration of the main method means. It represents a String a ... from the command line: Next : Using ellipsis to accept variable number of argumentsPrev : Multi dimensional arrays

Default Constructor provided by Compiler

When we do not explicitly provide a constructor to our class, the compiler provides a default constructor which initialise ... ation error would be generated saying that x was not initialized } Next : Access Specfiers Prev : Get and Set Methods