Core Java Tutorial

Java Tutorial or Core Java Tutorial or Java Programming Tutorial is a widely used robust technology. Let’s start learning Java from basic questions like what is Java tutorial, Core Java, where it is used, what type of applications are created in Java, why use java and Java platforms etc. Our Java tutorial helps you to learn Java with easy and simple examples.

Flow control with if and else

The if and else statements allow a block of code or a single statement to be ither executed or bypassed depending upon the result of a comparison operation. They are an essential part of Java “flow control” by which execution may proceed along alternate logic paths within a program.  

for, while, and do-while statements

The ability to “loop” by executing one or more statements repetitively is an important part of programming. Loops reduce the number of statements a programmer must code and result in a smaller, more memory efficient program. In Java, looping is performed using the for, while, and do-while statements.

The for statement | Decision making, Branching and Looping

The for statement 1) It is useful when the number of passes (iterations) can be predetermined The general syntax for (initialization; condition; update) { statements; } where: initialization – represents the declaration of one or more local variables of the same data type. When loop processing is complete, all such variables are destroyed. condition – …

The for statement | Decision making, Branching and Looping Read More »

The do-while statement

1) It defines a block of code to be executed as long as a particular condition is met. The condition is tested at the end of each iteration. It always guaranteed at least one pass through a do-while loop. syntax do { statements; } while (condition); where condition represents a binary expression that, if true, …

The do-while statement Read More »

The Benefit of Classes

Objects provide the benefit of modularity and information hiding. Classes provide the benefit of reusability. Software programmers use the same class, and thus the same code, over and over again to create many objects.

Defining Classes

To define a class, we use the class keyword and the name of the class: class MyClassName { … } By default, classes inherit from the Object class. If this class is a subclass of another specific class (that is, inherits from another class), use extends to indicate the superclass of this class: class myClassName …

Defining Classes Read More »

Class using constructor

Class using constructor Here’s a of SimpleRectangle, called Rectangle, that contains four constructors, a method to “move” the rectangle, a method to compute the area of the rectangle, and a finalize method to provide for clean up: public class Rectangle { public int width = 0; public int height = 0; public Point origin; // …

Class using constructor Read More »

Object

An object is a distinct instance of its class (an actual occurrence). It has its own set of variables (known as “instance variables”) and methods (known as “instance methods”). When called, an object’s instance methods automatically act upon its instance variables Java program creates many objects from a variety of classes. These objects interact with …

Object Read More »

Declaring an Object

Like other variable declarations, object declarations can also appear alone, like this: Rectangle rect; Declarations notify the compiler that you will use name to refer to a variable whose type is type. Declarations do not create new objects. Rectangle rect does not create a new Rectangle object, just a variable named rect to hold a …

Declaring an Object Read More »

Initializing an Object

The classes can provide one or more constructors to initialize a new object of that type. We can recognize a class’s constructors because they have the same name as the class and have no return type. Here are the declarations for Rectangle’s constructors: public Rectangle(Point p) public Rectangle(int w, int h) public Rectangle(Point p, int …

Initializing an Object Read More »