Skip to main content

Posts

Showing posts from April, 2021

Primitive Data Types

  So, as we've seen when we declare our variables, we give them a type, and the most fundamental types in Java are what are called primitive data types, and these are the data types that are built into the language. Now, when you hear the term primitive data type, you may think there's something kind of lowly about them, you know, something kind of, you know, less than modern about them. But that's not true at all. Primitive data types are actually very important. They're really the foundation of all other types that we use in Java, so they're really that kind of strong foundation that we're going to build on for any other data types we use in our programs. Now there are four categories of primitive types in Java. There are the integer types, floating point, character, and Boolean. So, let's look first at the integer types. Now there are four different integer types, but the difference then really is just the size of storage that they take up. But that diffe...

Variables, Data Types and Math Operations

  In order to do anything interesting in a program, we must have the ability to store and manipulate values. What allows us to do that are what we call variables. Now a variable, simply put, is just named data storage. Now Java is a strongly ‑ typed language. Now what that means is that when we declare a variable like, in this case, we have a variable named data Value, we have to specify the type of that variable, in this case, it's what we call an int, something that can store integers. So, what that means is that the data Value variable can only store things that are compatible with the type int. As we go through the course, we'll talk about this idea of one type being compatible with another. Now when we declare a variable, we can, of course, then assign a value to it, so our variable data Value now holds the value 100. Now when we use variables, we can do it the way we've done here where we declare it, then assign it, or as a matter of convenience, we can declare them a...

Introduction to Packages

Let's talk briefly about Java packages. Now packages are a very important concept in Java, and we can talk a great deal more about them later. We have a whole module dedicated to them. I want to look at just a couple of simple things about packages right now to get us started. Now, if we look at our source code, all the source code we've written up until now has just kind of our class definitions, and that's kind of by itself. But if you look at most Java source code out there, you'll see that at the top of the source code files is the word package, followed by some name, and what this does when we add this package concept is it provides organization within a Java program. Now, again, there're a lot of aspects of that, but I want to look at just kind of two basic aspects of it to get us started. One is that these package names follow a standard naming convention, and they affect our source code file structure. Now in terms of the naming convention, one very simple r...

Comments

  Java, like most programming languages, can include comments. All right, and comments are just basically text inside of your source code that the compiler doesn't see. Right, and there are really kind of just two general uses for comments. One is that it allows you to add human readable notes to your source code, right, it allows you to type things in the source code so that when you look at it later, or someone else looks at it, it's just leaving notes to understand what you were doing there. It's also useful for hiding source cool without deleting it. Maybe you're testing things out, so you want to just kind of take some things away and type some new stuff, or if there's something you don't want to anymore, but you think you want to do it again in the future, so comments allow you to take that stuff out so the content is in your source code, but the compiler doesn't compile it. There are three types of comments in Java. One, which is called line comments,...

Statement Structure and Whitespace

  Java programs are made up of statements. Now, a lot of different things can go on in a statement, and we'll talk about those things throughout this course, but fundamentally, programs are made with statements. Now each statement ends with a semicolon. Java is a language where the newline and the Enter key doesn't really create a new statement. It relies instead on the semicolon. If you're going from any of the C ‑ based languages, that's something you're very familiar with. Other languages like Visual Basic use the end of line to mark a statement. In Java, it's the semicolon. And the parts of a statement can be separated by zero or more whitespaces, and a whitespace could be many different things. It can be the space character, it can be a tab. And because statements don't end with newline, even the newline itself is just a whitespace in Java. Java's a language that gives us a lot of flexibility with whitespaces, so remember we said that the parts coul...

Integrated Development Environments (IDE)

If you wanted to, you could build your Java applications having only installed the JDK. You could use some arbitrary text editor to type in your program code, and then you could use command line tools to do all the compiling and executing of your programs, and that would work fine, and people did that for years, and some people still do that, but in general when we're developing, we want to use a more productive model than that. We like these things called integrated development environments that allow us to type in our code, compile it, debug it, everything all in one place. Now Java has lots and lots of IDEs available, and two of those you'll most commonly hear about are NetBeans and IntelliJ, both of which are available for free. For many years, NetBeans was maintained by the Oracle Corporation, and when Oracle was maintaining it, it was the official IDE for Java development. But Oracle support for NetBeans stopped as of JDK 8, so if you're working with an older version ...

JRE vs. JDK

  The JRE and the JDK are two terms you hear people mention very frequently in the Java world, and what they are the two parts that we need in order to run and create Java applications. The JRE is the Java Runtime Environment. JDK is the Java Development Kit. And so, the JRE is what you require in order to run Java applications, and end users normally install the JRE. They're the ones who are going to run our apps. The JDK provides the tools that we need to create Java apps. So, normally, developers are the ones who install the JDK on their machines. And in order to develop apps, you need to run them, so the JDK installation includes a JRE. So how does all this work together? If we sit down, and we type up a Java source file with our program code inside of it, and we want to go ahead and run that in some host environment, how do we do it? A host environment might be Windows, Linux. It could be Mac. It could even be a browser. It might be a phone running Android. How do we get from ...

What is Java?

The first thing we need to understand to get started is exactly what is Java? When someone says Java, what are they talking about? Well, Java is a programming language, but Java is also a runtime environment. It's both of those things. So, when we think about the programming language, it has things like the syntax, the data types, control flow, like looping and conditional statements and being object ‑ oriented, right, doing inheritance, and so forth. And then runtime, of course, must support those things, but it also provides things like configuration, security, a threading model, input/output, that sort of thing. So, when someone says Java, they could be referring to a programming language or the runtime environment or the whole thing. Now in general, the runtime environment someone is talking about when they just say Java is often referred to as Java Standard Edition. Right, that's kind of the basic Java environment. But it also provides other environments that derive from...

Railways will tell passengers to not charge laptops and phones at night, here is why

Indian Railways issued these instructions back in 2014 but their proper implementation seems to be starting now. HIGHLIGHTS You will soon not be able to charge your phone on a train. The restriction on phone charging will be between 11 pm and 5 am. Indian Railways found overcharging of devices caused minor fires on trains. When you travel by train in India, it is rare that you would have thought about charging your phone onboard. I mean it is not something that will occur to you before you step into a train to get on with your journey. But even though it is one of the most overlooked things, it is important. Charging your phone on a train is something that everyone does. But there is going to be a change to this simple benefit that you avail inside trains. Indian Railways has decided to put restrictions on charging mobile phones, laptops during certain hours to prevent fire hazards on trains. So, if you are traveling between 11 pm and 5 am on a train, you will not be able to cha...