Module 1 Getting To Know Java
Module 1 Getting To Know Java
Cabanatuan
Burgos Avenue, Cabanatuan City 3100
Tel. 463-2735 463-2697 600-2200 e-mail: crt.cabanatuan@gmail.com
Lesson Objectives:
At the end of this module, you should be able to:
1. Explain object-oriented programming (OOP’s) general principles and key terms
2. Demonstrate familiarity and understanding of basic structures, code, and syntax of the Java
programming language.
3. Identify the different components of the prescribed IDE for java, including useful word.
4. Evaluate simple Java programs.
Reference: https://www.tutorialspoint.com/java/index.htm
Productivity Tip: Turn off Distractions! One of the major productivity killers is the distraction of constant
interruptions: emails, phone calls, and people appearing at your door.
A. LESSON PREVIEW/REVIEW
1. Introduction
For today’s lesson try answering the questions below fill out the first column of the table. Write
your idea about the questions being asked in “What I know” part. It’s okay to write what came
out to your mind after reading the questions.
B. MAIN LESSON
• Dynamic − Java is considered to be more dynamic than C or C++ since it is designed to adapt to an
evolving environment. Java programs can carry extensive amount of run-time information that can
be used to verify and resolve accesses to objects on run-time.
AREAS OF APPLICATION
1. World Wide Web Applets
2. Cross-Platform Application Development
3. Other Network Application
SYNTAX
The syntax of Java is largely derived from C++. Unlike C++, which combines the syntax for structured,
generic, and object-oriented programming. Java was built almost exclusively as an object-oriented language.
All code is written inside a class, and everything is an object. with the exception of the primitive data types
(e.g. integers, floating-point numbers, Boolean values, and characters). which are not classes for performance
reasons.
Unlike C++. Java does not support operator overloading or multiple inheritance for classes. This
simplifies the language and aids in preventing potential errors and anti-pattern design. Java uses similar
commenting methods to C++. There are three different styles of comments: a single line style marked with
two slashes (//), a multiple line style opened with /* and closed with *, and the Javadoc commenting style
opened with /** and closed with *. The Javadoc style of commenting allows the user to run the Javadoc
executable to compile documentation for the program.
RESERVED WORDS:
volatile while
SAMPLE PROGRAM
Note: Class name should start in uppercase.
class HelloWorld
{
public static void main(String []args)
{
System.out.println("Hello World!!!");
}
}
• The dots or periods are used to separate the name of the components in the statement
• System is a class.
• out is an object defined in the System class.
• PrintIn() is a method. Method names are always followed by parentheses.
• First Java Application is a literal string that is the argument to the print in© method.
• ;(semicolon) is used to end a Java statement.
System.exit(0);
}
Besides allowing you to use the System class to produce command window output. Java provides
built-in classes that produce GUI output on dialog boxes. A dialog box is a GUI object resembling a window
which you can place messages you want to display.
You use an import statement when you want to access a built-in Java class that is contained in a
group of classes called package. To use the JOptionPane class, you must import the package named
javax.swing. JoptionPane.
In older versions of Java, any application that use a dialog was required to end with System exit(0);
statement or the application would not terminate. You can add this statement to your programs, and they will
work correctly, but it is not necessary.
import javax.swing.JOptionPane;
public class InputDialogDemo
{
public static void main(String[] args)
{
String name;
name = JOptionPane.showInputDialog("Enter Your Name");
JOptionPane.showMessageDialog(null, "Your name is " + name );
}
OUTPUT:
Enter Your Name Juan Dela Cruz
Your name is Juan Dela Cuz
Code Output
1 class Welcome1
{
public static void main(String arg[])
{
System.out.printIn(“Welcome to Computer
Programming 2”);
}
}
2 class Welcome2
{
public static void main(String arg[])
{
System.out.print(“Welcome to”);
System.out.print(“Computer Programming 2”);
}
}
3 class Welcome3
{
public static void main(String arg[])
{
System.out.printIn(“Welcome to”);
System.out.print(“Computer Programming 2”);
}
}
4 class Welcome4
{
public static void main(String arg[])
{
System.out.print(“Welcome to ” + Computer
Programming 2”);
}
}
5 class Welcome4
{
public static void main(String arg[])
{
System.out.print(“Welcome to ” +/n
Computer Programming 2”);
}
}
College for Research & Technology of
Cabanatuan
Burgos Avenue, Cabanatuan City 3100
Tel. 463-2735 463-2697 600-2200 e-mail: crt.cabanatuan@gmail.com
Based on what you have learn in this course overview about Computer Programming 2, answer
the third column in the table found at the page 1 of this module.
Code Output
1 Class Sample
{
Public static void main(String args[])
{
Int age=18;
String name=”Juan Dela Cruz”;
System.out.print(“I am” + name + “,” + age + “years
old.”;
}
}
2 import java.util.Scanner;
public class GetUserInput
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
System.out.print("Enter your name>>");
String name = input.nextLine();
System.out.print("Enter your age>>");
int age = input.nextInt();
JOptionPane.showMessageDiaglog(null, "your
name"+name+ "and you are"+age+"years old");
}
}
FAQ’S
1. Is there a case sensitive in Java Programming?
• Yes, java is case sensitive, which means identifier Hello and hello would have a
different meaning in java.
2. What is the rule in setting classmate name?
College for Research & Technology of
Cabanatuan
Burgos Avenue, Cabanatuan City 3100
Tel. 463-2735 463-2697 600-2200 e-mail: crt.cabanatuan@gmail.com
• For all class name, the first letter should be in Upper Case. If several words are used
to form the class’s name, each inner words first letter should be in Upper Case.
3. What is the rule in setting method names and program file name?
• All method names should start with a Lower-Case letter. If several words are used to
form the methods name, then each inner words first letter should be in Upper Case
while the program files name should exactly match the class name.