{"id":13,"date":"2024-03-18T21:10:39","date_gmt":"2024-03-18T21:10:39","guid":{"rendered":"https:\/\/logicnextgen.in\/?page_id=13"},"modified":"2026-05-29T10:11:34","modified_gmt":"2026-05-29T10:11:34","slug":"java-tutorial","status":"publish","type":"page","link":"https:\/\/logicnextgen.com\/tutorials\/java-tutorial\/","title":{"rendered":"Java Tutorial"},"content":{"rendered":"\n<p class=\"has-text-color has-link-color has-medium-font-size wp-elements-d8d430a65f532e5daa5f3544b976f9f1 wp-block-paragraph\" style=\"color:#ff8d00\"><strong> Java Programming Tutorial \u2013 Learn Java from Scratch<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"has-text-color has-link-color wp-elements-3766a962f97dc0990635a6223ac6abc5\" style=\"color:#ff8d00\"><a href=\"#Variables-in-java\"><strong>Tutorial 1: Introduction to Java<\/strong><\/a><\/li>\n\n\n\n<li class=\"has-text-color has-link-color wp-elements-ff5e589d7de669d832f06a7c187fb70e\" style=\"color:#ff8d00\"><a href=\"#Variables-in-java\"><strong>Tutorial 2: Variables in Java<\/strong><\/a><\/li>\n\n\n\n<li class=\"has-text-color has-link-color wp-elements-d9aabc94bd457756ebfebc9974d69900\" style=\"color:#ff8d00\"><strong><a href=\"#datatypes-in-java\">Tutorial 3: Data Types in Java<\/a><\/strong><\/li>\n\n\n\n<li class=\"has-text-color has-link-color wp-elements-1833daf7927723e29a07cd839531366d\" style=\"color:#ff8d00\"><strong><a href=\"#Tutorial-3:-If-Else\" data-type=\"internal\" data-id=\"#Tutorial-3:-If-Else\">Tutorial 3: If-Else<\/a><\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\"><strong>Tutorial 1: Introduction to Java<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Java programming language was originally developed by Sun Microsystems, which was initiated by James Gosling and released in 1995 as a core component of Sun Microsystems&#8217; Java platform (Java 1.0 [J2SE]).<br><strong>Object-Oriented Programming (OOP):<\/strong>\u00a0Java supports OOP concepts to create modular and reusable code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Platform Independence:<\/strong>\u00a0Java programs can run on any operating system with a JVM.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Robust and Secure:<\/strong>\u00a0Java ensures reliability and security through strong memory management and exception handling.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Multithreading and Concurrency:<\/strong>\u00a0Java allows concurrent execution of multiple tasks for efficiency.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Rich API and Standard Libraries:<\/strong>\u00a0Java provides extensive built-in libraries for various programming needs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Frameworks for Enterprise and Web Development:<\/strong>\u00a0Java supports frameworks that simplify enterprise and web application development.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Open-Source Libraries:<\/strong>\u00a0Java has a wide range of libraries to extend functionality and speed up development.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Maintainability and Scalability:<\/strong>\u00a0Java\u2019s structured design allows easy maintenance and growth of applications.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color has-large-font-size wp-elements-78aafdcc836bd16d362318d5ba10ec08 wp-block-paragraph\" id=\"Variables-in-java\" style=\"color:#ff8d00\"><strong>Tutorial 2: Variable<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A <strong>variable<\/strong> in Java is a container used to store data values.<br>It acts as a <strong>named memory location<\/strong> whose value can change during program execution.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<br>If you store age = 25, then <strong>age is a variable<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax of Variable<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">dataType variableName = value;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int age = 25;<\/code><\/pre>\n\n\n\n<h6 class=\"wp-block-heading\"><strong>Rules for Naming Variables<\/strong><\/h6>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Must start with a letter, <code>_<\/code>, or <code>$<\/code><\/li>\n\n\n\n<li>Cannot start with a number<\/li>\n\n\n\n<li>Cannot use Java keywords (like <code>int<\/code>, <code>class<\/code>)<\/li>\n\n\n\n<li>Case-sensitive (<code>age<\/code> \u2260 <code>Age<\/code>)<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>public class VariableExample {\n    public static void main(String&#91;] args) {\n        int age = 25;\n        String name = \"Kapoor\";\n        double salary = 50000.50;\n\n        System.out.println(\"Name: \" + name);\n        System.out.println(\"Age: \" + age);\n        System.out.println(\"Salary: \" + salary);\n    }\n}<\/code><\/pre>\n\n\n\n<h6 class=\"wp-block-heading\">Important Points<\/h6>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Variables must be declared before use<\/li>\n\n\n\n<li>Java is a <strong>strongly typed language<\/strong> (data type is mandatory)<\/li>\n\n\n\n<li>The value of a variable can be changed during execution<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Demonstrates storing different types of data.\n\nint age = 25;\ndouble price = 99.99;\nchar grade = 'A';\nboolean isActive = true;\n\nSystem.out.println(age);\nSystem.out.println(price);\nSystem.out.println(grade);\nSystem.out.println(isActive);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Real-Life Example\n\npublic class Employee {\n    public static void main(String&#91;] args) {\n        String name = \"Kapoor\";\n        int id = 101;\n        double salary = 45000;\n\n        System.out.println(\"Employee Name: \" + name);\n        System.out.println(\"Employee ID: \" + id);\n        System.out.println(\"Salary: \" + salary);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"has-text-color has-link-color has-large-font-size wp-elements-9d7075411af0d94336968f2c27fdcdee wp-block-paragraph\" id=\"datatypes-in-java\" style=\"color:#ff8d00\"><strong>Tutorial 2: Data Type<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A <strong>data type<\/strong> in Java defines:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>What type of data a variable can store<\/li>\n\n\n\n<li>How much memory will it use<\/li>\n\n\n\n<li>What operations can be performed on it<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udc49 Example:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">int age = 25;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here, int is the data type that tells Java that <strong>age will store integer values<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Data Type<\/th><th>Size<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>byte<\/td><td>1 byte<\/td><td>Small integer (-128 to 127)<\/td><\/tr><tr><td>short<\/td><td>2 bytes<\/td><td>Medium integer<\/td><\/tr><tr><td>int<\/td><td>4 bytes<\/td><td>Default integer type<\/td><\/tr><tr><td>long<\/td><td>8 bytes<\/td><td>Large integer<\/td><\/tr><tr><td>float<\/td><td>4 bytes<\/td><td>Decimal number<\/td><\/tr><tr><td>double<\/td><td>8 bytes<\/td><td>High precision decimal<\/td><\/tr><tr><td>char<\/td><td>2 bytes<\/td><td>Single character<\/td><\/tr><tr><td>boolean<\/td><td>1 bit<\/td><td>true\/false<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>public class datatype1{\n    public static void main(String&#91;] args) {\n        int age = 25;\n        double salary = 50000.75;\n        char grade = 'A';\n        boolean isActive = true;\n\n        System.out.println(age);\n        System.out.println(salary);\n        System.out.println(grade);\n        System.out.println(isActive);\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Student {\n    public static void main(String&#91;] args) {\n        int id = 101;\n        String name = \"Rahul\";\n        double marks = 85.5;\n        boolean passed = true;\n\n        System.out.println(\"ID: \" + id);\n        System.out.println(\"Name: \" + name);\n        System.out.println(\"Marks: \" + marks);\n        System.out.println(\"Passed: \" + passed);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"has-text-color has-link-color has-large-font-size wp-elements-e91b72a6999a95d81c640a5e4762a088 wp-block-paragraph\" id=\"Tutorial-3:-If-Else\" style=\"color:#ff8d00\"><strong>Tutorial 3: If Else<\/strong><\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>The if Statement<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<code>if<\/code>&nbsp;statement in Java checks a&nbsp;<strong>Boolean expression<\/strong>&nbsp;and executes a specific block of code only if the condition is&nbsp;<strong>true<\/strong>.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>The if-else Statement<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<code>if-else<\/code>&nbsp;statement allows Java programs to handle both&nbsp;<strong>true<\/strong>&nbsp;and&nbsp;<strong>false<\/strong>&nbsp;conditions. If the condition inside the&nbsp;<code>if<\/code>&nbsp;statement evaluates to&nbsp;<strong>false<\/strong>, the&nbsp;<code>else<\/code>&nbsp;block is executed instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using&nbsp;<strong>if-else statements in Java<\/strong>&nbsp;improves decision-making in programs by executing<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Most often, conditions are created using comparison operators, like the ones below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Less than:\u00a0a &lt; b<\/li>\n\n\n\n<li>Less than or equal to:\u00a0a &lt;= b<\/li>\n\n\n\n<li>Greater than:\u00a0a > b<\/li>\n\n\n\n<li>Greater than or equal to:\u00a0a >= b<\/li>\n\n\n\n<li>Equal to:\u00a0a == b<\/li>\n\n\n\n<li>Not equal to:\u00a0a != b<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>if (condition) {\n  \/\/ block of code to be executed if the condition is true\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>if (20 > 18) {\n  System.out.println(\"20 is greater than 18\");\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Java Programming Tutorial \u2013 Learn Java from Scratch Tutorial 1: Introduction to Java Java programming language was originally developed by Sun Microsystems, which was initiated by James Gosling and released in 1995 as a core component of Sun Microsystems&#8217; Java platform (Java 1.0 [J2SE]).Object-Oriented Programming (OOP):\u00a0Java supports OOP concepts to create modular and reusable code. &#8230; <a title=\"Java Tutorial\" class=\"read-more\" href=\"https:\/\/logicnextgen.com\/tutorials\/java-tutorial\/\" aria-label=\"Read more about Java Tutorial\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-13","page","type-page","status-publish"],"_links":{"self":[{"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/pages\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":63,"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/pages\/13\/revisions"}],"predecessor-version":[{"id":703,"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/pages\/13\/revisions\/703"}],"wp:attachment":[{"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/media?parent=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}