0%
Loading ...

Java Tutorials

This category contains Java basic tutorials

Scanner class in Java

In this tutorial, we will learn about Scanner Class in Java. Scanner class in Java is used to get input from users as we use scanf() in C language. Scanner class is a predefined class in java which is present in java.util package. It means we have to import this package to use Scanner class in Program. Here we will learn how to use Scanner class and different methods of Scanner class. Here I would like to start directly with an example which would so helpful to you to understand Scanner class. // Import the Scanner class import java.util.Scanner; class ScannerExample { public static void main(String[] args) { // Creating object of Scanner class Scanner obj = new Scanner(System.in); System.out.println(“Enter First Number”); int num1= obj.nextInt(); // Reading user input System.out.println(“Enter Second Number”); int num2= obj.nextInt(); // Reading user input System.out.println(“Sum is: ” + (num1+num2)); } } Here we will check available methods in Scanner class. Method Description nextBoolean() Read boolean input nextByte() Read byte input nextDouble() Read double input nextFloat() Read float value nextInt() Read int input nextLine() Read string input nextLong() Read long value nextShort() Read short input Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Scanner class in Java Read More »

Introduction to Java

In this tutorial, we will learn Introduction to Java. Java is an object-oriented programming language. Java language was developed by James Gosling at Sun Microsystems Inc. In starting they were thinking of naming this language Oak, But this name was already registered by another company so they named it Java. Java is a breed of coffee. So that is why the coffee mug is the logo of Java. Sun Microsystems was developed in the year 1982 by four persons. Of these four persons, One person was Vinod Khosla. He was an Indian and passed out from IIT Delhi. Java was originated at Sun Microsystem in 1991. Sun Microsystems Company developed software for Appliances. There was a problem they had to develop software for every platform even though they were working the same so that is by they invented Java language to overcome this problem. On January 27, 2010, Sun Microsystems was acquired by Oracle Corporation for the US $ 7.4 billion Java is Everywhere: It is a slogan by Java and it is true because Java resides in mobiles. Client machines, server machines, embedded devices, smartphones, cloud etc. Java Flavours: Java Versions: Version Release Date JDK Beta 1995 JDK 1.0 January 1996 JDK 1.1 February 1997 J2SE 1.2 December 1998 J2SE 1.3 May 2000 J2SE 1.4 February 2002 J2SE 5.0 September 2004 Java SE 6 December 2006 Java SE 7 July 2011 Java SE 8 (LTS) March 2014 Java SE 9 September 2017 Java SE 10 March 2018 Java SE 11 (LTS) September 2018 Java SE 12 March 2019 Java SE 13 September 2019 Java SE 14 March 2020 Java SE 15 September 2020 Java SE 16 March 2021 Java SE 17 (LTS) September 2021 Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Introduction to Java Read More »

Setup Environment for Java

In this tutorial, we will start with Java Language. To start with java, First, we have to install java in our machine and after installing java we have to set the path of java in our machine. That path will help us to run java programs in CMD. There are some commands which we use to run the program in CMD. So, to install java JDK(Java Development Kit). We have this link from where you can download Java JDK. If you want to download just click on this link. Click here to Download When you will complete this installation you will get two folders on that memory location, which you selected on the time of installation. By default its //C:Program Files/Java Java Development Kit Java Run-Time Environment Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Setup Environment for Java Read More »

First Program in Java

We will not waste our time we will directly move towards our Hello World first program in java. After writing our first program we will discuss the various things of our program why we are using them in our code what impact they are making in our code. Before starting, if you have a background in c++ or any other Object Oriented Language then that experience will help you in this series. But don’t worry Java is not that much though in starting things may be confusing for you but with the time you find everything very easy. Please keep it in your mind that, we can not write any Method or variable outside of class, It means the main function will be also part of any class. Java Code class FirstProgram { public static void main(String []args) { System.out.println("Hello World Our First Program in Java"); } } Output Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

First Program in Java Read More »

Operators in Java

In this tutorial, we will learn about Operators in Java. Operators are special symbols that we use to perform special operations like the addition of two numbers. Java provides us with a wide range of operators which help us to perform special operations. In Java, all the operators are divided into different categories All the operators are categorized according to their functionality like operators which perform mathematical operations like +, -, /, * that is in a different category and which perform relational operations are in different category like > or operators Types of Operators: – Unary Operator Arithmetic Operator Relational Operator Logical Operator Conditional Operator Difference Between operators and Operands: – Before going further let’s check out the difference between operators and operands. Operators are symbols which tell to the compiler to what kind of operation will perform and operands are values on which operation will perform. Operators and operands are together known as Expressions Operands may be in the form of Values like 10, 15 or in the form of variables such as a + b. Unary Operator: – Unary Operators are those who work with only one operand. There are two main unary operators in java which are increment(++) and decrement(–), operator. class Operators{ public static void main(String args[]) { int a=10; int b=20; int c=10; int d=20; System.out.println("Pre Inc result "+(++a)); System.out.println("Post Inc result "+(b++)); System.out.println("Pre dec result "+(–c)); System.out.println("Pre dec result "+(d–)); } } Arithmetic Operator: – Arithmetic Operators are those which help us to perform the mathematical operation there are five Arithmetic operators available in java. They are +, -, /, *, %. class Operators{ public static void main(String args[]) { int a=10; int b=20; System.out.println("Airthmetic + Opeartor: "+(a+b)); System.out.println("Airthmetic – Opeartor: "+(a-b)); System.out.println("Airthmetic / Opeartor: "+(a/b)); System.out.println("Airthmetic % Opeartor: "+(a%b)); System.out.println("Airthmetic * Opeartor: "+(a*b)); } } Relational Operator: – Relational operators help us to make compression between two operands there are six Relational operators available in java. They are , >, =, >=, ==, != . class Operators{ public static void main(String args[]) { int a=10; int b=20; System.out.println("Result of > Opeartor: "+(a>b)); System.out.println("Result of >= Opeartor: "+(a>=b)); System.out.println("Result of < Opeartor:"+(a<b)); System.out.println("Result of <= Opeartor: "+(a<=b)); System.out.println("Result of == Opeartor:"+(a==b)); System.out.println("Result of != Opeartor:"+(a!=b)); } } Logical Operator: – Instead of Operands, logical operators work on expression. There is a total of three logical operators which are && (Logical and), ||(logical or),! (logical not) Logical AND(&&): – Logical AND only returns true if have true operands on both side. other wise it returns false Operand 1 Operand 2 Result true true true true false false false true false false false false class Operators{ public static void main(String args[]) { boolean a=true; boolean b=false; System.out.println("Logical AND Result"+(a&&b)); } } Logical OR(||): – It returns true if any single or both operands are true other wise it returns false. Operand 1 Operand 2 Result true true true true false true false true true false false false class Operators{ public static void main(String args[]) { boolean a=true; boolean b=false; System.out.println("Logical OR Result"+(a||b)); } } Logical NOT(!): – It returns complement of given operands true for false and false for true: Operand Result true false false true class Operators{ public static void main(String args[]) { boolean a=true; boolean b=false; System.out.println("Logical NOT Result"+(!a)); System.out.println("Logical NOT Result"+(!b)); } } Conditional Operator: – The conditional operator is also known as utility and ternary operator is work as an if-else condition. Format to write conditional operator. condition ? if true : if false class Operator { public static void main(String[] args) { int number = 10; String result; result = (number%2 > 0) ? "Even" : "Odd"; System.out.println(number + " is " + result); } } Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Operators in Java Read More »

Keywords in Java

In this tutorial, we will learn about Keywords in Java. Java provides a wide range of keywords to us. Every keyword has some special meaning in Java. We can not use any keyword as a class name or as a variable name. All keywords have some predefined meaning which the Java compiler knows very well For example if you are using the “while” keyword then the compiler knows very well that we are going to define a loop. Like other programming languages, Java has some common keywords like if, and for. But it also has some special keywords like byte and implements. It’s important to note we can not use any keyword as the name of an identifier (as a class name, variable name or method name.) Keyword List in Java: – Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Keywords in Java Read More »

Scroll to Top
×