Java Basics: Understanding the Fundamentals

Java Basics: Understanding the Fundamentals

9 mins read274 Views Comment
Jaya
Jaya Sharma
Assistant Manager - Content
Updated on Oct 12, 2023 17:23 IST

Java is one of the most popular programming languages among developer since it easy to use and can be used on almost every application. The ease of use and its versatile nature makes it one of the favourite languages among most businesses.

2023_01_Untitled-design-1.jpg

In this article on Java Basics, we will be discussing the fundamentals of Java programming. This will help beginners in developing a strong base for understanding the language. 

Table of Contents 

What is Java?

Java is a widely-used programming language released by Sun Microsystem for coding web applications. This network-centric, multi-platform and object-oriented language can also be used as a platform. Due to the versatility of the language, it is capable of building localized and distributed software. Java is a high-level language that works as a bridge between human and hardware language. 

Explore free Java courses

Advantages of Java Programming Language

Java can be used on any operating system and most applications. The ease of using Java makes it a popular choice. However, it has a number of other features that improve its preferability over other programming languages.

  1. Many learning sources are available to understand Java basics for learners and new programmers. It comes with detailed documentation, books, and courses to support developers to help them learn the language. This detailed documentation helps beginners to write code in core Java and then advanced Java. 
  2. Java has a huge community that offers regular updates and supports the language developer while facing the coding challenges.
  3. Java language has multiple inbuilt functions and rich libraries due to which developers do not need to write every function from scratch. These rich libraries and inbuilt functions help in developing a range of applications.
  4. Java offers several tools to support debugging, testing, automated editing and deployment that make programming cost and time efficient. 
  5. Even untrusted Java code can be downloaded over a network and run in a secure environment without any harm of infecting the host system. Restrictions and security levels in Java are extremely configurable.
  6. Java codes are platform-independent and can run on any underlying platform without the need for rewriting. This makes Java extremely useful while running applications on multiple devices. 

Explore programming courses

Writing First Program in Java

This is an important Java basic that beginners must get acquainted with. Beginners should learn to code efficiently in Java. Do remember that just like every other programming language, Java also has its own rules to declare, define and work on components. To learn them in a quicker and better way, you can start by learning a simple program. You can start by printing “Welcome to Java Tutorials” in Java. Through this process, you will be able to understand the major components and syntaxes fundamentally.

To initially learn programming in Java, you can either download Blue J (bluej.org) or Eclipse (www.eclipse.org/downloads/packages/release/kepler/sr1/eclipse-ide-java-developers). You can also use an online Java compiler to start programming in Java. 

 
public class Welcome { //
public static void main(String[] args) { //
System.out.println("Welcome to Java Tutorials. This will be fun."); //
}
}
Copy code

Output:

 
Welcome to Java Tutorials. This will be fun.
Copy code

Understanding the Syntax

1. Comments

In programming, comments make a program more understandable in plain language. These are mentioned after placing // and are ignored by the compiler. Proper usage of comments makes it easier to find bugs. There are three types of comments in Java, including the following: 

  • Single Line(//comment): These start with two forward slashes (//). Once you place //, any text after that is not considered by compiler and is not executed.
  • Multi Line ( /* comment */): Such comments are placed between  /* and */. This is used for commenting multiple lines of code to explain complex code snippet or to comment multiple lines of code.
  • Documentation comment (/** comment */):  Such comments are placed between /** and */. These are used for writing large programs for a software application or project when we need to create documentation API.  

2. Java Access Modifiers

Access Modifiers in Java are those keywords that define accessibility of class and its members. They are used for controlling the visibility of interfaces, variables, methods, constructors, setter method and data members. This is an important Java basic that beginners must have the idea of. 

  • Public: It is a Java keyword that declares the member access as public. Since public members are visible to every class, any class can access the public class or method. 
  • Default: Whenever the access modifier is not specified for method, class, or data member, then by default it gets default access modifier. This is public by default. 
  • Private: This access modifier is specified using ‘Private’ keyword. The data members declared as private is accessible only within class in which these are declared. 
  • Protected: Methods or data members declared as protected are declared within same package or subclasses in different packages. 

Programming Kit For Advance Learners

Once you have learned to write basic programs on Java, you can install a Java edition on the system. This can be either Java SE, Java EE or Java ME. 

  1. Java Platform, Standard Edition (Java SE): This is a computing platform to develop and deploy portable code for desktop as well as a server environments. This is a part of Java software platform family that uses this programming language. Java SE defines general-purpose APIs.  
  2. Jakarta EE (formerly known as Java EE): It is a set of specifications that run on reference runtimes (either application servers or microservices). These handle security, scalability, transactions, concurrency and management of the components that it deploys. Its specifications define APIs and their interactions. 
  3. Java Platform, Micro Edition (Java ME): is a computing platform that develops and deploys portable codes for embedded and mobile devices. This edition is the part of Java software platform family that replaced PersonalJava. 

2. Now, you will need to download Java Development Kit(JDK) that helps in developing Java code. Java Development Kit consists of tools that write and compile Java codes into Java class applications.  

3. This code is compiled into bytecode that the computer can understand using Java Runtime Environment. Java Runtime Environment is a software layer that runs Java applications. JRM consists of libraries, JVM and other components for running Java applications.

4. After this, you will need to install Integrated Development Environment (IDE), which refers to programs used for composing, debugging and compiling the code. Eclipse, Android Studio or Netbeans are popular IDEs for Java. 

5. Now, we will start creating a basic program in Java. For this, first, open the downloaded IDE and create a new Java project. You can either create a new project or click on File in menu bar and create a new Java application/project. Now, name your project. Say, we name it ‘Welcome To Java Tutorials’.

Keywords in Java

It is important to have an in-depth understanding of keywords when you want to learn Java basics. Keywords are reserved words that cannot be used as methods, classes or variables.  

These are used for internal processes or for representing predefined actions. Here, we will discuss some of the popular keywords in Java.

  1. Static: This keyword is used for managing memory. This is applicable to methods, blocks, nested classes and variables. On applying static keyword in Java to members, it is indicated that the member belongs to class instead of belonging to individual instances of class.
  2. Final: This keyword helps in declaring data members, class and methods to be unalterable. This keyword is used as an access modifier in Java. Final keyword in Java can be used for declaring variable as constant, method as final or to declare class as final. It behaves differently when used with classes, methods and variables. 
  3. Superkeyword: This keyword is a reference variable used by the subclass for accessing object of intermediate parent class. Superkeyword in Java allows access to data members and parent class objects. It can be used in top-level class or interface as well.
  4. This: It is used for refering to current objects in constructor or method. This keyword in Java reduces confusion between class attributes and parameters with same name. This keyword is used for differentiating between local and instance variables in an object.
  5. enum: It is a keyword that declares an enumerated (unchangeable) type. It is a special class that represents a group of constants. It has attributes and methods similar to class but it can neither be used for creating objects nor for extending other classes. 

Variables in Java

One of the essential basics of Java is its variables. Variable stores value when a Java program is executed. It is the named memory location that is associated with a data type. Variables can also have an address. Here is a list of important variables in Java that you should know about.

  • Local variables: These are defined within the constructor, method or any block.  These are created at the time of entering the block and are destroyed once they leave the block.
  • Reference variables: These are those variables that hold the address of a datatype and are used to point objects/values. It can also store a null value.
  • Instance variable: These are defined directly within the class but outside member functions, constructors or blocks. Instance variables are created whenever an object is created using ‘new’ keyword.
  • Static variable: These global variables do not belong to any specific instance of class but directly belong to a class. Due to this, all objects of the class can share the same copy of static variable. 

Identifiers in Java

These are the symbolic names that are used for identification. These can be the name of variable, class, method, constants, package, etc. Let us take the help of an example to understand identifiers.  

 
public class WelcometoJava {
public static void main(String[] args) {
System.out.println("WelcometoJava");
}
}
Copy code

Here:

  • WelcometoJava: Class name
  • Main: main method
  • String: Name of Predefined Class
  • args: String variables
  • System: Predefined class
  • out: Name of the variable
  • println: method
Recommended online courses

Best-suited Java courses for you

Learn Java with these high-rated online courses

– / –
350 hours
Free
6 months
– / –
4 months
– / –
– / –
– / –
1 month
50 K
7 weeks
7.8 K
3 months
8.47 K
2 months
7 K
6 months
4 K
2 months

Data Types in Java

Data Types is one of the important Java basics used for specifying different values and sizes that can be stored in variables. There are two main types of data types in Java including Primitive data type and non-primitive data type. Let us take a look at these in detail:

Java Primitive Data Type

Primitive data types are the basic data types that are building blocks for data manipulation. There are eight types of primitive data types including the following: 

Data Type Default Value Default size
boolean false 1 bit
short 0 2 byte
char 2 byte
byte 0 1 byte
long 0L 8 byte
int 0 4 byte
double 0.0d 8 byte
float 0.0f 4 byte

Non-Primitive Data Types

These are the reference data types that refer to objects and instances. These data types cannot store the value of variable in the memory directly. Instead, they store the memory address of a variable. Unlike primitive data types, these are user-defined and created by developers. These can be assigned with null. There are five main non-primitive data types: Class, Object, String, Array and Interface.

Conclusion

We hope that you have been able to learn some important basics of Java through this article. To learn this programming language in depth, you can refer to detailed topics on Java that discuss different aspects of this programming language.

Explore Free Online Courses with Certificates

_______________

Recently completed any professional course/certification from the market? Tell us what you liked or disliked in the course for more curated content.

Click here to submit its review.

About the Author
author-image
Jaya Sharma
Assistant Manager - Content

Jaya is a writer with an experience of over 5 years in content creation and marketing. Her writing style is versatile since she likes to write as per the requirement of the domain. She has worked on Technology, Fina... Read Full Bio