• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Java » Java Control Structures

How to calculate the GCD (Greatest Common Divisor) in Java

By Dinesh Thakur

Currently the definition of Greatest Common Divisor (GDC) can be formalized as well: [Read more…] about How to calculate the GCD (Greatest Common Divisor) in Java

Finalizer methods in Java

By Dinesh Thakur

Finalizer methods are almost the opposite of constructor methods. A constructor method is used to initialize an object, while finalizer methods are called just before the object is garbage-collected and its memory reclaimed. The syntax of the finalizer method is simply finalize(). The Object class defines a default finalizer method. To create a finalizer method, override the finalize() method using the following signature: [Read more…] about Finalizer methods in Java

Java Program Vowel or Not Example

By Dinesh Thakur

In the switch statement, since same statements has to be executed corresponding to different cases (‘a’, ‘e’, ‘i’, ‘o’, ‘u’, ‘A’, ‘E’, ‘I’, ‘O’, ‘U’) so we write the statements with the last case. The break statement causes the switch statement to terminate when any of the vowels is entered. [Read more…] about Java Program Vowel or Not Example

Program To Show Importance of Continue Statement? Java Example

By Dinesh Thakur

In this example, the continue statement is placed in the body of inner for loop. While executing inner for loop, if the condition (m==n) evaluates to true then the continue statement is executed and the remaining statement for displaying values of m and n is skipped and control is transferred to the increment expression (n++) of inner for loop. This increments the value of n by 1 and test condition (n<=2) is evaluated again for this incremented value of n. This process continues. We have used continue statement in this program so that the same value of m and n should not be displayed. [Read more…] about Program To Show Importance of Continue Statement? Java Example

Java Calculate The Sum Of Only The Positive Numbers. Example

By Dinesh Thakur

This example computes the sum of positive numbers input by the user. When a negative number is input, the condition (num<0) become true and break statement is executed which leads to the termination of the while loop and the next statement following the loop is executed which displays the sum of positive numbers. The condition of the while loop always remains true as we have specified a non-zero value 1 which makes it run infinitely. The only way to exit this loop is to. use break statement. [Read more…] about Java Calculate The Sum Of Only The Positive Numbers. Example

Java Nested For Loop Examples

By Dinesh Thakur

Like the nesting of if and other looping statements, the for loop can also be nested. In other words, we can have a for loop in the body of other for loop. There is no restriction on the level of nesting of loops but one should take care while nesting at multiple levels otherwise unexpected results may arise. [Read more…] about Java Nested For Loop Examples

Solve Equation 3*x*x – 2*x +1 in Java Example

By Dinesh Thakur

In this example, we input the interval values a and b. Each time loop is executed the value of fx is calculated and displayed on the screen for the value of x which ranges from a to b. On each iteration, x is incremented by 0.05. This continues until x is less than equal to the value of b that user inputs. [Read more…] about Solve Equation 3*x*x – 2*x +1 in Java Example

Java Program to Find Average of N Numbers

By Dinesh Thakur

In this example, we input number of elements n (i.e.) whose average is to be calculated. When for loop begins executing, the loop control variable i is declared and initialized to 1. Then the test condition (i<=n) is checked. As it is true in this case because (1<=5) and the statements in the body of the loop are executed which inputs the first number (5 in our case) and add this value to variable sum. Then the increment expression i++ increases the value of variable i by 1 (i+ 1=2). After one complete iteration, the test condition in the for loop is checked again which is true again as (2<=5) and the body of the loop is executed again. This process continues until the loop control variable (i) is incremented to 6. Now when the test condition (6<=5) is evaluated again it becomes false and the execution of for loop terminates and control transfers to the next statement following the for loop that calculates the average of n (5) numbers which is then displayed. [Read more…] about Java Program to Find Average of N Numbers

Sum of First N Natural Numbers in Java Example

By Dinesh Thakur

In this example, the sum of first 10 natural numbers is displayed. First, input the value of n (10 in this case) i.e. number of natural numbers whose sum is to be calculated. Then, after initializing the variables i to 1 and sum to 0, we enter the do-while loop. The execution of the body of loop continues as long as condition (i<=n) evaluates to true. When variable 1’s is value becomes 11, the condition becomes false and this terminates the do-while loop and program execution continues with the next statement after the loop which displays the sum of first 10 natural numbers. [Read more…] about Sum of First N Natural Numbers in Java Example

Sum of Digits of a Number in Java Example

By Dinesh Thakur

In this program, we first input the number (Say num = 12345). Next the control reaches the while loop where it checks the condition (num>0) which is true as (12345>0) so the body of the loop is executed. [Read more…] about Sum of Digits of a Number in Java Example

Math.random() in Java Example

By Dinesh Thakur

The Random class provides a template for the creation of random number generators. The Math.random() method provides a static function for the generation of random double values. [Read more…] about Math.random() in Java Example

currentTimeMillis() Java Example

By Dinesh Thakur

The currentTimeMillis() method returns the current time in milliseconds since 00:00:00,January I, 1970.This method is used to know the time interval a process or job takes to perform. We record the time before and after the operation and the difference of two timings tells us the total time the operation took. [Read more…] about currentTimeMillis() Java Example

Date Format Example in Java

By Dinesh Thakur

We can change the format of the date in two steps: First, we create a formatter with the getDateInstance method. Then, we invoke the format method, which returns a String containing the formatted date. [Read more…] about Date Format Example in Java

Print System Date and Time in Java Example

By Dinesh Thakur

The Calendar class is an abstract class used to convert dates. We can use this class to convert a Date object to fields, such as YEAR, MONTH, HOUR, and so on. We can also use these fields to update a Date object. [Read more…] about Print System Date and Time in Java Example

Java Example to translate the word in piglatin

By Dinesh Thakur

In “PigLatin” a word such as KING is replaced by INGKAY and TROUBLE is replaced by OUBLETRAY and so on. The first vowel of the original word becomes the start of the translation, any proceeding letters being shifted towards the end and followed by AY words that begin with vowels are left on changed. [Read more…] about Java Example to translate the word in piglatin

Java – Number of Times a Word has Been Mentioned | Java Example

By Dinesh Thakur

Algorithm for Number of Times a Word has Been Mentioned : [Read more…] about Java – Number of Times a Word has Been Mentioned | Java Example

Remove Vowels from a Sentence | Java Example

By Dinesh Thakur

Algorithm for Remove Vowels from a Sentence: [Read more…] about Remove Vowels from a Sentence | Java Example

Reverse the Order of the Words in a Sentence in Java Example

By Dinesh Thakur

Stack-This class is a predefined class of java.uti1package. A stack represents a group of elements stored in LIFO (Last In Fast Out) order. This means that the element stored as a last element in the stack will be the first element to be removed from the stack. [Read more…] about Reverse the Order of the Words in a Sentence in Java Example

Comma Operator in Java Example

By Dinesh Thakur

There will be times when we will want to include more than one statement in the initialization and iteration sections of the For loop. For example, consider the loop in the following program: [Read more…] about Comma Operator in Java Example

Print Tables from 5 to 10 Except 6

By Dinesh Thakur

[Read more…] about Print Tables from 5 to 10 Except 6

Counting the Number of Non Blank Characters in a String | Java Example

By Dinesh Thakur

[Read more…] about Counting the Number of Non Blank Characters in a String | Java Example

Print Number from 1 to 10 Except 5

By Dinesh Thakur

[Read more…] about Print Number from 1 to 10 Except 5

Infinite For loop Example | Java Examples

By Dinesh Thakur

[Read more…] about Infinite For loop Example | Java Examples

Jump Statements in Java Example

By Dinesh Thakur

In Java, Jump statements are used to unconditionally transfer program control from one point to elsewhere in the program. Jump statements are primarily used to interrupt loop or switch-case instantly. Java supports three jump statements: break, continue, and return. [Read more…] about Jump Statements in Java Example

Print all the Prime Numbers up to 100

By Dinesh Thakur

we have seen how to test whether a given number is prime or not. The program segment given below uses a for loop to test each number in a given range and print it if it is prime. [Read more…] about Print all the Prime Numbers up to 100

Prime Number Program in Java Using BufferedReader Example.

By Dinesh Thakur

[Read more…] about Prime Number Program in Java Using BufferedReader Example.

Nested For Loop in Java Example

By Dinesh Thakur

Nested loop means one loop inside the other. When a loop is written inside the other loop, a condition is essential to maintain: the inner loop will not cross the boundary of the outer loop. That is, the inner loop will begin and end inside the outer loop. We can have any number of loops one inside the other. [Read more…] about Nested For Loop in Java Example

Enter 10 Number and Print the Number of Positive, Negative and Zeros Number

By Dinesh Thakur

In this example we use BufferedReader class for Reading text from a character-input stream. After Enter any 5 Number we check if number ==0 then is zero if number greater than 0 then it is positive other wise negative. [Read more…] about Enter 10 Number and Print the Number of Positive, Negative and Zeros Number

Enter a String from keyboard and check whether it Palindrome or Not

By Dinesh Thakur

Length():-This method is a predefined method of String class present in java. Lang package. It is used to determine the length of string and return type of this method is int type. [Read more…] about Enter a String from keyboard and check whether it Palindrome or Not

Sum of first n Sequence Numbers in Java Example

By Dinesh Thakur

[Read more…] about Sum of first n Sequence Numbers in Java Example

Next Page »

Primary Sidebar

Java Tutorials

Java Tutorials

  • Java - Home
  • Java - IDE
  • Java - Features
  • Java - History
  • Java - this Keyword
  • Java - Tokens
  • Java - Jump Statements
  • Java - Control Statements
  • Java - Literals
  • Java - Data Types
  • Java - Type Casting
  • Java - Constant
  • Java - Differences
  • Java - Keyword
  • Java - Static Keyword
  • Java - Variable Scope
  • Java - Identifiers
  • Java - Nested For Loop
  • Java - Vector
  • Java - Type Conversion Vs Casting
  • Java - Access Protection
  • Java - Implicit Type Conversion
  • Java - Type Casting
  • Java - Call by Value Vs Reference
  • Java - Collections
  • Java - Garbage Collection
  • Java - Scanner Class
  • Java - this Keyword
  • Java - Final Keyword
  • Java - Access Modifiers
  • Java - Design Patterns in Java

OOPS Concepts

  • Java - OOPS Concepts
  • Java - Characteristics of OOP
  • Java - OOPS Benefits
  • Java - Procedural Vs OOP's
  • Java - Polymorphism
  • Java - Encapsulation
  • Java - Multithreading
  • Java - Serialization

Java Operator & Types

  • Java - Operator
  • Java - Logical Operators
  • Java - Conditional Operator
  • Java - Assignment Operator
  • Java - Shift Operators
  • Java - Bitwise Complement Operator

Java Constructor & Types

  • Java - Constructor
  • Java - Copy Constructor
  • Java - String Constructors
  • Java - Parameterized Constructor

Java Array

  • Java - Array
  • Java - Accessing Array Elements
  • Java - ArrayList
  • Java - Passing Arrays to Methods
  • Java - Wrapper Class
  • Java - Singleton Class
  • Java - Access Specifiers
  • Java - Substring

Java Inheritance & Interfaces

  • Java - Inheritance
  • Java - Multilevel Inheritance
  • Java - Single Inheritance
  • Java - Abstract Class
  • Java - Abstraction
  • Java - Interfaces
  • Java - Extending Interfaces
  • Java - Method Overriding
  • Java - Method Overloading
  • Java - Super Keyword
  • Java - Multiple Inheritance

Exception Handling Tutorials

  • Java - Exception Handling
  • Java - Exception-Handling Advantages
  • Java - Final, Finally and Finalize

Data Structures

  • Java - Data Structures
  • Java - Bubble Sort

Advance Java

  • Java - Applet Life Cycle
  • Java - Applet Explaination
  • Java - Thread Model
  • Java - RMI Architecture
  • Java - Applet
  • Java - Swing Features
  • Java - Choice and list Control
  • Java - JFrame with Multiple JPanels
  • Java - Java Adapter Classes
  • Java - AWT Vs Swing
  • Java - Checkbox
  • Java - Byte Stream Classes
  • Java - Character Stream Classes
  • Java - Change Color of Applet
  • Java - Passing Parameters
  • Java - Html Applet Tag
  • Java - JComboBox
  • Java - CardLayout
  • Java - Keyboard Events
  • Java - Applet Run From CLI
  • Java - Applet Update Method
  • Java - Applet Display Methods
  • Java - Event Handling
  • Java - Scrollbar
  • Java - JFrame ContentPane Layout
  • Java - Class Rectangle
  • Java - Event Handling Model

Java programs

  • Java - Armstrong Number
  • Java - Program Structure
  • Java - Java Programs Types
  • Java - Font Class
  • Java - repaint()
  • Java - Thread Priority
  • Java - 1D Array
  • Java - 3x3 Matrix
  • Java - drawline()
  • Java - Prime Number Program
  • Java - Copy Data
  • Java - Calculate Area of Rectangle
  • Java - Strong Number Program
  • Java - Swap Elements of an Array
  • Java - Parameterized Constructor
  • Java - ActionListener
  • Java - Print Number
  • Java - Find Average Program
  • Java - Simple and Compound Interest
  • Java - Area of Rectangle
  • Java - Default Constructor Program
  • Java - Single Inheritance Program
  • Java - Array of Objects
  • Java - Passing 2D Array
  • Java - Compute the Bill
  • Java - BufferedReader Example
  • Java - Sum of First N Number
  • Java - Check Number
  • Java - Sum of Two 3x3 Matrices
  • Java - Calculate Circumference
  • Java - Perfect Number Program
  • Java - Factorial Program
  • Java - Reverse a String

Other Links

  • Java - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW