Showing posts with the label Java Stuff

What is Java Class and Object?

In this Java Class and Object tutorial, we will learn about the fundamentals of Java Programming. Java Class and Object is the base of Java. And we have tried to explain it in a simpler way. For your better understanding we have also provided example Java programs for concepts Java Classes and Object and Java Constructors. Classes and Objects are the fundamental building blocks of OOPS (Object Oriented Programming). A java object is a physical and logical entity where as java class is logical entity. Table of Content 1. What is a Java Class? Create your first Java program "Hello World" Explanation of Java keywords used in "Hello World" program 2. What is a Java Object? How to create Java Object? What is the use of Java Objects? 3. What is Java Constructor? Non-Parameterized Constructor (Default) Parameterized Constructor 1. What is a Java Class? Before creating an object in Java, you need to define a class. A class is a blueprint from which object is created. We can

What are Java Methods?

In this post, we'll learn everything about Java Methods. Table of Contents What is a Java Method ? How to Create a Method ? What is a Main method in Java ? Types of Java Methods Parameterized Methods Non - Parameterized Methods How to Call a Method ? Static Methods Non - Static Methods 1. What is a method in Java? A method in java is a group of instructions that are performed together to do a specific task. Methods are generally known as Functions in other languages like C, C++ etc.  Let's say you want to print numbers 1 to 10 in your program multiple times. So, if you have created a method with code which can print 1 to 10 numbers then you can just call that method multiple times in your program and you do not have to write the code to print 1 to 10. Java Methods have some features, let's take a look at them: Java Method can be public, private, protected or default. Java method can or cannot return a value. If you do not want your method to return anything, you have to dec

Java Loops and Control Statements

In programming if you want to repeat the execution of particular set of instructions or want to execute a function/set of lines repeatedly then we use loops. For example you want to print a number 10 times, what would you do? Probably a newbie would write print statement 10 times, but we can do the same thing to use a loop.  Let's understand the different types of loops with examples. For loop For-each loop While loop Do-While loop 1. For Loop When you know that you want to execute your code fixed no. of times say 10 times, then for loop comes into picture. It's the mostly used and the simplest loop in any programming. Here is the For loop structure: for (initializing variable; condition; increment/decrement) { // Code/Statement to be iterated } It has four different elements, let's understand them: Initialization Variable - It is the starting point of the for loop. This variable gets initialized when for loop gets started. Condition - It comes into play after initia

Java Conditional Statements

  Java , like all other programming languages, is equipped with specific statements that allow us to check a  condition  and execute certain parts of code depending on whether the  condition  is true or false. Such statements are called conditional, and are a form of composite statement. The Java  if statement  is used to test the condition. It checks boolean condition:  true  or  false . There are various types of if statement in Java. if statement if-else statement if-else-if ladder nested if statement Java supports the usual logical conditions from mathematics: Less than:  a < b Less than or equal to:  a <= b Greater than:  a > b Greater than or equal to:  a >= b Equal to  a == b Not Equal to:  a != b Java if Statement The Java if statement tests the condition. It executes the  if block  if condition is true. Syntax: 1.    if (condition){   2.    //code to be executed    3.    }   Example: 1.    //Java Program to demonstrate t